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

📄 s57reader.cpp

📁 支持各种栅格图像和矢量图像读取的库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            switch( nRCNM )            {              case RCNM_VI:                oVI_Index.AddRecord( nRCID, poRecord->Clone() );                break;              case RCNM_VC:                oVC_Index.AddRecord( nRCID, poRecord->Clone() );                break;              case RCNM_VE:                oVE_Index.AddRecord( nRCID, poRecord->Clone() );                break;              case RCNM_VF:                oVF_Index.AddRecord( nRCID, poRecord->Clone() );                break;              default:                CPLAssert( FALSE );                break;            }        }        else if( EQUAL(poKeyField->GetFieldDefn()->GetName(),"FRID") )        {            int         nRCID = poRecord->GetIntSubfield( "FRID",0, "RCID",0);                        oFE_Index.AddRecord( nRCID, poRecord->Clone() );        }        else if( EQUAL(poKeyField->GetFieldDefn()->GetName(),"DSID") )        {            CPLFree( pszDSNM );            pszDSNM =                CPLStrdup(poRecord->GetStringSubfield( "DSID", 0, "DSNM", 0 ));            if( nOptionFlags & S57M_RETURN_DSID )            {                if( poDSIDRecord != NULL )                    delete poDSIDRecord;                poDSIDRecord = poRecord->Clone();            }        }        else if( EQUAL(poKeyField->GetFieldDefn()->GetName(),"DSPM") )        {            nCOMF = MAX(1,poRecord->GetIntSubfield( "DSPM",0, "COMF",0));            nSOMF = MAX(1,poRecord->GetIntSubfield( "DSPM",0, "SOMF",0));            if( nOptionFlags & S57M_RETURN_DSID )            {                if( poDSPMRecord != NULL )                    delete poDSPMRecord;                poDSPMRecord = poRecord->Clone();            }        }        else        {            CPLDebug( "S57",                      "Skipping %s record in S57Reader::Ingest().\n",                      poKeyField->GetFieldDefn()->GetName() );        }    }    bFileIngested = TRUE;/* -------------------------------------------------------------------- *//*      If update support is enabled, read and apply them.              *//* -------------------------------------------------------------------- */    if( nOptionFlags & S57M_UPDATES )        FindAndApplyUpdates();}/************************************************************************//*                           SetNextFEIndex()                           *//************************************************************************/void S57Reader::SetNextFEIndex( int nNewIndex, int nRCNM ){    if( nRCNM == RCNM_VI )        nNextVIIndex = nNewIndex;    else if( nRCNM == RCNM_VC )        nNextVCIndex = nNewIndex;    else if( nRCNM == RCNM_VE )        nNextVEIndex = nNewIndex;    else if( nRCNM == RCNM_VF )        nNextVFIndex = nNewIndex;    else if( nRCNM == RCNM_DSID )        nNextDSIDIndex = nNewIndex;    else    {        if( nNextFEIndex != nNewIndex )            ClearPendingMultiPoint();                nNextFEIndex = nNewIndex;    }}/************************************************************************//*                           GetNextFEIndex()                           *//************************************************************************/int S57Reader::GetNextFEIndex( int nRCNM ){    if( nRCNM == RCNM_VI )        return nNextVIIndex;    else if( nRCNM == RCNM_VC )        return nNextVCIndex;    else if( nRCNM == RCNM_VE )        return nNextVEIndex;    else if( nRCNM == RCNM_VF )        return nNextVFIndex;    else if( nRCNM == RCNM_DSID )        return nNextDSIDIndex;    else        return nNextFEIndex;}/************************************************************************//*                          ReadNextFeature()                           *//************************************************************************/OGRFeature * S57Reader::ReadNextFeature( OGRFeatureDefn * poTarget ){    if( !bFileIngested )        Ingest();/* -------------------------------------------------------------------- *//*      Special case for "in progress" multipoints being split up.      *//* -------------------------------------------------------------------- */    if( poMultiPoint != NULL )    {        if( poTarget == NULL || poTarget == poMultiPoint->GetDefnRef() )        {            return NextPendingMultiPoint();        }        else        {            ClearPendingMultiPoint();        }    }/* -------------------------------------------------------------------- *//*      Next vector feature?                                            *//* -------------------------------------------------------------------- */    if( (nOptionFlags & S57M_RETURN_DSID)         && nNextDSIDIndex == 0         && (poTarget == NULL || EQUAL(poTarget->GetName(),"DSID")) )    {        return ReadDSID();    }        /* -------------------------------------------------------------------- *//*      Next vector feature?                                            *//* -------------------------------------------------------------------- */    if( nOptionFlags & S57M_RETURN_PRIMITIVES )    {        int nRCNM = 0;        int *pnCounter = NULL;        if( poTarget == NULL )        {            if( nNextVIIndex < oVI_Index.GetCount() )            {                nRCNM = RCNM_VI;                pnCounter = &nNextVIIndex;            }            else if( nNextVCIndex < oVC_Index.GetCount() )            {                nRCNM = RCNM_VC;                pnCounter = &nNextVCIndex;            }            else if( nNextVEIndex < oVE_Index.GetCount() )            {                nRCNM = RCNM_VE;                pnCounter = &nNextVEIndex;            }            else if( nNextVFIndex < oVF_Index.GetCount() )            {                nRCNM = RCNM_VF;                pnCounter = &nNextVFIndex;            }        }        else        {            if( EQUAL(poTarget->GetName(),OGRN_VI) )            {                nRCNM = RCNM_VI;                pnCounter = &nNextVIIndex;            }            else if( EQUAL(poTarget->GetName(),OGRN_VC) )            {                nRCNM = RCNM_VC;                pnCounter = &nNextVCIndex;            }            else if( EQUAL(poTarget->GetName(),OGRN_VE) )            {                nRCNM = RCNM_VE;                pnCounter = &nNextVEIndex;            }            else if( EQUAL(poTarget->GetName(),OGRN_VF) )            {                nRCNM = RCNM_VF;                pnCounter = &nNextVFIndex;            }        }        if( nRCNM != 0 )        {            OGRFeature *poFeature = ReadVector( *pnCounter, nRCNM );            if( poFeature != NULL )            {                *pnCounter += 1;                return poFeature;            }        }    }        /* -------------------------------------------------------------------- *//*      Next feature.                                                   *//* -------------------------------------------------------------------- */    while( nNextFEIndex < oFE_Index.GetCount() )    {        OGRFeature      *poFeature;        OGRFeatureDefn *poFeatureDefn;        poFeatureDefn = (OGRFeatureDefn *)             oFE_Index.GetClientInfoByIndex( nNextFEIndex );        if( poFeatureDefn == NULL )        {            poFeatureDefn = FindFDefn( oFE_Index.GetByIndex( nNextFEIndex ) );            oFE_Index.SetClientInfoByIndex( nNextFEIndex, poFeatureDefn );        }        if( poFeatureDefn != poTarget && poTarget != NULL )        {            nNextFEIndex++;            continue;        }        poFeature = ReadFeature( nNextFEIndex++, poTarget );        if( poFeature != NULL )        {            if( (nOptionFlags & S57M_SPLIT_MULTIPOINT)                && poFeature->GetGeometryRef() != NULL                && wkbFlatten(poFeature->GetGeometryRef()->getGeometryType())                                                        == wkbMultiPoint)            {                poMultiPoint = poFeature;                iPointOffset = 0;                return NextPendingMultiPoint();            }            return poFeature;        }    }    return NULL;}/************************************************************************//*                            ReadFeature()                             *//*                                                                      *//*      Read the features who's id is provided.                         *//************************************************************************/OGRFeature *S57Reader::ReadFeature( int nFeatureId, OGRFeatureDefn *poTarget ){    OGRFeature  *poFeature;    if( nFeatureId < 0 || nFeatureId >= oFE_Index.GetCount() )        return NULL;    poFeature = AssembleFeature( oFE_Index.GetByIndex(nFeatureId),                                 poTarget );    if( poFeature != NULL )        poFeature->SetFID( nFeatureId );    return poFeature;}/************************************************************************//*                          AssembleFeature()                           *//*                                                                      *//*      Assemble an OGR feature based on a feature record.              *//************************************************************************/OGRFeature *S57Reader::AssembleFeature( DDFRecord * poRecord,                                        OGRFeatureDefn * poTarget ){    int         nPRIM, nOBJL;    OGRFeatureDefn *poFDefn;/* -------------------------------------------------------------------- *//*      Find the feature definition to use.  Currently this is based    *//*      on the primitive, but eventually this should be based on the    *//*      object class (FRID.OBJL) in some cases, and the primitive in    *//*      others.                                                         *//* -------------------------------------------------------------------- */    poFDefn = FindFDefn( poRecord );    if( poFDefn == NULL )        return NULL;/* -------------------------------------------------------------------- *//*      Does this match our target feature definition?  If not skip     *//*      this feature.                                                   *//* -------------------------------------------------------------------- */    if( poTarget != NULL && poFDefn != poTarget )        return NULL;/* -------------------------------------------------------------------- *//*      Create the new feature object.                                  *//* -------------------------------------------------------------------- */    OGRFeature          *poFeature;    poFeature = new OGRFeature( poFDefn );/* -------------------------------------------------------------------- *//*      Assign a few standard feature attribues.                        *//* -------------------------------------------------------------------- */    nOBJL = poRecord->GetIntSubfield( "FRID", 0, "OBJL", 0 );    poFeature->SetField( "OBJL", nOBJL );    poFeature->SetField( "RCID",                         poRecord->GetIntSubfield( "FRID", 0, "RCID", 0 ));    poFeature->SetField( "PRIM",                         poRecord->GetIntSubfield( "FRID", 0, "PRIM", 0 ));    poFeature->SetField( "GRUP",                         poRecord->GetIntSubfield( "FRID", 0, "GRUP", 0 ));    poFeature->SetField( "RVER",                         poRecord->GetIntSubfield( "FRID", 0, "RVER", 0 ));    poFeature->SetField( "AGEN",                         poRecord->GetIntSubfield( "FOID", 0, "AGEN", 0 ));    poFeature->SetField( "FIDN",                         poRecord->GetIntSubfield( "FOID", 0, "FIDN", 0 ));    poFeature->SetField( "FIDS",                         poRecord->GetIntSubfield( "FOID", 0, "FIDS", 0 ));/* -------------------------------------------------------------------- *//*      Generate long name, if requested.                               *//* -------------------------------------------------------------------- */    if( nOptionFlags & S57M_LNAM_REFS )    {        GenerateLNAMAndRefs( poRecord, poFeature );    }/* -------------------------------------------------------------------- *//*      Generate primitive references if requested.                     *//* -------------------------------------------------------------------- */    if( nOptionFlags & S57M_RETURN_LINKAGES )        GenerateFSPTAttributes( poRecord, poFeature );

⌨️ 快捷键说明

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