⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ugklinestring.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ugklinestring.cpp: implementation of the UGKLineString class.////////////////////////////////////////////////////////////////////////#include "ugklinestring.h"#include "ugk_memopr.h"/************************************************************************//*                           UGKLineString()                            *//************************************************************************/UGKLineString::UGKLineString(){	nPointCount = 0;	paoPoints = NULL;	padfZ = NULL;}/************************************************************************//*                           ~UGKLineString()                           *//************************************************************************/UGKLineString::~UGKLineString(){	if ( paoPoints != NULL)		UGK_Free(paoPoints);	if( padfZ != NULL )		UGK_Free(padfZ);}/************************************************************************//*                          getGeometryName()                           *//************************************************************************/const char * UGKLineString::getGeometryName() const{    return "LINESTRING";}/************************************************************************//*                          getGeometryType()                           *//************************************************************************/UGKwkbGeometryType UGKLineString::getGeometryType() const{    if( getCoordinateDimension() == 3 )        return wkbLineString25D;    else        return wkbLineString;}/************************************************************************//*                       getCoordinateDimension()                       *//************************************************************************/int UGKLineString::getCoordinateDimension() const{    if( padfZ != NULL )        return 3;    else        return 2;}/************************************************************************//*                            getDimension()                            *//************************************************************************/int UGKLineString::getDimension() const{    return 1;  //一维}/************************************************************************//*                               empty()                                *//************************************************************************/void UGKLineString::empty(){    setNumPoints( 0 );}/************************************************************************//*                            flattenTo2D()                             *//************************************************************************/void UGKLineString::flattenTo2D(){    Make2D();}/************************************************************************//*                               Make2D()                               *//*                              强制转换为2D                            *//************************************************************************/void UGKLineString::Make2D(){    if( padfZ != NULL )    {        UGK_Free( padfZ );        padfZ = NULL;    }}/************************************************************************//*                               clone()                                *//************************************************************************/UGKGeometry *UGKLineString::clone() const{    UGKLineString       *poNewLineString;    poNewLineString = new UGKLineString();     poNewLineString->setPoints( nPointCount, paoPoints, padfZ );     return poNewLineString;}/************************************************************************//*                              WkbSize()                               *//*                                                                      *//*      Return the size of this object in well known binary(WKB)        *//*      representation including the byte order, and type information.  *//************************************************************************/int UGKLineString::WkbSize() const{    return 5 + 4 + 8 * nPointCount * getCoordinateDimension();}/************************************************************************//*                               Make3D()                               *//*                            强制转换为3维                             *//************************************************************************/void UGKLineString::Make3D(){    if( padfZ == NULL )    {        if( nPointCount == 0 )            padfZ = (double *) UGK_Calloc(sizeof(double),1);        else            padfZ = (double *) UGK_Calloc(sizeof(double),nPointCount);    }}/************************************************************************//*                              getPoint()                              *//************************************************************************//** * Fetch a point in line string. */void  UGKLineString::getPoint( int i, UGKPoint * poPoint ) const{    assert( i >= 0 );    assert( i < nPointCount );    assert( poPoint != NULL );    poPoint->setX( paoPoints[i].x );    poPoint->setY( paoPoints[i].y );    if( getCoordinateDimension() == 3 ) //如果是三维        poPoint->setZ( padfZ[i] );}/************************************************************************//*                                getZ()                                *//*                            返回指定点的Z坐标                         *//************************************************************************/double UGKLineString::getZ( int i ) const{    if( padfZ != NULL && i >= 0 && i < nPointCount )        return( padfZ[i] );    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().  */void UGKLineString::setNumPoints( int nNewPointCount ){    if( nNewPointCount == 0 ) //置0    {        UGK_Free( paoPoints );        paoPoints = NULL;                UGK_Free( padfZ );        padfZ = NULL;                nPointCount = 0;        return;    }  //如果比当前已有的顶点数少,则不做任何操作    if( nNewPointCount > nPointCount )     {        paoPoints = (UGKRawPoint *)            UGK_Realloc(paoPoints, sizeof(UGKRawPoint) * nNewPointCount);        assert( paoPoints != NULL );                memset( paoPoints + nPointCount,                         0, sizeof(UGKRawPoint) * (nNewPointCount - nPointCount) );        // 对于新增加的顶点的值赋初值0        if( getCoordinateDimension() == 3 )        {            padfZ = (double *)                UGK_Realloc( 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. * */void UGKLineString::setPoint( int iPoint, UGKPoint * 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. *  * * @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 UGKLineString::setPoint( int iPoint, double xIn, double yIn, double zIn ){    if( iPoint >= nPointCount ) //如果超过当前已有的顶点数        setNumPoints( iPoint+1 );    paoPoints[iPoint].x = xIn;    paoPoints[iPoint].y = yIn;    if( zIn != 0.0 )    {//-----------如果原来所有的点都是二维的,而这里设置点的Z坐标不为0------        Make3D();  //强制转换为3维        padfZ[iPoint] = zIn;    }    else if( getCoordinateDimension() == 3 )    {        padfZ[iPoint] = 0.0;    }}/************************************************************************//*                              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. */void UGKLineString::addPoint( UGKPoint * 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. * @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 UGKLineString::addPoint( double x, double y, double z ){    setPoint( nPointCount, x, y, z );}/************************************************************************//*                             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. * * @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). */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -