📄 ntffilereader.cpp
字号:
poGeometry = new OGRPoint( dfX, dfY, dfZ ); } else if( nGType == 2 ) { OGRLineString *poLine = new OGRLineString; double dfX, dfY, dfZ, dfXLast=0.0, dfYLast=0.0; int iCoord, nOutCount = 0; poGeometry = poLine; poLine->setNumPoints( nNumCoord ); for( iCoord = 0; iCoord < nNumCoord; iCoord++ ) { int iStart = 14 + iCoord * (GetXYLen()*2+nZWidth+2); dfX = atoi(poRecord->GetField(iStart+0, iStart+GetXYLen()-1)) * GetXYMult() + GetXOrigin(); dfY = atoi(poRecord->GetField(iStart+GetXYLen(), iStart+GetXYLen()*2-1)) * GetXYMult() + GetYOrigin(); dfZ = atoi(poRecord->GetField(iStart+1+2*GetXYLen(), iStart+1+2*GetXYLen()+nZWidth-1)) * dfZMult; if( iCoord == 0 ) { dfXLast = dfX; dfYLast = dfY; poLine->setPoint( nOutCount++, dfX, dfY, dfZ ); } else if( dfXLast != dfX || dfYLast != dfY ) { dfXLast = dfX; dfYLast = dfY; poLine->setPoint( nOutCount++, dfX, dfY, dfZ ); } } poLine->setNumPoints( nOutCount ); CacheAddByGeomId( atoi(poRecord->GetField(3,8)), poLine ); } if( poGeometry != NULL ) poGeometry->assignSpatialReference( poDS->GetSpatialRef() ); return poGeometry;}/************************************************************************//* ProcessAttDesc() *//************************************************************************/int NTFFileReader::ProcessAttDesc( NTFRecord * poRecord, NTFAttDesc* psAD ){ int iChar; const char *pszData; if( poRecord->GetType() != NRT_ADR ) return FALSE; psAD->poCodeList = NULL; strcpy( psAD->val_type, poRecord->GetField( 3, 4 )); strcpy( psAD->fwidth, poRecord->GetField( 5, 7 )); strcpy( psAD->finter, poRecord->GetField( 8, 12 )); pszData = poRecord->GetData(); for( iChar = 12; pszData[iChar] != '\0' && pszData[iChar] != '\\'; iChar++ ) {} strcpy( psAD->att_name, poRecord->GetField( 13, iChar )); return TRUE;}/************************************************************************//* ProcessAttRecGroup() *//* *//* Extract attribute values from all attribute records in a *//* record set. *//************************************************************************/int NTFFileReader::ProcessAttRecGroup( NTFRecord **papoRecords, char ***ppapszTypes, char ***ppapszValues ){ *ppapszTypes = NULL; *ppapszValues = NULL; for( int iRec = 0; papoRecords[iRec] != NULL; iRec++ ) { char **papszTypes1 = NULL, **papszValues1 = NULL; if( papoRecords[iRec]->GetType() != NRT_ATTREC ) continue; if( !ProcessAttRec( papoRecords[iRec], NULL, &papszTypes1, &papszValues1 ) ) return FALSE; if( *ppapszTypes == NULL ) { *ppapszTypes = papszTypes1; *ppapszValues = papszValues1; } else { for( int i=0; papszTypes1[i] != NULL; i++ ) { *ppapszTypes = CSLAddString( *ppapszTypes, papszTypes1[i] ); *ppapszValues = CSLAddString( *ppapszValues, papszValues1[i] ); } CSLDestroy( papszTypes1 ); CSLDestroy( papszValues1 ); } } return TRUE;}/************************************************************************//* ProcessAttRec() *//************************************************************************/int NTFFileReader::ProcessAttRec( NTFRecord * poRecord, int *pnAttId, char *** ppapszTypes, char *** ppapszValues ){ int iOffset; const char *pszData; if( poRecord->GetType() != NRT_ATTREC ) return FALSE;/* -------------------------------------------------------------------- *//* Extract the attribute id. *//* -------------------------------------------------------------------- */ if( pnAttId != NULL ) *pnAttId = atoi(poRecord->GetField(3,8));/* ==================================================================== *//* Loop handling attribute till we get a '0' indicating the end *//* of the record. *//* ==================================================================== */ *ppapszTypes = NULL; *ppapszValues = NULL; iOffset = 8; pszData = poRecord->GetData(); while( pszData[iOffset] != '0' && pszData[iOffset] != '\0' ) { NTFAttDesc *psAttDesc; int nEnd; int nFWidth;/* -------------------------------------------------------------------- *//* Extract the two letter code name for the attribute, and use *//* it to find the correct ATTDESC info. *//* -------------------------------------------------------------------- */ psAttDesc = GetAttDesc(pszData + iOffset ); if( psAttDesc == NULL ) { CPLDebug( "NTF", "Couldn't translate attrec type `%2.2s'.", pszData + iOffset ); return FALSE; } *ppapszTypes = CSLAddString( *ppapszTypes, poRecord->GetField(iOffset+1,iOffset+2) );/* -------------------------------------------------------------------- *//* Establish the width of the value. Zero width fields are *//* terminated by a backslash. *//* -------------------------------------------------------------------- */ nFWidth = atoi(psAttDesc->fwidth); if( nFWidth == 0 ) { const char * pszData = poRecord->GetData(); for( nEnd = iOffset + 2; pszData[nEnd] != '\\' && pszData[nEnd] != '\0'; nEnd++ ) {} } else { nEnd = iOffset + 3 + nFWidth - 1; }/* -------------------------------------------------------------------- *//* Extract the value. If it is formatted as fixed point real *//* we reprocess it to insert the decimal point. *//* -------------------------------------------------------------------- */ const char * pszRawValue = poRecord->GetField(iOffset+3,nEnd); *ppapszValues = CSLAddString( *ppapszValues, pszRawValue );/* -------------------------------------------------------------------- *//* Establish new offset position. *//* -------------------------------------------------------------------- */ if( nFWidth == 0 ) { iOffset = nEnd; if( pszData[iOffset] == '\\' ) iOffset++; } else iOffset += 2 + atoi(psAttDesc->fwidth); } return TRUE;}/************************************************************************//* GetAttDesc() *//************************************************************************/NTFAttDesc * NTFFileReader::GetAttDesc( const char * pszType ){ for( int i = 0; i < nAttCount; i++ ) { if( EQUALN(pszType, pasAttDesc[i].val_type, 2) ) return pasAttDesc + i; } return NULL;}/************************************************************************//* ProcessAttValue() *//* *//* Take an attribute type/value pair and transform into a *//* meaningful attribute name, and value. The source can be an *//* ATTREC or the VAL_TYPE/VALUE pair of a POINTREC or LINEREC. *//* The name is transformed from the two character short form to *//* the long user name. The value will be transformed from *//* fixed point (with the decimal implicit) to fixed point with *//* an explicit decimal point if it has a "R" format. *//************************************************************************/int NTFFileReader::ProcessAttValue( const char *pszValType, const char *pszRawValue, char **ppszAttName, char **ppszAttValue, char **ppszCodeDesc ){/* -------------------------------------------------------------------- *//* Find the ATTDESC for this attribute, and assign return name value.*//* -------------------------------------------------------------------- */ NTFAttDesc *psAttDesc = GetAttDesc(pszValType); if( psAttDesc == NULL ) return FALSE; if( ppszAttName != NULL ) *ppszAttName = psAttDesc->att_name;/* -------------------------------------------------------------------- *//* Extract the value. If it is formatted as fixed point real *//* we reprocess it to insert the decimal point. *//* -------------------------------------------------------------------- */ if( psAttDesc->finter[0] == 'R' ) { static char szRealString[30]; const char *pszDecimalPortion; int nWidth, nPrecision; for( pszDecimalPortion = psAttDesc->finter; *pszDecimalPortion != ',' && *pszDecimalPortion != '\0'; pszDecimalPortion++ ) {} nWidth = strlen(pszRawValue); nPrecision = atoi(pszDecimalPortion+1); strncpy( szRealString, pszRawValue, nWidth - nPrecision ); szRealString[nWidth-nPrecision] = '.'; strcpy( szRealString+nWidth-nPrecision+1, pszRawValue+nWidth-nPrecision ); *ppszAttValue = szRealString; }/* -------------------------------------------------------------------- *//* If it is an integer, we just reformat to get rid of leading *//* zeros. *//* -------------------------------------------------------------------- */ else if( psAttDesc->finter[0] == 'I' ) { static char szIntString[30]; sprintf( szIntString, "%d", atoi(pszRawValue) ); *ppszAttValue = szIntString; }/* -------------------------------------------------------------------- *//* Otherwise we take the value directly. *//* -------------------------------------------------------------------- */ else { *ppszAttValue = (char *) pszRawValue; }/* -------------------------------------------------------------------- *//* Handle processing code values into code descriptions, if *//* applicable. *//* -------------------------------------------------------------------- */ if( ppszCodeDesc == NULL ) { } else if( psAttDesc->poCodeList != NULL ) { *ppszCodeDesc = (char *)psAttDesc->poCodeList->Lookup( *ppszAttValue ); } else { *ppszCodeDesc = NULL; } return TRUE;}/************************************************************************//* ApplyAttributeValues() *//* *//* Apply a series of attribute values to a feature from generic *//* attribute records. *//************************************************************************/void NTFFileReader::ApplyAttributeValues( OGRFeature * poFeature, NTFRecord ** papoGroup, ... ){ char **papszTypes = NULL, **papszValues = NULL;/* -------------------------------------------------------------------- *//* Extract attribute values from record group. *//* -------------------------------------------------------------------- */ if( !ProcessAttRecGroup( papoGroup, &papszTypes, &papszValues ) ) return; /* -------------------------------------------------------------------- *//* Handle attribute pairs *//* -------------------------------------------------------------------- */ va_list hVaArgs; const char *pszAttName; va_start(hVaArgs, papoGroup); while( (pszAttName = va_arg(hVaArgs, const char *)) != NULL ) { int iField = va_arg(hVaArgs, int); ApplyAttributeValue( poFeature, iField, pszAttName,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -