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

📄 s57reader.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    {#ifdef DEBUG        fprintf( stderr,                  "Point features with other than one spatial linkage.\n" );        poFRecord->Dump( stderr );#endif        CPLDebug( "S57",            "Point feature encountered with other than one spatial linkage." );    }            nRCID = ParseName( poFSPT, 0, &nRCNM );    double      dfX = 0.0, dfY = 0.0, dfZ = 0.0;    if( !FetchPoint( nRCNM, nRCID, &dfX, &dfY, &dfZ ) )    {        CPLAssert( FALSE );        return;    }    poFeature->SetGeometryDirectly( new OGRPoint( dfX, dfY, dfZ ) );}/************************************************************************//*                      AssembleSoundingGeometry()                      *//************************************************************************/void S57Reader::AssembleSoundingGeometry( DDFRecord * poFRecord,                                          OGRFeature * poFeature ){    DDFField    *poFSPT;    int         nRCNM, nRCID;    DDFRecord   *poSRecord;    /* -------------------------------------------------------------------- *//*      Feature the spatial record containing the point.                *//* -------------------------------------------------------------------- */    poFSPT = poFRecord->FindField( "FSPT" );    if( poFSPT == NULL )        return;    CPLAssert( poFSPT->GetRepeatCount() == 1 );            nRCID = ParseName( poFSPT, 0, &nRCNM );    if( nRCNM == RCNM_VI )        poSRecord = oVI_Index.FindRecord( nRCID );    else        poSRecord = oVC_Index.FindRecord( nRCID );    if( poSRecord == NULL )        return;/* -------------------------------------------------------------------- *//*      Extract vertices.                                               *//* -------------------------------------------------------------------- */    OGRMultiPoint       *poMP = new OGRMultiPoint();    DDFField            *poField;    int                 nPointCount, i, nBytesLeft;    DDFSubfieldDefn    *poXCOO, *poYCOO, *poVE3D;    const char         *pachData;    poField = poSRecord->FindField( "SG2D" );    if( poField == NULL )        poField = poSRecord->FindField( "SG3D" );    if( poField == NULL )        return;    poXCOO = poField->GetFieldDefn()->FindSubfieldDefn( "XCOO" );    poYCOO = poField->GetFieldDefn()->FindSubfieldDefn( "YCOO" );    poVE3D = poField->GetFieldDefn()->FindSubfieldDefn( "VE3D" );    nPointCount = poField->GetRepeatCount();    pachData = poField->GetData();    nBytesLeft = poField->GetDataSize();    for( i = 0; i < nPointCount; i++ )    {        double          dfX, dfY, dfZ = 0.0;        int             nBytesConsumed;        dfY = poYCOO->ExtractIntData( pachData, nBytesLeft,                                      &nBytesConsumed ) / (double) nCOMF;        nBytesLeft -= nBytesConsumed;        pachData += nBytesConsumed;        dfX = poXCOO->ExtractIntData( pachData, nBytesLeft,                                      &nBytesConsumed ) / (double) nCOMF;        nBytesLeft -= nBytesConsumed;        pachData += nBytesConsumed;                if( poVE3D != NULL )        {            dfZ = poYCOO->ExtractIntData( pachData, nBytesLeft,                                          &nBytesConsumed ) / (double) nSOMF;            nBytesLeft -= nBytesConsumed;            pachData += nBytesConsumed;        }        poMP->addGeometryDirectly( new OGRPoint( dfX, dfY, dfZ ) );    }    poFeature->SetGeometryDirectly( poMP );}/************************************************************************//*                        AssembleLineGeometry()                        *//************************************************************************/void S57Reader::AssembleLineGeometry( DDFRecord * poFRecord,                                      OGRFeature * poFeature ){    DDFField    *poFSPT;    int         nEdgeCount;    OGRLineString *poLine = new OGRLineString();/* -------------------------------------------------------------------- *//*      Find the FSPT field.                                            *//* -------------------------------------------------------------------- */    poFSPT = poFRecord->FindField( "FSPT" );    if( poFSPT == NULL )        return;    nEdgeCount = poFSPT->GetRepeatCount();/* ==================================================================== *//*      Loop collecting edges.                                          *//* ==================================================================== */    for( int iEdge = 0; iEdge < nEdgeCount; iEdge++ )    {        DDFRecord       *poSRecord;        int             nRCID;/* -------------------------------------------------------------------- *//*      Find the spatial record for this edge.                          *//* -------------------------------------------------------------------- */        nRCID = ParseName( poFSPT, iEdge );        poSRecord = oVE_Index.FindRecord( nRCID );        if( poSRecord == NULL )        {            CPLError( CE_Warning, CPLE_AppDefined,                      "Couldn't find spatial record %d.\n"                      "Feature OBJL=%s, RCID=%d may have corrupt or"                      "missing geometry.",                      nRCID,                      poFeature->GetDefnRef()->GetName(),                      poFRecord->GetIntSubfield( "FRID", 0, "RCID", 0 ) );            continue;        }    /* -------------------------------------------------------------------- *//*      Establish the number of vertices, and whether we need to        *//*      reverse or not.                                                 *//* -------------------------------------------------------------------- */        int             nVCount;        int             nStart, nEnd, nInc;        DDFField        *poSG2D = poSRecord->FindField( "SG2D" );        DDFSubfieldDefn *poXCOO=NULL, *poYCOO=NULL;        if( poSG2D != NULL )        {            poXCOO = poSG2D->GetFieldDefn()->FindSubfieldDefn("XCOO");            poYCOO = poSG2D->GetFieldDefn()->FindSubfieldDefn("YCOO");            nVCount = poSG2D->GetRepeatCount();        }        else            nVCount = 0;        if( poFRecord->GetIntSubfield( "FSPT", 0, "ORNT", iEdge ) == 2 )        {            nStart = nVCount-1;            nEnd = 0;            nInc = -1;        }        else        {            nStart = 0;            nEnd = nVCount-1;            nInc = 1;        }/* -------------------------------------------------------------------- *//*      Add the start node, if this is the first edge.                  *//* -------------------------------------------------------------------- */        if( iEdge == 0 )        {            int         nVC_RCID;            double      dfX, dfY;                        if( nInc == 1 )                nVC_RCID = ParseName( poSRecord->FindField( "VRPT" ), 0 );            else                nVC_RCID = ParseName( poSRecord->FindField( "VRPT" ), 1 );            if( FetchPoint( RCNM_VC, nVC_RCID, &dfX, &dfY ) )                poLine->addPoint( dfX, dfY );            else                CPLError( CE_Warning, CPLE_AppDefined,                           "Unable to fetch start node RCID%d.\n"                          "Feature OBJL=%s, RCID=%d may have corrupt or"                          " missing geometry.",                           nVC_RCID,                           poFeature->GetDefnRef()->GetName(),                          poFRecord->GetIntSubfield( "FRID", 0, "RCID", 0 ) );        }        /* -------------------------------------------------------------------- *//*      Collect the vertices.                                           *//* -------------------------------------------------------------------- */        int             nVBase = poLine->getNumPoints();                poLine->setNumPoints( nVCount+nVBase );        for( int i = nStart; i != nEnd+nInc; i += nInc )        {            double      dfX, dfY;            const char  *pachData;            int         nBytesRemaining;            pachData = poSG2D->GetSubfieldData(poXCOO,&nBytesRemaining,i);                            dfX = poXCOO->ExtractIntData(pachData,nBytesRemaining,NULL)                / (double) nCOMF;            pachData = poSG2D->GetSubfieldData(poYCOO,&nBytesRemaining,i);            dfY = poXCOO->ExtractIntData(pachData,nBytesRemaining,NULL)                / (double) nCOMF;                            poLine->setPoint( nVBase++, dfX, dfY );        }/* -------------------------------------------------------------------- *//*      Add the end node.                                               *//* -------------------------------------------------------------------- */        {            int         nVC_RCID;            double      dfX, dfY;                        if( nInc == 1 )                nVC_RCID = ParseName( poSRecord->FindField( "VRPT" ), 1 );            else                nVC_RCID = ParseName( poSRecord->FindField( "VRPT" ), 0 );            if( FetchPoint( RCNM_VC, nVC_RCID, &dfX, &dfY ) )                poLine->addPoint( dfX, dfY );            else                CPLError( CE_Warning, CPLE_AppDefined,                           "Unable to fetch end node RCID=%d.\n"                          "Feature OBJL=%s, RCID=%d may have corrupt or"                          " missing geometry.",                           nVC_RCID,                           poFeature->GetDefnRef()->GetName(),                          poFRecord->GetIntSubfield( "FRID", 0, "RCID", 0 ) );        }    }    if( poLine->getNumPoints() >= 2 )        poFeature->SetGeometryDirectly( poLine );    else        delete poLine;}/************************************************************************//*                        AssembleAreaGeometry()                        *//************************************************************************/void S57Reader::AssembleAreaGeometry( DDFRecord * poFRecord,                                         OGRFeature * poFeature ){    DDFField    *poFSPT;    OGRGeometryCollection * poLines = new OGRGeometryCollection();/* -------------------------------------------------------------------- *//*      Find the FSPT fields.                                           *//* -------------------------------------------------------------------- */    for( int iFSPT = 0;          (poFSPT = poFRecord->FindField( "FSPT", iFSPT )) != NULL;         iFSPT++ )    {        int         nEdgeCount;        nEdgeCount = poFSPT->GetRepeatCount();/* ==================================================================== *//*      Loop collecting edges.                                          *//* ==================================================================== */        for( int iEdge = 0; iEdge < nEdgeCount; iEdge++ )        {            DDFRecord       *poSRecord;            int             nRCID;/* -------------------------------------------------------------------- *//*      Find the spatial record for this edge.                          *//* -------------------------------------------------------------------- */            nRCID = ParseName( poFSPT, iEdge );            poSRecord = oVE_Index.FindRecord( nRCID );            if( poSRecord == NULL )            {                CPLError( CE_Warning, CPLE_AppDefined,                          "Couldn't find spatial record %d.\n", nRCID );                continue;            }    /* -------------------------------------------------------------------- *//*      Create the line string.                                         *//* -------------------------------------------------------------------- */            OGRLineString *poLine = new OGRLineString();        /* -------------------------------------------------------------------- *//*      Add the start node.                                             *//* -------------------------------------------------------------------- */            {                int         nVC_RCID;                double      dfX, dfY;                            nVC_RCID = ParseName( poSRecord->FindField( "VRPT" ), 0 );                if( FetchPoint( RCNM_VC, nVC_RCID, &dfX, &dfY ) )                    poLine->addPoint( dfX, dfY );            }        /* -------------------------------------------------------------------- *//*      Collect the vertices.                                           *//* -------------------------------------------------------------------- */            if( !FetchLine( poSRecord, poLine->getNumPoints(), 1, poLine ) )            {                CPLDebug( "S57", "FetchLine() failed in AssembleAreaGeometry()!" );                delete poLine;                continue;            }/* -------------------------------------------------------------------- *//*      Add the end node.                                               *//* -------------------------------------------------------------------- */            {                int         nVC_RCID;                double      dfX, dfY;                            nVC_RCID = ParseName( poSRecord->FindField( "VRPT" ), 1 );                if( FetchPoint( RCNM_VC, nVC_RCID, &dfX, &dfY ) )                    poLine->addPoint( dfX, dfY );            }            poLines->addGeometryDirectly( poLine );        }    }/* -------------------------------------------------------------------- *//*      Build lines into a polygon.                                     *//* -------------------------------------------------------------------- */    OGRPolygon  *poPolygon;    OGRErr      eErr;    poPolygon = (OGRPolygon *)         OGRBuildPolygonFromEdges( (OGRGeometryH) poLines,                                   TRUE, FALSE, 0.0, &eErr );    if( eErr != OGRERR_NONE )    {        CPLError( CE_Warning

⌨️ 快捷键说明

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