📄 ogrlinestring.cpp
字号:
{ if( padfZ != NULL ) { OGRFree( padfZ ); padfZ = NULL; } nCoordDimension = 2;}/************************************************************************//* Make3D() *//************************************************************************/void OGRLineString::Make3D(){ if( padfZ == NULL ) { if( nPointCount == 0 ) padfZ = (double *) OGRCalloc(sizeof(double),1); else padfZ = (double *) OGRCalloc(sizeof(double),nPointCount); } nCoordDimension = 3;}/************************************************************************//* getPoint() *//************************************************************************//** * Fetch a point in line string. * * This method relates to the SFCOM ILineString::get_Point() method. * * @param i the vertex to fetch, from 0 to getNumPoints()-1. * @param poPoint a point to initialize with the fetched point. */void OGRLineString::getPoint( int i, OGRPoint * poPoint ) const{ assert( i >= 0 ); assert( i < nPointCount ); assert( poPoint != NULL ); poPoint->setX( paoPoints[i].x ); poPoint->setY( paoPoints[i].y ); if( getCoordinateDimension() == 3 && padfZ != NULL ) poPoint->setZ( padfZ[i] );}/** * \fn int OGRLineString::getNumPoints() const; * * Fetch vertex count. * * Returns the number of vertices in the line string. * * @return vertex count. *//** * \fn double OGRLineString::getX( int iVertex ) const; * * Get X at vertex. * * Returns the X value at the indicated vertex. If iVertex is out of range a * crash may occur, no internal range checking is performed. * * @param iVertex the vertex to return, between 0 and getNumPoints()-1. * * @return X value. *//** * \fn double OGRLineString::getY( int iVertex ) const; * * Get Y at vertex. * * Returns the Y value at the indicated vertex. If iVertex is out of range a * crash may occur, no internal range checking is performed. * * @param iVertex the vertex to return, between 0 and getNumPoints()-1. * * @return X value. *//************************************************************************//* getZ() *//************************************************************************//** * Get Z at vertex. * * Returns the Z (elevation) value at the indicated vertex. If no Z * value is available, 0.0 is returned. If iVertex is out of range a * crash may occur, no internal range checking is performed. * * @param iVertex the vertex to return, between 0 and getNumPoints()-1. * * @return Z value. */double OGRLineString::getZ( int iVertex ) const{ if( padfZ != NULL && iVertex >= 0 && iVertex < nPointCount && nCoordDimension >= 3 ) return( padfZ[iVertex] ); else return 0.0;}/************************************************************************//* setNumPoints() *//************************************************************************//** * Set number of points in geometry. * * This method primary exists to preset the number of points in a linestring * geometry before setPoint() is used to assign them to avoid reallocating * the array larger with each call to addPoint(). * * This method has no SFCOM analog. * * @param nNewPointCount the new number of points for geometry. */void OGRLineString::setNumPoints( int nNewPointCount ){ if( nNewPointCount == 0 ) { OGRFree( paoPoints ); paoPoints = NULL; OGRFree( padfZ ); padfZ = NULL; nPointCount = 0; return; } if( nNewPointCount > nPointCount ) { paoPoints = (OGRRawPoint *) OGRRealloc(paoPoints, sizeof(OGRRawPoint) * nNewPointCount); assert( paoPoints != NULL ); memset( paoPoints + nPointCount, 0, sizeof(OGRRawPoint) * (nNewPointCount - nPointCount) ); if( getCoordinateDimension() == 3 ) { padfZ = (double *) OGRRealloc( padfZ, sizeof(double)*nNewPointCount ); memset( padfZ + nPointCount, 0, sizeof(double) * (nNewPointCount - nPointCount) ); } } nPointCount = nNewPointCount;}/************************************************************************//* setPoint() *//************************************************************************//** * Set the location of a vertex in line string. * * If iPoint is larger than the number of necessary the number of existing * points in the line string, the point count will be increased to * accomodate the request. * * There is no SFCOM analog to this method. * * @param iPoint the index of the vertex to assign (zero based). * @param poPoint the value to assign to the vertex. */void OGRLineString::setPoint( int iPoint, OGRPoint * poPoint ){ setPoint( iPoint, poPoint->getX(), poPoint->getY(), poPoint->getZ() );}/************************************************************************//* setPoint() *//************************************************************************//** * Set the location of a vertex in line string. * * If iPoint is larger than the number of necessary the number of existing * points in the line string, the point count will be increased to * accomodate the request. * * There is no SFCOM analog to this method. * * @param iPoint the index of the vertex to assign (zero based). * @param xIn input X coordinate to assign. * @param yIn input Y coordinate to assign. * @param zIn input Z coordinate to assign (defaults to zero). */void OGRLineString::setPoint( int iPoint, double xIn, double yIn, double zIn ){ if( getCoordinateDimension() == 2 ) Make3D(); if( iPoint >= nPointCount ) setNumPoints( iPoint+1 ); paoPoints[iPoint].x = xIn; paoPoints[iPoint].y = yIn; if( zIn != 0.0 ) { Make3D(); padfZ[iPoint] = zIn; } else if( getCoordinateDimension() == 3 ) { padfZ[iPoint] = 0.0; }}void OGRLineString::setPoint( int iPoint, double xIn, double yIn ){ if( iPoint >= nPointCount ) setNumPoints( iPoint+1 ); paoPoints[iPoint].x = xIn; paoPoints[iPoint].y = yIn;}/************************************************************************//* addPoint() *//************************************************************************//** * Add a point to a line string. * * The vertex count of the line string is increased by one, and assigned from * the passed location value. * * There is no SFCOM analog to this method. * * @param poPoint the point to assign to the new vertex. */void OGRLineString::addPoint( OGRPoint * poPoint ){ setPoint( nPointCount, poPoint->getX(), poPoint->getY(), poPoint->getZ() );}/************************************************************************//* addPoint() *//************************************************************************//** * Add a point to a line string. * * The vertex count of the line string is increased by one, and assigned from * the passed location value. * * There is no SFCOM analog to this method. * * @param x the X coordinate to assign to the new point. * @param y the Y coordinate to assign to the new point. * @param z the Z coordinate to assign to the new point (defaults to zero). */void OGRLineString::addPoint( double x, double y, double z ){ setPoint( nPointCount, x, y, z );}void OGRLineString::addPoint( double x, double y ){ setPoint( nPointCount, x, y );}/************************************************************************//* setPoints() *//************************************************************************//** * Assign all points in a line string. * * This method clears any existing points assigned to this line string, * and assigns a whole new set. It is the most efficient way of assigning * the value of a line string. * * There is no SFCOM analog to this method. * * @param nPointsIn number of points being passed in paoPointsIn * @param paoPointsIn list of points being assigned. * @param padfZ the Z values that go with the points (optional, may be NULL). */void OGRLineString::setPoints( int nPointsIn, OGRRawPoint * paoPointsIn, double * padfZ ){ setNumPoints( nPointsIn ); memcpy( paoPoints, paoPointsIn, sizeof(OGRRawPoint) * nPointsIn);/* -------------------------------------------------------------------- *//* Check 2D/3D. *//* -------------------------------------------------------------------- */ if( padfZ == NULL && getCoordinateDimension() > 2 ) { Make2D(); } else if( padfZ ) { Make3D(); memcpy( this->padfZ, padfZ, sizeof(double) * nPointsIn ); }}/************************************************************************//* setPoints() *//************************************************************************//** * Assign all points in a line string. * * This method clear any existing points assigned to this line string, * and assigns a whole new set. * * There is no SFCOM analog to this method. * * @param nPointsIn number of points being passed in padfX and padfY. * @param padfX list of X coordinates of points being assigned. * @param padfY list of Y coordinates of points being assigned. * @param padfZ list of Z coordinates of points being assigned (defaults to * NULL for 2D objects). */void OGRLineString::setPoints( int nPointsIn, double * padfX, double * padfY, double * padfZ ){ int i;/* -------------------------------------------------------------------- *//* Check 2D/3D. *//* -------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -