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

📄 s57reader.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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 );/* -------------------------------------------------------------------- *//*      Apply object class specific attributes, if supported.           *//* -------------------------------------------------------------------- */    if( poRegistrar != NULL )        ApplyObjectClassAttributes( poRecord, poFeature );/* -------------------------------------------------------------------- *//*      Find and assign spatial component.                              *//* -------------------------------------------------------------------- */    nPRIM = poRecord->GetIntSubfield( "FRID", 0, "PRIM", 0 );    if( nPRIM == PRIM_P )    {        if( nOBJL == 129 ) /* SOUNDG */            AssembleSoundingGeometry( poRecord, poFeature );        else            AssemblePointGeometry( poRecord, poFeature );    }    else if( nPRIM == PRIM_L )    {        AssembleLineGeometry( poRecord, poFeature );    }    else if( nPRIM == PRIM_A )    {        AssembleAreaGeometry( poRecord, poFeature );    }    return poFeature;}/************************************************************************//*                     ApplyObjectClassAttributes()                     *//************************************************************************/void S57Reader::ApplyObjectClassAttributes( DDFRecord * poRecord,                                            OGRFeature * poFeature ){/* -------------------------------------------------------------------- *//*      ATTF Attributes                                                 *//* -------------------------------------------------------------------- */    DDFField    *poATTF = poRecord->FindField( "ATTF" );    int         nAttrCount, iAttr;    if( poATTF == NULL )        return;    nAttrCount = poATTF->GetRepeatCount();    for( iAttr = 0; iAttr < nAttrCount; iAttr++ )    {        int     nAttrId = poRecord->GetIntSubfield("ATTF",0,"ATTL",iAttr);        const char *pszAcronym;                if( nAttrId < 1 || nAttrId > poRegistrar->GetMaxAttrIndex()             || (pszAcronym = poRegistrar->GetAttrAcronym(nAttrId)) == NULL )        {            if( !bAttrWarningIssued )            {                bAttrWarningIssued = TRUE;                CPLError( CE_Warning, CPLE_AppDefined,                          "Illegal feature attribute id (ATTF:ATTL[%d]) of %d\n"                          "on feature FIDN=%d, FIDS=%d.\n"                          "Skipping attribute, no more warnings will be issued.",                          iAttr, nAttrId,                           poFeature->GetFieldAsInteger( "FIDN" ),                          poFeature->GetFieldAsInteger( "FIDS" ) );            }            continue;        }        /* Fetch the attribute value */        const char *pszValue;        pszValue = poRecord->GetStringSubfield("ATTF",0,"ATVL",iAttr);                /* Apply to feature in an appropriate way */        int iField;        OGRFieldDefn *poFldDefn;        iField = poFeature->GetDefnRef()->GetFieldIndex(pszAcronym);        if( iField < 0 )        {            if( !bMissingWarningIssued )            {                bMissingWarningIssued = TRUE;                CPLError( CE_Warning, CPLE_AppDefined,                           "Attributes %s ignored, not in expected schema.\n"                          "No more warnings will be issued for this dataset.",                           pszAcronym );            }            continue;        }        poFldDefn = poFeature->GetDefnRef()->GetFieldDefn( iField );        if( poFldDefn->GetType() == OFTInteger             || poFldDefn->GetType() == OFTReal )        {            if( strlen(pszValue) == 0 )            {                if( nOptionFlags & S57M_PRESERVE_EMPTY_NUMBERS )                    poFeature->SetField( iField, EMPTY_NUMBER_MARKER );                else                    /* leave as null if value was empty string */;            }            else                poFeature->SetField( iField, pszValue );        }        else            poFeature->SetField( iField, pszValue );    }    /* -------------------------------------------------------------------- *//*      NATF (national) attributes                                      *//* -------------------------------------------------------------------- */    DDFField    *poNATF = poRecord->FindField( "NATF" );    if( poNATF == NULL )        return;    nAttrCount = poNATF->GetRepeatCount();    for( iAttr = 0; iAttr < nAttrCount; iAttr++ )    {        int     nAttrId = poRecord->GetIntSubfield("NATF",0,"ATTL",iAttr);        const char *pszAcronym;        if( nAttrId < 1 || nAttrId >= poRegistrar->GetMaxAttrIndex()            || (pszAcronym = poRegistrar->GetAttrAcronym(nAttrId)) == NULL )        {            static int bAttrWarningIssued = FALSE;            if( !bAttrWarningIssued )            {                bAttrWarningIssued = TRUE;                CPLError( CE_Warning, CPLE_AppDefined,                          "Illegal feature attribute id (NATF:ATTL[%d]) of %d\n"                          "on feature FIDN=%d, FIDS=%d.\n"                          "Skipping attribute, no more warnings will be issued.",                          iAttr, nAttrId,                           poFeature->GetFieldAsInteger( "FIDN" ),                          poFeature->GetFieldAsInteger( "FIDS" ) );            }            continue;        }                poFeature->SetField( pszAcronym,                              poRecord->GetStringSubfield("NATF",0,"ATVL",iAttr) );    }}/************************************************************************//*                        GenerateLNAMAndRefs()                         *//************************************************************************/void S57Reader::GenerateLNAMAndRefs( DDFRecord * poRecord,                                     OGRFeature * poFeature ){    char        szLNAM[32];        /* -------------------------------------------------------------------- *//*      Apply the LNAM to the object.                                   *//* -------------------------------------------------------------------- */    sprintf( szLNAM, "%04X%08X%04X",             poFeature->GetFieldAsInteger( "AGEN" ),             poFeature->GetFieldAsInteger( "FIDN" ),             poFeature->GetFieldAsInteger( "FIDS" ) );    poFeature->SetField( "LNAM", szLNAM );/* -------------------------------------------------------------------- *//*      Do we have references to other features.                        *//* -------------------------------------------------------------------- */    DDFField    *poFFPT;    poFFPT = poRecord->FindField( "FFPT" );    if( poFFPT == NULL )        return;/* -------------------------------------------------------------------- *//*      Apply references.                                               *//* -------------------------------------------------------------------- */    int         nRefCount = poFFPT->GetRepeatCount();    DDFSubfieldDefn *poLNAM;    char        **papszRefs = NULL;    int         *panRIND = (int *) CPLMalloc(sizeof(int) * nRefCount);    poLNAM = poFFPT->GetFieldDefn()->FindSubfieldDefn( "LNAM" );    if( poLNAM == NULL )        return;    for( int iRef = 0; iRef < nRefCount; iRef++ )    {        unsigned char *pabyData;        pabyData = (unsigned char *)            poFFPT->GetSubfieldData( poLNAM, NULL, iRef );                sprintf( szLNAM, "%02X%02X%02X%02X%02X%02X%02X%02X",                 pabyData[1], pabyData[0], /* AGEN */                 pabyData[5], pabyData[4], pabyData[3], pabyData[2], /* FIDN */                 pabyData[7], pabyData[6] );        papszRefs = CSLAddString( papszRefs, szLNAM );        panRIND[iRef] = pabyData[8];    }    poFeature->SetField( "LNAM_REFS", papszRefs );    CSLDestroy( papszRefs );    poFeature->SetField( "FFPT_RIND", nRefCount, panRIND );    CPLFree( panRIND );}/************************************************************************//*                       GenerateFSPTAttributes()                       *//************************************************************************/void S57Reader::GenerateFSPTAttributes( DDFRecord * poRecord,                                        OGRFeature * poFeature ){/* -------------------------------------------------------------------- *//*      Feature the spatial record containing the point.                *//* -------------------------------------------------------------------- */    DDFField    *poFSPT;    int         nCount, i;    poFSPT = poRecord->FindField( "FSPT" );    if( poFSPT == NULL )        return;            nCount = poFSPT->GetRepeatCount();/* -------------------------------------------------------------------- *//*      Allocate working lists of the attributes.                       *//* -------------------------------------------------------------------- */    int *panORNT, *panUSAG, *panMASK, *panRCNM, *panRCID;        panORNT = (int *) CPLMalloc( sizeof(int) * nCount );    panUSAG = (int *) CPLMalloc( sizeof(int) * nCount );    panMASK = (int *) CPLMalloc( sizeof(int) * nCount );    panRCNM = (int *) CPLMalloc( sizeof(int) * nCount );    panRCID = (int *) CPLMalloc( sizeof(int) * nCount );/* -------------------------------------------------------------------- *//*      loop over all entries, decoding them.                           *//* -------------------------------------------------------------------- */    for( i = 0; i < nCount; i++ )    {        panRCID[i] = ParseName( poFSPT, i, panRCNM + i );        panORNT[i] = poRecord->GetIntSubfield( "FSPT", 0, "ORNT",i);        panUSAG[i] = poRecord->GetIntSubfield( "FSPT", 0, "USAG",i);        panMASK[i] = poRecord->GetIntSubfield( "FSPT", 0, "MASK",i);    }/* -------------------------------------------------------------------- *//*      Assign to feature.                                              *//* -------------------------------------------------------------------- */    poFeature->SetField( "NAME_RCNM", nCount, panRCNM );    poFeature->SetField( "NAME_RCID", nCount, panRCID );    poFeature->SetField( "ORNT", nCount, panORNT );    poFeature->SetField( "USAG", nCount, panUSAG );    poFeature->SetField( "MASK", nCount, panMASK );/* -------------------------------------------------------------------- *//*      Cleanup.                                                        *//* -------------------------------------------------------------------- */    CPLFree( panRCNM );    CPLFree( panRCID );    CPLFree( panORNT );    CPLFree( panUSAG );    CPLFree( panMASK );}/************************************************************************//*                             ReadVector()                             *//*                                                                      *//*      Read a vector primitive objects based on the type (RCNM_)       *//*      and index within the related index.                             *//************************************************************************/OGRFeature *S57Reader::ReadVector( int nFeatureId, int nRCNM ){    DDFRecordIndex *poIndex;    const char *pszFDName = NULL;/* -------------------------------------------------------------------- *//*      What type of vector are we fetching.                            *//* -------------------------------------------------------------------- */    switch( nRCNM )    {

⌨️ 快捷键说明

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