?? ogr_api.cpp
字號(hào):
/******************************************************************************
* $Id: ogr_api.cpp 12043 2007-09-03 17:58:51Z mloskot $
*
* 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.
****************************************************************************/
#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.
*/
void OGR_G_AddPoint( OGRGeometryH hGeom,
double dfX, double dfY, double dfZ )
{
switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) )
{
case wkbPoint:
{
((OGRPoint *) hGeom)->setX( dfX );
((OGRPoint *) hGeom)->setY( dfY );
((OGRPoint *) hGeom)->setZ( dfZ );
}
break;
case wkbLineString:
((OGRLineString *) hGeom)->addPoint( dfX, dfY, dfZ );
break;
default:
CPLAssert( FALSE );
break;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -