?? ogrlinestring.cpp
字號(hào):
*
* 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. */
/* -------------------------------------------------------------------- */
if( padfZ == NULL )
Make2D();
else
Make3D();
/* -------------------------------------------------------------------- */
/* Assign values. */
/* -------------------------------------------------------------------- */
setNumPoints( nPointsIn );
for( i = 0; i < nPointsIn; i++ )
{
paoPoints[i].x = padfX[i];
paoPoints[i].y = padfY[i];
}
if( this->padfZ != NULL )
memcpy( this->padfZ, padfZ, sizeof(double) * nPointsIn );
}
/************************************************************************/
/* getPoints() */
/************************************************************************/
/**
* Returns all points of line string.
*
* This method copies all points into user list. This list must be at
* least sizeof(OGRRawPoint) * OGRGeometry::getNumPoints() byte in size.
* It also copies all Z coordinates.
*
* There is no SFCOM analog to this method.
*
* @param paoPointsOut a buffer into which the points is written.
* @param padfZ the Z values that go with the points (optional, may be NULL).
*/
void OGRLineString::getPoints( OGRRawPoint * paoPointsOut, double * padfZ ) const
{
if ( ! paoPointsOut )
return;
memcpy( paoPointsOut, paoPoints, sizeof(OGRRawPoint) * nPointCount );
/* -------------------------------------------------------------------- */
/* Check 2D/3D. */
/* -------------------------------------------------------------------- */
if( padfZ )
{
if ( this->padfZ )
memcpy( padfZ, this->padfZ, sizeof(double) * nPointCount );
else
memset( padfZ, 0, sizeof(double) * nPointCount );
}
}
/************************************************************************/
/* addSubLineString() */
/************************************************************************/
/**
* Add a segment of another linestring to this one.
*
* Adds the request range of vertices to the end of this line string
* in an efficient manner. If the nStartVertex is larger than the
* nEndVertex then the vertices will be reversed as they are copied.
*
* @param poOtherLine the other OGRLineString.
* @param nStartVertex the first vertex to copy, defaults to 0 to start
* with the first vertex in the other linestring.
* @param nEndVertex the last vertex to copy, defaults to -1 indicating
* the last vertex of the other line string.
*/
void OGRLineString::addSubLineString( const OGRLineString *poOtherLine,
int nStartVertex, int nEndVertex )
{
/* -------------------------------------------------------------------- */
/* Do a bit of argument defaulting and validation. */
/* -------------------------------------------------------------------- */
if( nEndVertex == -1 )
nEndVertex = poOtherLine->getNumPoints() - 1;
if( nStartVertex < 0 || nEndVertex < 0
|| nStartVertex >= poOtherLine->getNumPoints()
|| nEndVertex >= poOtherLine->getNumPoints() )
{
CPLAssert( FALSE );
return;
}
/* -------------------------------------------------------------------- */
/* Grow this linestring to hold the additional points. */
/* -------------------------------------------------------------------- */
int nOldPoints = nPointCount;
int nPointsToAdd = ABS(nEndVertex-nStartVertex) + 1;
setNumPoints( nPointsToAdd + nOldPoints );
/* -------------------------------------------------------------------- */
/* Copy the x/y points - forward copies use memcpy. */
/* -------------------------------------------------------------------- */
if( nEndVertex >= nStartVertex )
{
memcpy( paoPoints + nOldPoints,
poOtherLine->paoPoints + nStartVertex,
sizeof(OGRRawPoint) * nPointsToAdd );
if( poOtherLine->padfZ != NULL )
{
Make3D();
memcpy( padfZ + nOldPoints, poOtherLine->padfZ + nStartVertex,
sizeof(double) * nPointsToAdd );
}
}
/* -------------------------------------------------------------------- */
/* Copy the x/y points - reverse copies done double by double. */
/* -------------------------------------------------------------------- */
else
{
int i;
for( i = 0; i < nPointsToAdd; i++ )
{
paoPoints[i+nOldPoints].x =
poOtherLine->paoPoints[nStartVertex-i].x;
paoPoints[i+nOldPoints].y =
poOtherLine->paoPoints[nStartVertex-i].y;
}
if( poOtherLine->padfZ != NULL )
{
Make3D();
for( i = 0; i < nPointsToAdd; i++ )
{
padfZ[i+nOldPoints] = poOtherLine->padfZ[nStartVertex-i];
}
}
}
}
/************************************************************************/
/* importFromWkb() */
/* */
/* Initialize from serialized stream in well known binary */
/* format. */
/************************************************************************/
OGRErr OGRLineString::importFromWkb( unsigned char * pabyData,
int nSize )
{
OGRwkbByteOrder eByteOrder;
if( nSize < 21 && nSize != -1 )
return OGRERR_NOT_ENOUGH_DATA;
/* -------------------------------------------------------------------- */
/* Get the byte order byte. */
/* -------------------------------------------------------------------- */
eByteOrder = DB2_V72_FIX_BYTE_ORDER((OGRwkbByteOrder) *pabyData);
assert( eByteOrder == wkbXDR || eByteOrder == wkbNDR );
/* -------------------------------------------------------------------- */
/* Get the geometry feature type. For now we assume that */
/* geometry type is between 0 and 255 so we only have to fetch */
/* one byte. */
/* -------------------------------------------------------------------- */
OGRwkbGeometryType eGeometryType;
int bIs3D = FALSE;
int nBytesAvailable = nSize;
if( eByteOrder == wkbNDR )
{
eGeometryType = (OGRwkbGeometryType) pabyData[1];
bIs3D = pabyData[4] & 0x80 || pabyData[2] & 0x80;
}
else
{
eGeometryType = (OGRwkbGeometryType) pabyData[4];
bIs3D = pabyData[1] & 0x80 || pabyData[3] & 0x80;
}
CPLAssert( eGeometryType == wkbLineString );
/* -------------------------------------------------------------------- */
/* Get the vertex count. */
/* -------------------------------------------------------------------- */
int nNewNumPoints;
memcpy( &nNewNumPoints, pabyData + 5, 4 );
if( OGR_SWAP( eByteOrder ) )
nNewNumPoints = CPL_SWAP32(nNewNumPoints);
/* Check if the wkb stream buffer is big enough to store
* fetched number of points.
* 16 or 24 - size of point structure
*/
int nPointSize = (bIs3D ? 24 : 16);
int nBufferMinSize = nPointSize * nNewNumPoints;
if( nBufferMinSize > nBytesAvailable && nBytesAvailable > 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Length of input WKB is too small" );
return OGRERR_NOT_ENOUGH_DATA;
}
setNumPoints( nNewNumPoints );
if( bIs3D )
Make3D();
else
Make2D();
/* -------------------------------------------------------------------- */
/* Get the vertex. */
/* -------------------------------------------------------------------- */
int i = 0;
int nBytesToCopy = 0;
if( bIs3D )
{
for( i = 0; i < nPointCount; i++ )
{
nBytesToCopy = 24;
if( nBytesToCopy > nBytesAvailable && nBytesAvailable > 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"WKB buffer with OGRLineString points is too small! \
\n\tWKB stream may be corrupted or it is EWKB stream which is not supported");
return OGRERR_NOT_ENOUGH_DATA;
}
if ( nBytesAvailable > 0 )
nBytesAvailable -= nBytesToCopy;
memcpy( paoPoints + i, pabyData + 9 + i*24, 16 );
memcpy( padfZ + i, pabyData + 9 + 16 + i*24, 8 );
}
}
else
{
nBytesToCopy = 16 * nPointCount;
if( nBytesToCopy > nBytesAvailable && nBytesAvailable > 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"WKB buffer with OGRLineString points is too small! \
\n\tWKB stream may be corrupted or it is EWKB stream which is not supported");
return OGRERR_NOT_ENOUGH_DATA;
}
memcpy( paoPoints, pabyData + 9, nBytesToCopy );
}
/* -------------------------------------------------------------------- */
/* Byte swap if needed. */
/* -------------------------------------------------------------------- */
if( OGR_SWAP( eByteOrder ) )
{
for( i = 0; i < nPointCount; i++ )
{
CPL_SWAPDOUBLE( &(paoPoints[i].x) );
CPL_SWAPDOUBLE( &(paoPoints[i].y) );
}
if( bIs3D )
{
for( i = 0; i < nPointCount; i++ )
{
CPL_SWAPDOUBLE( padfZ + i );
}
}
}
return OGRERR_NONE;
}
/************************************************************************/
/* exportToWkb() */
/* */
/* Build a well known binary representation of this object. */
/************************************************************************/
OGRErr OGRLineString::exportToWkb( OGRwkbByteOrder eByteOrder,
unsigned char * pabyData ) const
{
/* -------------------------------------------------------------------- */
/* Set the byte order. */
/* -------------------------------------------------------------------- */
pabyData[0] = DB2_V72_UNFIX_BYTE_ORDER((unsigned char) eByteOrder);
/* -------------------------------------------------------------------- */
/* Set the geometry feature type. */
/* -------------------------------------------------------------------- */
GUInt32 nGType = getGeometryType();
if( eByteOrder == wkbNDR )
nGType = CPL_LSBWORD32( nGType );
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -