?? ogrlinearring.cpp
字號:
/******************************************************************************
* $Id: ogrlinearring.cpp 12517 2007-10-23 15:07:35Z mloskot $
*
* Project: OpenGIS Simple Features Reference Implementation
* Purpose: The OGRLinearRing geometry class.
* Author: Frank Warmerdam, warmerdam@pobox.com
*
******************************************************************************
* Copyright (c) 1999, 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_p.h"
CPL_CVSID("$Id: ogrlinearring.cpp 12517 2007-10-23 15:07:35Z mloskot $");
/************************************************************************/
/* OGRLinearRing() */
/************************************************************************/
OGRLinearRing::OGRLinearRing()
{
}
/************************************************************************/
/* ~OGRLinearRing() */
/************************************************************************/
OGRLinearRing::~OGRLinearRing()
{
}
/************************************************************************/
/* OGRLinearRing() */
/************************************************************************/
OGRLinearRing::OGRLinearRing( OGRLinearRing * poSrcRing )
{
if( poSrcRing == NULL )
{
CPLDebug( "OGR", "OGRLinearRing::OGRLinearRing(OGRLinearRing*poSrcRing) - passed in ring is NULL!" );
return;
}
setNumPoints( poSrcRing->getNumPoints() );
memcpy( paoPoints, poSrcRing->paoPoints,
sizeof(OGRRawPoint) * getNumPoints() );
if( poSrcRing->padfZ )
{
Make3D();
memcpy( padfZ, poSrcRing->padfZ, sizeof(double) * getNumPoints() );
}
}
/************************************************************************/
/* getGeometryName() */
/************************************************************************/
const char * OGRLinearRing::getGeometryName() const
{
return "LINEARRING";
}
/************************************************************************/
/* WkbSize() */
/* */
/* Disable this method. */
/************************************************************************/
int OGRLinearRing::WkbSize() const
{
return 0;
}
/************************************************************************/
/* importFromWkb() */
/* */
/* Disable method for this class. */
/************************************************************************/
OGRErr OGRLinearRing::importFromWkb( unsigned char *pabyData, int nSize )
{
(void) pabyData;
(void) nSize;
return OGRERR_UNSUPPORTED_OPERATION;
}
/************************************************************************/
/* exportToWkb() */
/* */
/* Disable method for this class. */
/************************************************************************/
OGRErr OGRLinearRing::exportToWkb( OGRwkbByteOrder eByteOrder,
unsigned char * pabyData ) const
{
(void) eByteOrder;
(void) pabyData;
return OGRERR_UNSUPPORTED_OPERATION;
}
/************************************************************************/
/* _importFromWkb() */
/* */
/* Helper method for OGRPolygon. NOT A NORMAL importFromWkb() */
/* method! */
/************************************************************************/
OGRErr OGRLinearRing::_importFromWkb( OGRwkbByteOrder eByteOrder, int b3D,
unsigned char * pabyData,
int nBytesAvailable )
{
if( nBytesAvailable < 4 && nBytesAvailable != -1 )
return OGRERR_NOT_ENOUGH_DATA;
/* -------------------------------------------------------------------- */
/* Get the vertex count. */
/* -------------------------------------------------------------------- */
int nNewNumPoints;
memcpy( &nNewNumPoints, pabyData, 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 = (b3D ? 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;
}
/* (Re)Allocation of paoPoints buffer. */
setNumPoints( nNewNumPoints );
if( b3D )
Make3D();
else
Make2D();
/* -------------------------------------------------------------------- */
/* Get the vertices */
/* -------------------------------------------------------------------- */
int i = 0;
int nBytesToCopy = 0;
if( !b3D )
{
nBytesToCopy = 16 * nPointCount;
if( nBytesToCopy > nBytesAvailable && nBytesAvailable > 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"WKB buffer with OGRLinearRing 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 + 4, nBytesToCopy );
}
else
{
for( int i = 0; i < nPointCount; i++ )
{
nBytesToCopy = 24;
if( nBytesToCopy > nBytesAvailable && nBytesAvailable > 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"WKB buffer with OGRLinearRing 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].x), pabyData + 4 + 24 * i, 8 );
memcpy( &(paoPoints[i].y), pabyData + 4 + 24 * i + 8, 8 );
memcpy( padfZ + i, pabyData + 4 + 24 * i + 16, 8 );
}
}
/* -------------------------------------------------------------------- */
/* 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( b3D )
{
CPL_SWAPDOUBLE( padfZ + i );
}
}
}
return OGRERR_NONE;
}
/************************************************************************/
/* _exportToWkb() */
/* */
/* Helper method for OGRPolygon. THIS IS NOT THE NORMAL */
/* exportToWkb() METHOD! */
/************************************************************************/
OGRErr OGRLinearRing::_exportToWkb( OGRwkbByteOrder eByteOrder, int b3D,
unsigned char * pabyData ) const
{
int i, nWords;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -