SDTSPointReader *SDTSTransfer::GetLayerPointReader( int iEntry ) { SDTSPointReader *poPointReader; if( iEntry < 0 || iEntry >= nLayers || oCATD.GetEntryType( panLayerCATDEntry[iEntry] ) != SLTPoint ) { return NULL; } poPointReader = new SDTSPointReader( &oIREF ); if( !poPointReader->Open( oCATD.GetEntryFilePath( panLayerCATDEntry[iEntry] ) ) ) { delete poPointReader; return NULL; } else { return poPointReader; } }
SDTSPointReader *SDTSTransfer::GetLayerPointReader( int iEntry ) { if( iEntry < 0 || iEntry >= nLayers || oCATD.GetEntryType( panLayerCATDEntry[iEntry] ) != SLTPoint ) { return nullptr; } SDTSPointReader *poPointReader = new SDTSPointReader( &oIREF ); if( !poPointReader->Open( oCATD.GetEntryFilePath( panLayerCATDEntry[iEntry] ) ) ) { panLayerCATDEntry[iEntry] = SLTUnknown; // to prevent further attempt delete poPointReader; return nullptr; } return poPointReader; }
static void WritePointShapefile( const char * pszShapefile, SDTSTransfer * poTransfer, const char * pszMODN ) { SDTSPointReader *poPointReader; /* -------------------------------------------------------------------- */ /* Fetch a reference to the indexed Pointgon reader. */ /* -------------------------------------------------------------------- */ poPointReader = (SDTSPointReader *) poTransfer->GetLayerIndexedReader( poTransfer->FindLayer( pszMODN ) ); if( poPointReader == NULL ) { fprintf( stderr, "Failed to open %s.\n", poTransfer->GetCATD()->GetModuleFilePath( pszMODN ) ); return; } poPointReader->Rewind(); /* -------------------------------------------------------------------- */ /* Create the Shapefile. */ /* -------------------------------------------------------------------- */ SHPHandle hSHP; hSHP = SHPCreate( pszShapefile, SHPT_POINT ); if( hSHP == NULL ) { fprintf( stderr, "Unable to create shapefile `%s'\n", pszShapefile ); return; } /* -------------------------------------------------------------------- */ /* Create the database file, and our basic set of attributes. */ /* -------------------------------------------------------------------- */ DBFHandle hDBF; int nAreaField, nSDTSRecordField; char szDBFFilename[1024]; sprintf( szDBFFilename, "%s.dbf", pszShapefile ); hDBF = DBFCreate( szDBFFilename ); if( hDBF == NULL ) { fprintf( stderr, "Unable to create shapefile .dbf for `%s'\n", pszShapefile ); return; } nSDTSRecordField = DBFAddField( hDBF, "SDTSRecId", FTInteger, 8, 0 ); nAreaField = DBFAddField( hDBF, "AreaId", FTString, 12, 0 ); char **papszModRefs = poPointReader->ScanModuleReferences(); AddPrimaryAttrToDBFSchema( hDBF, poTransfer, papszModRefs ); CSLDestroy( papszModRefs ); /* ==================================================================== */ /* Process all the line features in the module. */ /* ==================================================================== */ SDTSRawPoint *poRawPoint; while( (poRawPoint = poPointReader->GetNextPoint()) != NULL ) { int iShape; /* -------------------------------------------------------------------- */ /* Write out a shape with the vertices. */ /* -------------------------------------------------------------------- */ SHPObject *psShape; psShape = SHPCreateSimpleObject( SHPT_POINT, 1, &(poRawPoint->dfX), &(poRawPoint->dfY), &(poRawPoint->dfZ) ); iShape = SHPWriteObject( hSHP, -1, psShape ); SHPDestroyObject( psShape ); /* -------------------------------------------------------------------- */ /* Write out the attributes. */ /* -------------------------------------------------------------------- */ char szID[13]; DBFWriteIntegerAttribute( hDBF, iShape, nSDTSRecordField, poRawPoint->oModId.nRecord ); sprintf( szID, "%s:%ld", poRawPoint->oAreaId.szModule, poRawPoint->oAreaId.nRecord ); DBFWriteStringAttribute( hDBF, iShape, nAreaField, szID ); WritePrimaryAttrToDBF( hDBF, iShape, poTransfer, poRawPoint ); if( !poPointReader->IsIndexed() ) delete poRawPoint; } /* -------------------------------------------------------------------- */ /* Close, and cleanup. */ /* -------------------------------------------------------------------- */ DBFClose( hDBF ); SHPClose( hSHP ); }
int SDTSTransfer::GetBounds( double *pdfMinX, double *pdfMinY, double *pdfMaxX, double *pdfMaxY ) { bool bFirst = true; for( int iLayer = 0; iLayer < GetLayerCount(); iLayer++ ) { if( GetLayerType( iLayer ) == SLTPoint ) { SDTSPointReader *poLayer = reinterpret_cast<SDTSPointReader *>( GetLayerIndexedReader( iLayer ) ); if( poLayer == nullptr ) continue; poLayer->Rewind(); SDTSRawPoint *poPoint = nullptr; while( (poPoint = reinterpret_cast<SDTSRawPoint *>( poLayer->GetNextFeature() ) ) != nullptr ) { if( bFirst ) { *pdfMinX = poPoint->dfX; *pdfMaxX = poPoint->dfX; *pdfMinY = poPoint->dfY; *pdfMaxY = poPoint->dfY; bFirst = false; } else { *pdfMinX = std::min( *pdfMinX, poPoint->dfX ); *pdfMaxX = std::max( *pdfMaxX, poPoint->dfX ); *pdfMinY = std::min( *pdfMinY, poPoint->dfY ); *pdfMaxY = std::max( *pdfMaxY, poPoint->dfY ); } if( !poLayer->IsIndexed() ) delete poPoint; } } else if( GetLayerType( iLayer ) == SLTRaster ) { SDTSRasterReader *poRL = GetLayerRasterReader( iLayer ); if( poRL == nullptr ) continue; double adfGeoTransform[6]; poRL->GetTransform( adfGeoTransform ); const double dfMinX = adfGeoTransform[0]; const double dfMaxY = adfGeoTransform[3]; const double dfMaxX = adfGeoTransform[0] + poRL->GetXSize() * adfGeoTransform[1]; const double dfMinY = adfGeoTransform[3] + poRL->GetYSize() * adfGeoTransform[5]; if( bFirst ) { *pdfMinX = dfMinX; *pdfMaxX = dfMaxX; *pdfMinY = dfMinY; *pdfMaxY = dfMaxY; bFirst = false; } else { *pdfMinX = std::min( dfMinX, *pdfMinX ); *pdfMaxX = std::max( dfMaxX, *pdfMaxX ); *pdfMinY = std::min( dfMinY, *pdfMinY ); *pdfMaxY = std::max( dfMaxY, *pdfMaxY ); } delete poRL; } } return !bFirst; }
int SDTSTransfer::GetBounds( double *pdfMinX, double *pdfMinY, double *pdfMaxX, double *pdfMaxY ) { int bFirst = TRUE; for( int iLayer = 0; iLayer < GetLayerCount(); iLayer++ ) { if( GetLayerType( iLayer ) == SLTPoint ) { SDTSPointReader *poLayer; SDTSRawPoint *poPoint; poLayer = (SDTSPointReader *) GetLayerIndexedReader( iLayer ); if( poLayer == NULL ) continue; poLayer->Rewind(); while( (poPoint = (SDTSRawPoint*) poLayer->GetNextFeature()) ) { if( bFirst ) { *pdfMinX = *pdfMaxX = poPoint->dfX; *pdfMinY = *pdfMaxY = poPoint->dfY; bFirst = FALSE; } else { *pdfMinX = MIN(*pdfMinX,poPoint->dfX); *pdfMaxX = MAX(*pdfMaxX,poPoint->dfX); *pdfMinY = MIN(*pdfMinY,poPoint->dfY); *pdfMaxY = MAX(*pdfMaxY,poPoint->dfY); } if( !poLayer->IsIndexed() ) delete poPoint; } } else if( GetLayerType( iLayer ) == SLTRaster ) { SDTSRasterReader *poRL; double adfGeoTransform[6]; double dfMinX, dfMaxX, dfMinY, dfMaxY; poRL = GetLayerRasterReader( iLayer ); if( poRL == NULL ) continue; poRL->GetTransform( adfGeoTransform ); dfMinX = adfGeoTransform[0]; dfMaxY = adfGeoTransform[3]; dfMaxX = adfGeoTransform[0] + poRL->GetXSize()*adfGeoTransform[1]; dfMinY = adfGeoTransform[3] + poRL->GetYSize()*adfGeoTransform[5]; if( bFirst ) { *pdfMinX = dfMinX; *pdfMaxX = dfMaxX; *pdfMinY = dfMinY; *pdfMaxY = dfMaxY; bFirst = FALSE; } else { *pdfMinX = MIN(dfMinX,*pdfMinX); *pdfMaxX = MAX(dfMaxX,*pdfMaxX); *pdfMinY = MIN(dfMinY,*pdfMinY); *pdfMaxY = MAX(dfMaxY,*pdfMaxY); } delete poRL; } } return !bFirst; }