static void NTFCount( const char * pszFile ) { FILE *fp; NTFRecord *poRecord = NULL; int anCount[100], i; for( i = 0; i < 100; i++ ) anCount[i] = 0; fp = VSIFOpen( pszFile, "r" ); if( fp == NULL ) return; do { if( poRecord != NULL ) delete poRecord; poRecord = new NTFRecord( fp ); anCount[poRecord->GetType()]++; } while( poRecord->GetType() != 99 ); VSIFClose( fp ); printf( "\nReporting on: %s\n", pszFile ); for( i = 0; i < 100; i++ ) { if( anCount[i] > 0 ) printf( "Found %d records of type %d\n", anCount[i], i ); } }
void NTFFileReader::EstablishRasterAccess() { /* -------------------------------------------------------------------- */ /* Read the type 50 record. */ /* -------------------------------------------------------------------- */ NTFRecord *poRecord; while( (poRecord = ReadRecord()) != NULL && poRecord->GetType() != NRT_GRIDHREC && poRecord->GetType() != NRT_VTR ) { delete poRecord; } if( poRecord->GetType() != NRT_GRIDHREC ) { delete poRecord; CPLError( CE_Failure, CPLE_AppDefined, "Unable to find GRIDHREC (type 50) record in what appears\n" "to be an NTF Raster DTM product." ); return; } /* -------------------------------------------------------------------- */ /* Parse if LANDRANGER_DTM */ /* -------------------------------------------------------------------- */ if( GetProductId() == NPC_LANDRANGER_DTM ) { nRasterXSize = atoi(poRecord->GetField(13,16)); nRasterYSize = atoi(poRecord->GetField(17,20)); // NOTE: unusual use of GeoTransform - the pixel origin is the // bottom left corner! adfGeoTransform[0] = atoi(poRecord->GetField(25,34)); adfGeoTransform[1] = 50; adfGeoTransform[2] = 0; adfGeoTransform[3] = atoi(poRecord->GetField(35,44)); adfGeoTransform[4] = 0; adfGeoTransform[5] = 50; nRasterDataType = 3; /* GDT_Int16 */ } /* -------------------------------------------------------------------- */ /* Parse if LANDFORM_PROFILE_DTM */ /* -------------------------------------------------------------------- */ else if( GetProductId() == NPC_LANDFORM_PROFILE_DTM ) { nRasterXSize = atoi(poRecord->GetField(23,30)); nRasterYSize = atoi(poRecord->GetField(31,38)); // NOTE: unusual use of GeoTransform - the pixel origin is the // bottom left corner! adfGeoTransform[0] = atoi(poRecord->GetField(13,17)) + GetXOrigin(); adfGeoTransform[1] = atoi(poRecord->GetField(39,42)); adfGeoTransform[2] = 0; adfGeoTransform[3] = atoi(poRecord->GetField(18,22)) + GetYOrigin(); adfGeoTransform[4] = 0; adfGeoTransform[5] = atoi(poRecord->GetField(43,46)); nRasterDataType = 3; /* GDT_Int16 */ } /* -------------------------------------------------------------------- */ /* Initialize column offsets table. */ /* -------------------------------------------------------------------- */ delete poRecord; panColumnOffset = (long *) CPLCalloc(sizeof(long),nRasterXSize); GetFPPos( panColumnOffset+0, NULL ); /* -------------------------------------------------------------------- */ /* Create an OGRSFLayer for this file readers raster points. */ /* -------------------------------------------------------------------- */ if( poDS != NULL ) { poRasterLayer = new OGRNTFRasterLayer( poDS, this ); poDS->AddLayer( poRasterLayer ); } }
CPLErr NTFFileReader::ReadRasterColumn( int iColumn, float *pafElev ) { /* -------------------------------------------------------------------- */ /* If we don't already have the scanline offset of the previous */ /* line, force reading of previous records to establish it. */ /* -------------------------------------------------------------------- */ if( panColumnOffset[iColumn] == 0 ) { int iPrev; for( iPrev = 0; iPrev < iColumn-1; iPrev++ ) { if( panColumnOffset[iPrev+1] == 0 ) { CPLErr eErr; eErr = ReadRasterColumn( iPrev, NULL ); if( eErr != CE_None ) return eErr; } } } /* -------------------------------------------------------------------- */ /* If the dataset isn't open, open it now. */ /* -------------------------------------------------------------------- */ if( GetFP() == NULL ) Open(); /* -------------------------------------------------------------------- */ /* Read requested record. */ /* -------------------------------------------------------------------- */ NTFRecord *poRecord; SetFPPos( panColumnOffset[iColumn], iColumn ); poRecord = ReadRecord(); if( iColumn < nRasterXSize-1 ) { GetFPPos( panColumnOffset+iColumn+1, NULL ); } /* -------------------------------------------------------------------- */ /* Handle LANDRANGER DTM columns. */ /* -------------------------------------------------------------------- */ if( pafElev != NULL && GetProductId() == NPC_LANDRANGER_DTM ) { double dfVScale, dfVOffset; dfVOffset = atoi(poRecord->GetField(56,65)); dfVScale = atoi(poRecord->GetField(66,75)) * 0.001; for( int iPixel = 0; iPixel < nRasterXSize; iPixel++ ) { pafElev[iPixel] = (float) (dfVOffset + dfVScale * atoi(poRecord->GetField(84+iPixel*4,87+iPixel*4))); } } /* -------------------------------------------------------------------- */ /* Handle PROFILE */ /* -------------------------------------------------------------------- */ else if( pafElev != NULL && GetProductId() == NPC_LANDFORM_PROFILE_DTM ) { for( int iPixel = 0; iPixel < nRasterXSize; iPixel++ ) { pafElev[iPixel] = (float) (atoi(poRecord->GetField(19+iPixel*5,23+iPixel*5)) * GetZMult()); } } delete poRecord; return CE_None; }