📄 tigerpolygon.cpp
字号:
if( bUsingRTS ) { AddFieldDefns(psRTSInfo, poFeatureDefn); }}/************************************************************************//* ~TigerPolygon() *//************************************************************************/TigerPolygon::~TigerPolygon(){ if( fpRTS != NULL ) VSIFClose( fpRTS );}/************************************************************************//* SetModule() *//************************************************************************/int TigerPolygon::SetModule( const char * pszModule ){ if( !OpenFile( pszModule, "A" ) ) return FALSE; EstablishFeatureCount(); /* -------------------------------------------------------------------- *//* Open the RTS file *//* -------------------------------------------------------------------- */ if( bUsingRTS ) { if( fpRTS != NULL ) { VSIFClose( fpRTS ); fpRTS = NULL; } if( pszModule ) { char *pszFilename; pszFilename = poDS->BuildFilename( pszModule, "S" ); fpRTS = VSIFOpen( pszFilename, "rb" ); CPLFree( pszFilename ); nRTSRecLen = EstablishRecordLength( fpRTS ); } } return TRUE;}/************************************************************************//* GetFeature() *//************************************************************************/OGRFeature *TigerPolygon::GetFeature( int nRecordId ){ char achRecord[OGR_TIGER_RECBUF_LEN]; if( nRecordId < 0 || nRecordId >= nFeatures ) { CPLError( CE_Failure, CPLE_FileIO, "Request for out-of-range feature %d of %sA", nRecordId, pszModule ); return NULL; }/* -------------------------------------------------------------------- *//* Read the raw record data from the file. *//* -------------------------------------------------------------------- */ if( fpPrimary == NULL ) return NULL; if( VSIFSeek( fpPrimary, nRecordId * nRecordLength, SEEK_SET ) != 0 ) { CPLError( CE_Failure, CPLE_FileIO, "Failed to seek to %d of %sA", nRecordId * nRecordLength, pszModule ); return NULL; } if( VSIFRead( achRecord, nRecordLength, 1, fpPrimary ) != 1 ) { CPLError( CE_Failure, CPLE_FileIO, "Failed to read record %d of %sA", nRecordId, pszModule ); return NULL; } /* -------------------------------------------------------------------- */ /* Set fields. */ /* -------------------------------------------------------------------- */ OGRFeature *poFeature = new OGRFeature( poFeatureDefn ); SetFields( psRTAInfo, poFeature, achRecord ); /* -------------------------------------------------------------------- */ /* Read RTS record, and apply fields. */ /* -------------------------------------------------------------------- */ if( fpRTS != NULL ) { char achRTSRec[OGR_TIGER_RECBUF_LEN]; if( VSIFSeek( fpRTS, nRecordId * nRTSRecLen, SEEK_SET ) != 0 ) { CPLError( CE_Failure, CPLE_FileIO, "Failed to seek to %d of %sS", nRecordId * nRTSRecLen, pszModule ); return NULL; } if( VSIFRead( achRTSRec, psRTSInfo->nRecordLength, 1, fpRTS ) != 1 ) { CPLError( CE_Failure, CPLE_FileIO, "Failed to read record %d of %sS", nRecordId, pszModule ); return NULL; } SetFields( psRTSInfo, poFeature, achRTSRec ); } return poFeature;}/************************************************************************//* SetWriteModule() *//************************************************************************/int TigerPolygon::SetWriteModule( const char *pszFileCode, int nRecLen, OGRFeature *poFeature ){ int bSuccess; bSuccess = TigerFileBase::SetWriteModule( pszFileCode, nRecLen, poFeature); if( !bSuccess ) return bSuccess;/* -------------------------------------------------------------------- *//* Open the RT3 file *//* -------------------------------------------------------------------- */ if( bUsingRTS ) { if( fpRTS != NULL ) { VSIFClose( fpRTS ); fpRTS = NULL; } if( pszModule ) { char *pszFilename; pszFilename = poDS->BuildFilename( pszModule, "S" ); fpRTS = VSIFOpen( pszFilename, "ab" ); CPLFree( pszFilename ); } } return TRUE;}/************************************************************************//* CreateFeature() *//************************************************************************/OGRErr TigerPolygon::CreateFeature( OGRFeature *poFeature ){ char szRecord[OGR_TIGER_RECBUF_LEN];/* -------------------------------------------------------------------- *//* Write basic data record ("RTA") *//* -------------------------------------------------------------------- */ if( !SetWriteModule( "A", psRTAInfo->nRecordLength+2, poFeature ) ) return OGRERR_FAILURE; memset( szRecord, ' ', psRTAInfo->nRecordLength ); WriteFields( psRTAInfo, poFeature, szRecord ); WriteRecord( szRecord, psRTAInfo->nRecordLength, "A" );/* -------------------------------------------------------------------- *//* Prepare S record. *//* -------------------------------------------------------------------- */ memset( szRecord, ' ', psRTSInfo->nRecordLength ); WriteFields( psRTSInfo, poFeature, szRecord ); WriteRecord( szRecord, psRTSInfo->nRecordLength, "S", fpRTS ); return OGRERR_NONE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -