📄 ntffilereader.cpp
字号:
else if( nGType == 5 && nNumCoord == 3 ) { double adfX[3], adfY[3]; int iCoord; for( iCoord = 0; iCoord < nNumCoord; iCoord++ ) { int iStart = 14 + iCoord * (GetXYLen()*2+1); adfX[iCoord] = atoi(poRecord->GetField(iStart+0, iStart+GetXYLen()-1)) * GetXYMult() + GetXOrigin(); adfY[iCoord] = atoi(poRecord->GetField(iStart+GetXYLen(), iStart+GetXYLen()*2-1)) * GetXYMult() + GetYOrigin(); } poGeometry = NTFStrokeArcToOGRGeometry_Points( adfX[0], adfY[0], adfX[1], adfY[1], adfX[2], adfY[2], 72 ); }/* -------------------------------------------------------------------- *//* Circle *//* -------------------------------------------------------------------- */ else if( nGType == 7 ) { double dfCenterX, dfCenterY, dfArcX, dfArcY, dfRadius; int iCenterStart = 14; int iArcStart = 14 + 2 * GetXYLen() + 1; dfCenterX = atoi(poRecord->GetField(iCenterStart, iCenterStart+GetXYLen()-1)) * GetXYMult() + GetXOrigin(); dfCenterY = atoi(poRecord->GetField(iCenterStart+GetXYLen(), iCenterStart+GetXYLen()*2-1)) * GetXYMult() + GetYOrigin(); dfArcX = atoi(poRecord->GetField(iArcStart, iArcStart+GetXYLen()-1)) * GetXYMult() + GetXOrigin(); dfArcY = atoi(poRecord->GetField(iArcStart+GetXYLen(), iArcStart+GetXYLen()*2-1)) * GetXYMult() + GetYOrigin(); dfRadius = sqrt( (dfCenterX - dfArcX) * (dfCenterX - dfArcX) + (dfCenterY - dfArcY) * (dfCenterY - dfArcY) ); poGeometry = NTFStrokeArcToOGRGeometry_Angles( dfCenterX, dfCenterY, dfRadius, 0.0, 360.0, 72 ); } else { fprintf( stderr, "GType = %d\n", nGType ); CPLAssert( FALSE ); } if( poGeometry != NULL ) poGeometry->assignSpatialReference( poDS->GetSpatialRef() ); return poGeometry;}/************************************************************************//* ProcessGeometry3D() *//************************************************************************/OGRGeometry *NTFFileReader::ProcessGeometry3D( NTFRecord * poRecord, int * pnGeomId ){ int nGType, nNumCoord; OGRGeometry *poGeometry = NULL; if( poRecord->GetType() != NRT_GEOMETRY3D ) return NULL; nGType = atoi(poRecord->GetField(9,9)); // GTYPE nNumCoord = atoi(poRecord->GetField(10,13)); // NUM_COORD if( pnGeomId != NULL ) *pnGeomId = atoi(poRecord->GetField(3,8)); // GEOM_ID if( nGType == 1 ) { double dfX, dfY, dfZ; dfX = atoi(poRecord->GetField(14,14+GetXYLen()-1)) * GetXYMult() + GetXOrigin(); dfY = atoi(poRecord->GetField(14+GetXYLen(),14+GetXYLen()*2-1)) * GetXYMult() + GetYOrigin(); dfZ = atoi(poRecord->GetField(14+1+2*GetXYLen(), 14+1+2*GetXYLen()+nZWidth-1)) * dfZMult; 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' )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -