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

📄 ogrlinestring.cpp

📁 在linux环境下
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{    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( 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;    }}/************************************************************************//*                              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 );}/************************************************************************//*                             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 )    {        int     i, bIs3D = FALSE;        for( i = 0; i < nPointsIn && !bIs3D; i++ )        {            if( padfZ[i] != 0.0 )                bIs3D = TRUE;        }        if( !bIs3D )            padfZ = NULL;    }    if( padfZ == NULL )    {        if( this->padfZ != NULL )            Make2D();    }    else    {        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 )    {        int     bIs3D = FALSE;        for( i = 0; i < nPointsIn && !bIs3D; i++ )        {            if( padfZ[i] != 0.0 )                bIs3D = TRUE;        }        if( !bIs3D )            padfZ = NULL;    }    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 );}/************************************************************************//*                           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;    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);    setNumPoints( nNewNumPoints );        if( bIs3D )        Make3D();    else        Make2D();    /* -------------------------------------------------------------------- *//*      Get the vertex.                                                 *//* -------------------------------------------------------------------- */    int         i;        if( bIs3D )    {        for( i = 0; i < nPointCount; i++ )        {            memcpy( paoPoints + i, pabyData + 9 + i*24, 16 );            memcpy( padfZ + i, pabyData + 9 + 16 + i*24, 8 );        }    }    else    {        memcpy( paoPoints, pabyData + 9, 16 * nPointCount );    }    /* -------------------------------------------------------------------- *//*      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 ){/* -------------------------------------------------------------------- *//*      Set the byte order.                                             */

⌨️ 快捷键说明

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