📄 s57reader.cpp
字号:
/* -------------------------------------------------------------------- *//* 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 );}/************************************************************************//* ReadDSID() *//************************************************************************/OGRFeature *S57Reader::ReadDSID(){ if( poDSIDRecord == NULL && poDSPMRecord == NULL ) return NULL;/* -------------------------------------------------------------------- *//* Find the feature definition to use. *//* -------------------------------------------------------------------- */ OGRFeatureDefn *poFDefn = NULL; for( int i = 0; i < nFDefnCount; i++ ) { if( EQUAL(papoFDefnList[i]->GetName(),"DSID") ) { poFDefn = papoFDefnList[i]; break; } } if( poFDefn == NULL ) { CPLAssert( FALSE ); return NULL; }/* -------------------------------------------------------------------- *//* Create feature. *//* -------------------------------------------------------------------- */ OGRFeature *poFeature = new OGRFeature( poFDefn );/* -------------------------------------------------------------------- *//* Apply DSID values. *//* -------------------------------------------------------------------- */ if( poDSIDRecord != NULL ) { poFeature->SetField( "DSID_EXPP", poDSIDRecord->GetIntSubfield( "DSID", 0, "EXPP", 0 )); poFeature->SetField( "DSID_INTU", poDSIDRecord->GetIntSubfield( "DSID", 0, "INTU", 0 )); poFeature->SetField( "DSID_DSNM", poDSIDRecord->GetStringSubfield( "DSID", 0, "DSNM", 0 )); poFeature->SetField( "DSID_EDTN", poDSIDRecord->GetStringSubfield( "DSID", 0, "EDTN", 0 )); if( strlen(szUPDNUpdate) > 0 ) poFeature->SetField( "DSID_UPDN", szUPDNUpdate ); else poFeature->SetField( "DSID_UPDN", poDSIDRecord->GetStringSubfield( "DSID", 0, "UPDN", 0 )); poFeature->SetField( "DSID_UADT", poDSIDRecord->GetStringSubfield( "DSID", 0, "UADT", 0 )); poFeature->SetField( "DSID_ISDT", poDSIDRecord->GetStringSubfield( "DSID", 0, "ISDT", 0 )); poFeature->SetField( "DSID_STED", poDSIDRecord->GetFloatSubfield( "DSID", 0, "STED", 0 )); poFeature->SetField( "DSID_PRSP", poDSIDRecord->GetIntSubfield( "DSID", 0, "PRSP", 0 )); poFeature->SetField( "DSID_PSDN", poDSIDRecord->GetStringSubfield( "DSID", 0, "PSDN", 0 )); poFeature->SetField( "DSID_PRED", poDSIDRecord->GetStringSubfield( "DSID", 0, "PRED", 0 )); poFeature->SetField( "DSID_PROF", poDSIDRecord->GetIntSubfield( "DSID", 0, "PROF", 0 )); poFeature->SetField( "DSID_AGEN", poDSIDRecord->GetIntSubfield( "DSID", 0, "AGEN", 0 )); poFeature->SetField( "DSID_COMT", poDSIDRecord->GetStringSubfield( "DSID", 0, "COMT", 0 ));/* -------------------------------------------------------------------- *//* Apply DSSI values. *//* -------------------------------------------------------------------- */ poFeature->SetField( "DSSI_DSTR", poDSIDRecord->GetIntSubfield( "DSSI", 0, "DSTR", 0 )); poFeature->SetField( "DSSI_AALL", poDSIDRecord->GetIntSubfield( "DSSI", 0, "AALL", 0 )); poFeature->SetField( "DSSI_NALL", poDSIDRecord->GetIntSubfield( "DSSI", 0, "NALL", 0 )); poFeature->SetField( "DSSI_NOMR", poDSIDRecord->GetIntSubfield( "DSSI", 0, "NOMR", 0 )); poFeature->SetField( "DSSI_NOCR", poDSIDRecord->GetIntSubfield( "DSSI", 0, "NOCR", 0 )); poFeature->SetField( "DSSI_NOGR", poDSIDRecord->GetIntSubfield( "DSSI", 0, "NOGR", 0 ));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -