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

📄 ogrlinestring.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    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 );    else        nGType = CPL_MSBWORD32( nGType );    memcpy( pabyData + 1, &nGType, 4 );    /* -------------------------------------------------------------------- *//*      Copy in the data count.                                         *//* -------------------------------------------------------------------- */    memcpy( pabyData+5, &nPointCount, 4 );/* -------------------------------------------------------------------- *//*      Copy in the raw data.                                           *//* -------------------------------------------------------------------- */    int         i;        if( getCoordinateDimension() == 3 )    {        for( i = 0; i < nPointCount; i++ )        {            memcpy( pabyData + 9 + 24*i, paoPoints+i, 16 );            memcpy( pabyData + 9 + 16 + 24*i, padfZ+i, 8 );        }    }    else        memcpy( pabyData+9, paoPoints, 16 * nPointCount );/* -------------------------------------------------------------------- *//*      Swap if needed.                                                 *//* -------------------------------------------------------------------- */    if( OGR_SWAP( eByteOrder ) )    {        int     nCount;        nCount = CPL_SWAP32( nPointCount );        memcpy( pabyData+5, &nCount, 4 );        for( i = getCoordinateDimension() * nPointCount - 1; i >= 0; i-- )        {            CPL_SWAP64PTR( pabyData + 9 + 8 * i );        }    }        return OGRERR_NONE;}/************************************************************************//*                           importFromWkt()                            *//*                                                                      *//*      Instantiate from well known text format.  Currently this is     *//*      `LINESTRING ( x y, x y, ...)',                                  *//************************************************************************/OGRErr OGRLineString::importFromWkt( char ** ppszInput ){

⌨️ 快捷键说明

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