📄 ogrpoint.cpp
字号:
/******************************************************************************
* $Id: ogrpoint.cpp 10646 2007-01-18 02:38:10Z warmerdam $
*
* Project: OpenGIS Simple Features Reference Implementation
* Purpose: The Point 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"
#include <assert.h>
CPL_CVSID("$Id: ogrpoint.cpp 10646 2007-01-18 02:38:10Z warmerdam $");
/************************************************************************/
/* OGRPoint() */
/************************************************************************/
/**
* Create a (0,0) point.
*/
OGRPoint::OGRPoint()
{
x = 0;
y = 0;
z = 0;
}
/************************************************************************/
/* OGRPoint() */
/* */
/* Initialize point to value. */
/************************************************************************/
OGRPoint::OGRPoint( double xIn, double yIn, double zIn )
{
x = xIn;
y = yIn;
z = zIn;
nCoordDimension = 3;
}
/************************************************************************/
/* OGRPoint() */
/* */
/* Initialize point to value. */
/************************************************************************/
OGRPoint::OGRPoint( double xIn, double yIn )
{
x = xIn;
y = yIn;
z = 0.0;
nCoordDimension = 2;
}
/************************************************************************/
/* ~OGRPoint() */
/************************************************************************/
OGRPoint::~OGRPoint()
{
}
/************************************************************************/
/* clone() */
/* */
/* Make a new object that is a copy of this object. */
/************************************************************************/
OGRGeometry *OGRPoint::clone() const
{
OGRPoint *poNewPoint = new OGRPoint( x, y, z );
poNewPoint->assignSpatialReference( getSpatialReference() );
poNewPoint->setCoordinateDimension( nCoordDimension );
return poNewPoint;
}
/************************************************************************/
/* empty() */
/************************************************************************/
void OGRPoint::empty()
{
x = y = z = 0.0;
}
/************************************************************************/
/* getDimension() */
/************************************************************************/
int OGRPoint::getDimension() const
{
return 0;
}
/************************************************************************/
/* getGeometryType() */
/************************************************************************/
OGRwkbGeometryType OGRPoint::getGeometryType() const
{
if( nCoordDimension < 3 )
return wkbPoint;
else
return wkbPoint25D;
}
/************************************************************************/
/* getGeometryName() */
/************************************************************************/
const char * OGRPoint::getGeometryName() const
{
return "POINT";
}
/************************************************************************/
/* flattenTo2D() */
/************************************************************************/
void OGRPoint::flattenTo2D()
{
z = 0;
nCoordDimension = 2;
}
/************************************************************************/
/* setCoordinateDimension() */
/************************************************************************/
void OGRPoint::setCoordinateDimension( int nNewDimension )
{
nCoordDimension = nNewDimension;
if( nCoordDimension == 2 )
z = 0;
}
/************************************************************************/
/* WkbSize() */
/* */
/* Return the size of this object in well known binary */
/* representation including the byte order, and type information. */
/************************************************************************/
int OGRPoint::WkbSize() const
{
if( nCoordDimension != 3 )
return 21;
else
return 29;
}
/************************************************************************/
/* importFromWkb() */
/* */
/* Initialize from serialized stream in well known binary */
/* format. */
/************************************************************************/
OGRErr OGRPoint::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;
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;
}
assert( eGeometryType == wkbPoint );
/* -------------------------------------------------------------------- */
/* Get the vertex. */
/* -------------------------------------------------------------------- */
memcpy( &x, pabyData + 5, 16 );
if( OGR_SWAP( eByteOrder ) )
{
CPL_SWAPDOUBLE( &x );
CPL_SWAPDOUBLE( &y );
}
if( bIs3D )
{
memcpy( &z, pabyData + 5 + 16, 8 );
if( OGR_SWAP( eByteOrder ) )
{
CPL_SWAPDOUBLE( &z );
}
nCoordDimension = 3;
}
else
{
z = 0;
nCoordDimension = 2;
}
return OGRERR_NONE;
}
/************************************************************************/
/* exportToWkb() */
/* */
/* Build a well known binary representation of this object. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -