📄 ogr_api.cpp
字号:
/****************************************************************************** * $Id: ogr_api.cpp,v 1.10 2005/09/12 20:55:41 fwarmerdam Exp $ * * Project: OpenGIS Simple Features Reference Implementation * Purpose: C API Functions that don't correspond one-to-one with C++ * methods, such as the "simplified" geometry access functions. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2002, Frank Warmerdam * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************** * * $Log: ogr_api.cpp,v $ * Revision 1.10 2005/09/12 20:55:41 fwarmerdam * Fixed OGR_G_AddGeometry() to support 2D or 2.5D linestrings being * added to a polygon. * * Revision 1.9 2005/07/20 02:33:51 fwarmerdam * fixed up dimension test for adding to polygons * * Revision 1.8 2005/07/20 01:43:51 fwarmerdam * upgraded OGR geometry dimension handling * * Revision 1.7 2004/09/17 15:05:36 fwarmerdam * added get_Area() support * * Revision 1.6 2003/05/28 19:16:42 warmerda * fixed up argument names and stuff for docs * * Revision 1.5 2003/04/14 17:33:35 warmerda * Fixed GetPoint's y value for points as per bug 319. * * Revision 1.4 2003/03/31 15:55:42 danmo * Added C API function docs * * Revision 1.3 2003/01/07 16:44:27 warmerda * added removeGeometry * * Revision 1.2 2002/10/19 16:22:32 warmerda * fixed bug with OGR_G_GetGeometryRef() for interior rings of polygons * * Revision 1.1 2002/09/26 18:11:51 warmerda * New * */#include "ogr_geometry.h"#include "ogr_api.h"#include "cpl_error.h"/************************************************************************//* OGR_G_GetPointCount() *//************************************************************************//** * Fetch number of points from a geometry. * * @param hGeom handle to the geometry from which to get the number of points. * @return the number of points. */int OGR_G_GetPointCount( OGRGeometryH hGeom ){ switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) ) { case wkbPoint: return 1; case wkbLineString: { OGRLineString *poLine = (OGRLineString *) hGeom; return poLine->getNumPoints(); } default: return 0; }}/************************************************************************//* OGR_G_GetX() *//************************************************************************//** * Fetch the x coordinate of a point from a geometry. * * @param hGeom handle to the geometry from which to get the x coordinate. * @param i point to get the x coordinate. * @return the X coordinate of this point. */double OGR_G_GetX( OGRGeometryH hGeom, int i ){ switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) ) { case wkbPoint: { if( i == 0 ) return ((OGRPoint *) hGeom)->getX(); else return 0.0; } case wkbLineString: return ((OGRLineString *) hGeom)->getX( i ); default: return 0.0; }}/************************************************************************//* OGR_G_GetY() *//************************************************************************//** * Fetch the x coordinate of a point from a geometry. * * @param hGeom handle to the geometry from which to get the y coordinate. * @param i point to get the Y coordinate. * @return the Y coordinate of this point. */double OGR_G_GetY( OGRGeometryH hGeom, int i ){ switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) ) { case wkbPoint: { if( i == 0 ) return ((OGRPoint *) hGeom)->getY(); else return 0.0; } case wkbLineString: return ((OGRLineString *) hGeom)->getY( i ); default: return 0.0; }}/************************************************************************//* OGR_G_GetZ() *//************************************************************************//** * Fetch the z coordinate of a point from a geometry. * * @param hGeom handle to the geometry from which to get the Z coordinate. * @param i point to get the Z coordinate. * @return the Z coordinate of this point. */double OGR_G_GetZ( OGRGeometryH hGeom, int i ){ switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) ) { case wkbPoint: { if( i == 0 ) return ((OGRPoint *) hGeom)->getZ(); else return 0.0; } case wkbLineString: return ((OGRLineString *) hGeom)->getZ( i ); default: return 0.0; }}/************************************************************************//* OGR_G_GetPoint() *//************************************************************************//** * Fetch a point in line string or a point geometry. * * @param hGeom handle to the geometry from which to get the coordinates. * @param i the vertex to fetch, from 0 to getNumPoints()-1, zero for a point. * @param pdfX value of x coordinate. * @param pdfY value of y coordinate. * @param pdfZ value of z coordinate. */void OGR_G_GetPoint( OGRGeometryH hGeom, int i, double *pdfX, double *pdfY, double *pdfZ ){ switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) ) { case wkbPoint: { CPLAssert( i == 0 ); if( i == 0 ) { *pdfX = ((OGRPoint *)hGeom)->getX(); *pdfY = ((OGRPoint *)hGeom)->getY(); if( pdfZ != NULL ) *pdfZ = ((OGRPoint *)hGeom)->getZ(); } } break; case wkbLineString: { *pdfX = ((OGRLineString *) hGeom)->getX( i ); *pdfY = ((OGRLineString *) hGeom)->getY( i ); if( pdfZ != NULL ) *pdfZ = ((OGRLineString *) hGeom)->getZ( i ); } break; default: CPLAssert( FALSE ); break; }}/************************************************************************//* OGR_G_SetPoint() *//************************************************************************//** * Set the location of a vertex in a point or linestring geometry. * * If iPoint is larger than the number of existing * points in the linestring, the point count will be increased to * accomodate the request. * * @param hGeom handle to the geometry to add a vertex to. * @param i the index of the vertex to assign (zero based) or * zero for a point. * @param dfX input X coordinate to assign. * @param dfY input Y coordinate to assign. * @param dfZ input Z coordinate to assign (defaults to zero). */void OGR_G_SetPoint( OGRGeometryH hGeom, int i, double dfX, double dfY, double dfZ ){ switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) ) { case wkbPoint: { CPLAssert( i == 0 ); if( i == 0 ) { ((OGRPoint *) hGeom)->setX( dfX ); ((OGRPoint *) hGeom)->setY( dfY ); ((OGRPoint *) hGeom)->setZ( dfZ ); } } break; case wkbLineString: ((OGRLineString *) hGeom)->setPoint( i, dfX, dfY, dfZ ); break; default: CPLAssert( FALSE ); break; }}/************************************************************************//* OGR_G_SetPoint_2D() *//************************************************************************//** * Set the location of a vertex in a point or linestring geometry. * * If iPoint is larger than the number of existing * points in the linestring, the point count will be increased to * accomodate the request. * * @param hGeom handle to the geometry to add a vertex to. * @param i the index of the vertex to assign (zero based) or * zero for a point. * @param dfX input X coordinate to assign. * @param dfY input Y coordinate to assign. */void OGR_G_SetPoint_2D( OGRGeometryH hGeom, int i, double dfX, double dfY ) { switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) ) { case wkbPoint: { CPLAssert( i == 0 ); if( i == 0 ) { ((OGRPoint *) hGeom)->setX( dfX ); ((OGRPoint *) hGeom)->setY( dfY ); } } break; case wkbLineString: ((OGRLineString *) hGeom)->setPoint( i, dfX, dfY ); break; default: CPLAssert( FALSE ); break; }}/************************************************************************//* OGR_G_AddPoint() *//************************************************************************//** * Add a point to a geometry (line string or point). * * The vertex count of the line string is increased by one, and assigned from * the passed location value. * * @param hGeom handle to the geometry to add a point to. * @param dfX x coordinate of point to add. * @param dfY y coordinate of point to add. * @param dfZ z coordinate of point to add. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -