80
98
virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
81
99
const char *pszGCPProjection );
101
virtual const char *GetMetadataItem( const char * pszName,
102
const char * pszDomain = "" );
103
virtual char **GetMetadata( const char * pszDomain = "" );
83
105
static GDALDataset *Open( GDALOpenInfo * );
106
static int Identify( GDALOpenInfo * );
84
107
static GDALDataset *Create( const char * pszFilename,
85
108
int nXSize, int nYSize, int nBands,
86
109
GDALDataType eType, char ** papszParmList );
89
112
/************************************************************************/
90
/* ==================================================================== */
92
/* ==================================================================== */
93
/************************************************************************/
95
/************************************************************************/
96
113
/* ERSDataset() */
97
114
/************************************************************************/
130
150
VSIFCloseL( fpImage );
153
CloseDependentDatasets();
155
CPLFree( pszProjection );
157
CPLFree( pszGCPProjection );
160
GDALDeinitGCPs( nGCPCount, pasGCPList );
161
CPLFree( pasGCPList );
164
if( poHeader != NULL )
168
/************************************************************************/
169
/* CloseDependentDatasets() */
170
/************************************************************************/
172
int ERSDataset::CloseDependentDatasets()
174
int bHasDroppedRef = RawDataset::CloseDependentDatasets();
133
176
if( poDepFile != NULL )
180
bHasDroppedRef = TRUE;
137
182
for( iBand = 0; iBand < nBands; iBand++ )
138
183
papoBands[iBand] = NULL;
140
186
GDALClose( (GDALDatasetH) poDepFile );
143
CPLFree( pszProjection );
145
CPLFree( pszGCPProjection );
148
GDALDeinitGCPs( nGCPCount, pasGCPList );
149
CPLFree( pasGCPList );
152
if( poHeader != NULL )
190
return bHasDroppedRef;
156
193
/************************************************************************/
184
221
/************************************************************************/
222
/* GetMetadataItem() */
223
/************************************************************************/
225
const char *ERSDataset::GetMetadataItem( const char * pszName,
226
const char * pszDomain )
228
if (pszDomain != NULL && EQUAL(pszDomain, "ERS") && pszName != NULL)
230
if (EQUAL(pszName, "PROJ"))
231
return osProj.size() ? osProj.c_str() : NULL;
232
if (EQUAL(pszName, "DATUM"))
233
return osDatum.size() ? osDatum.c_str() : NULL;
234
if (EQUAL(pszName, "UNITS"))
235
return osUnits.size() ? osUnits.c_str() : NULL;
237
return GDALPamDataset::GetMetadataItem(pszName, pszDomain);
240
/************************************************************************/
242
/************************************************************************/
244
char **ERSDataset::GetMetadata( const char *pszDomain )
247
if( pszDomain != NULL && EQUAL(pszDomain, "ERS") )
249
oERSMetadataList.Clear();
251
oERSMetadataList.AddString(CPLSPrintf("%s=%s", "PROJ", osProj.c_str()));
253
oERSMetadataList.AddString(CPLSPrintf("%s=%s", "DATUM", osDatum.c_str()));
255
oERSMetadataList.AddString(CPLSPrintf("%s=%s", "UNITS", osUnits.c_str()));
256
return oERSMetadataList.List();
259
return GDALPamDataset::GetMetadata( pszDomain );
262
/************************************************************************/
185
263
/* GetGCPCount() */
186
264
/************************************************************************/
260
338
char szERSProj[32], szERSDatum[32], szERSUnits[32];
262
340
oSRS.exportToERM( szERSProj, szERSDatum, szERSUnits );
342
/* Write the above computed values, unless they have been overriden by */
343
/* the creation options PROJ, DATUM or UNITS */
264
345
poHeader->Set( "RasterInfo.WarpControl.CoordinateSpace.Datum",
265
CPLString().Printf( "\"%s\"", szERSDatum ) );
346
CPLString().Printf( "\"%s\"",
347
(osDatum.size()) ? osDatum.c_str() : szERSDatum ) );
266
348
poHeader->Set( "RasterInfo.WarpControl.CoordinateSpace.Projection",
267
CPLString().Printf( "\"%s\"", szERSProj ) );
349
CPLString().Printf( "\"%s\"",
350
(osProj.size()) ? osProj.c_str() : szERSProj ) );
268
351
poHeader->Set( "RasterInfo.WarpControl.CoordinateSpace.CoordinateType",
269
352
CPLString().Printf( "EN" ) );
270
353
poHeader->Set( "RasterInfo.WarpControl.CoordinateSpace.Units",
271
CPLString().Printf( "\"%s\"", szERSUnits ) );
354
CPLString().Printf( "\"%s\"",
355
(osUnits.size()) ? osUnits.c_str() : szERSUnits ) );
272
356
poHeader->Set( "RasterInfo.WarpControl.CoordinateSpace.Rotation",
337
421
char szERSProj[32], szERSDatum[32], szERSUnits[32];
339
423
oSRS.exportToERM( szERSProj, szERSDatum, szERSUnits );
425
/* Write the above computed values, unless they have been overriden by */
426
/* the creation options PROJ, DATUM or UNITS */
427
WriteProjectionInfo( (osProj.size()) ? osProj.c_str() : szERSProj,
428
(osDatum.size()) ? osDatum.c_str() : szERSDatum,
429
(osUnits.size()) ? osUnits.c_str() : szERSUnits );
434
/************************************************************************/
435
/* WriteProjectionInfo() */
436
/************************************************************************/
438
void ERSDataset::WriteProjectionInfo(const char* pszProj,
439
const char* pszDatum,
440
const char* pszUnits)
341
442
bHDRDirty = TRUE;
342
443
poHeader->Set( "CoordinateSpace.Datum",
343
CPLString().Printf( "\"%s\"", szERSDatum ) );
444
CPLString().Printf( "\"%s\"", pszDatum ) );
344
445
poHeader->Set( "CoordinateSpace.Projection",
345
CPLString().Printf( "\"%s\"", szERSProj ) );
446
CPLString().Printf( "\"%s\"", pszProj ) );
346
447
poHeader->Set( "CoordinateSpace.CoordinateType",
347
448
CPLString().Printf( "EN" ) );
348
449
poHeader->Set( "CoordinateSpace.Units",
349
CPLString().Printf( "\"%s\"", szERSUnits ) );
450
CPLString().Printf( "\"%s\"", pszUnits ) );
350
451
poHeader->Set( "CoordinateSpace.Rotation",
581
683
/* -------------------------------------------------------------------- */
582
684
OGRSpatialReference oSRS;
584
CPLString osProjection = poHeader->Find(
585
"RasterInfo.WarpControl.CoordinateSpace.Projection", "RAW" );
586
CPLString osDatum = poHeader->Find(
587
"RasterInfo.WarpControl.CoordinateSpace.Datum", "WGS84" );
588
CPLString osUnits = poHeader->Find(
589
"RasterInfo.WarpControl.CoordinateSpace.Units", "METERS" );
686
osProj = poHeader->Find( "RasterInfo.WarpControl.CoordinateSpace.Projection", "" );
687
osDatum = poHeader->Find( "RasterInfo.WarpControl.CoordinateSpace.Datum", "" );
688
osUnits = poHeader->Find( "RasterInfo.WarpControl.CoordinateSpace.Units", "" );
591
oSRS.importFromERM( osProjection, osDatum, osUnits );
690
oSRS.importFromERM( osProj.size() ? osProj : "RAW",
691
osDatum.size() ? osDatum : "WGS84",
692
osUnits.size() ? osUnits : "METERS" );
593
694
CPLFree( pszGCPProjection );
594
695
oSRS.exportToWkt( &pszGCPProjection );
597
698
/************************************************************************/
599
/************************************************************************/
601
GDALDataset *ERSDataset::Open( GDALOpenInfo * poOpenInfo )
699
/* ==================================================================== */
701
/* ==================================================================== */
702
/************************************************************************/
704
class ERSRasterBand : public RawRasterBand
708
ERSRasterBand( GDALDataset *poDS, int nBand, void * fpRaw,
709
vsi_l_offset nImgOffset, int nPixelOffset,
711
GDALDataType eDataType, int bNativeOrder,
712
int bIsVSIL = FALSE, int bOwnsFP = FALSE );
714
virtual double GetNoDataValue( int *pbSuccess = NULL );
715
virtual CPLErr SetNoDataValue( double );
718
/************************************************************************/
719
/* ERSRasterBand() */
720
/************************************************************************/
722
ERSRasterBand::ERSRasterBand( GDALDataset *poDS, int nBand, void * fpRaw,
723
vsi_l_offset nImgOffset, int nPixelOffset,
725
GDALDataType eDataType, int bNativeOrder,
726
int bIsVSIL, int bOwnsFP ) :
727
RawRasterBand(poDS, nBand, fpRaw, nImgOffset, nPixelOffset,
728
nLineOffset, eDataType, bNativeOrder, bIsVSIL, bOwnsFP)
732
/************************************************************************/
733
/* GetNoDataValue() */
734
/************************************************************************/
736
double ERSRasterBand::GetNoDataValue( int *pbSuccess )
738
ERSDataset* poGDS = (ERSDataset*) poDS;
739
if (poGDS->bHasNoDataValue)
743
return poGDS->dfNoDataValue;
746
return RawRasterBand::GetNoDataValue(pbSuccess);
749
/************************************************************************/
750
/* SetNoDataValue() */
751
/************************************************************************/
753
CPLErr ERSRasterBand::SetNoDataValue( double dfNoDataValue )
755
ERSDataset* poGDS = (ERSDataset*) poDS;
756
if (!poGDS->bHasNoDataValue || poGDS->dfNoDataValue != dfNoDataValue)
758
poGDS->bHasNoDataValue = TRUE;
759
poGDS->dfNoDataValue = dfNoDataValue;
761
poGDS->bHDRDirty = TRUE;
762
poGDS->poHeader->Set( "RasterInfo.NullCellValue",
763
CPLString().Printf( "%.16g", dfNoDataValue) );
768
/************************************************************************/
770
/************************************************************************/
772
int ERSDataset::Identify( GDALOpenInfo * poOpenInfo )
604
775
/* -------------------------------------------------------------------- */
607
778
if( poOpenInfo->nHeaderBytes > 15
608
779
&& EQUALN((const char *) poOpenInfo->pabyHeader,"Algorithm Begin",15) )
610
CPLError( CE_Failure, CPLE_OpenFailed,
611
"%s appears to be an algorithm ERS file, which is not currently supported.",
781
CPLError( CE_Failure, CPLE_OpenFailed,
782
"%s appears to be an algorithm ERS file, which is not currently supported.",
612
783
poOpenInfo->pszFilename );
616
787
/* -------------------------------------------------------------------- */
617
788
/* We assume the user selects the .ers file. */
618
789
/* -------------------------------------------------------------------- */
619
if( poOpenInfo->nHeaderBytes < 15
790
if( poOpenInfo->nHeaderBytes < 15
620
791
|| !EQUALN((const char *) poOpenInfo->pabyHeader,"DatasetHeader ",14) )
797
/************************************************************************/
799
/************************************************************************/
801
GDALDataset *ERSDataset::Open( GDALOpenInfo * poOpenInfo )
804
if( !Identify( poOpenInfo ) )
623
807
/* -------------------------------------------------------------------- */
624
808
/* Open the .ers file, and read the first line. */
625
809
/* -------------------------------------------------------------------- */
626
FILE *fpERS = VSIFOpenL( poOpenInfo->pszFilename, "rb" );
810
VSILFILE *fpERS = VSIFOpenL( poOpenInfo->pszFilename, "rb" );
628
812
if( fpERS == NULL )
849
1041
/* -------------------------------------------------------------------- */
850
1042
OGRSpatialReference oSRS;
852
CPLString osProjection = poHeader->Find( "CoordinateSpace.Projection",
854
CPLString osDatum = poHeader->Find( "CoordinateSpace.Datum", "WGS84" );
855
CPLString osUnits = poHeader->Find( "CoordinateSpace.Units", "METERS" );
1044
poDS->osProj = poHeader->Find( "CoordinateSpace.Projection", "" );
1045
poDS->osDatum = poHeader->Find( "CoordinateSpace.Datum", "" );
1046
poDS->osUnits = poHeader->Find( "CoordinateSpace.Units", "" );
857
oSRS.importFromERM( osProjection, osDatum, osUnits );
1048
oSRS.importFromERM( poDS->osProj.size() ? poDS->osProj : "RAW",
1049
poDS->osDatum.size() ? poDS->osDatum : "WGS84",
1050
poDS->osUnits.size() ? poDS->osUnits : "METERS" );
859
1052
CPLFree( poDS->pszProjection );
860
1053
oSRS.exportToWkt( &(poDS->pszProjection) );
862
1055
/* -------------------------------------------------------------------- */
863
1056
/* Look for the geotransform. */
864
1057
/* -------------------------------------------------------------------- */
865
if( poHeader->Find( "RasterInfo.RegistrationCoord.Eastings", NULL )
866
&& poHeader->Find( "RasterInfo.CellInfo.Xdimension", NULL ) )
1058
if( poHeader->Find( "RasterInfo.RegistrationCoord.Eastings", NULL ) )
868
1060
poDS->bGotTransform = TRUE;
869
1061
poDS->adfGeoTransform[0] = CPLAtof(
870
1062
poHeader->Find( "RasterInfo.RegistrationCoord.Eastings", "" ));
871
1063
poDS->adfGeoTransform[1] = CPLAtof(
872
poHeader->Find( "RasterInfo.CellInfo.Xdimension", "" ));
1064
poHeader->Find( "RasterInfo.CellInfo.Xdimension", "1.0" ));
873
1065
poDS->adfGeoTransform[2] = 0.0;
874
1066
poDS->adfGeoTransform[3] = CPLAtof(
875
1067
poHeader->Find( "RasterInfo.RegistrationCoord.Northings", "" ));
876
1068
poDS->adfGeoTransform[4] = 0.0;
877
1069
poDS->adfGeoTransform[5] = -CPLAtof(
878
poHeader->Find( "RasterInfo.CellInfo.Ydimension", "" ));
1070
poHeader->Find( "RasterInfo.CellInfo.Ydimension", "1.0" ));
880
1072
else if( poHeader->Find( "RasterInfo.RegistrationCoord.Latitude", NULL )
881
1073
&& poHeader->Find( "RasterInfo.CellInfo.Xdimension", NULL ) )
914
1106
/* -------------------------------------------------------------------- */
915
1107
if( poHeader->Find( "RasterInfo.NullCellValue", NULL ) )
917
CPLPushErrorHandler( CPLQuietErrorHandler );
919
for( iBand = 1; iBand <= poDS->nBands; iBand++ )
920
poDS->GetRasterBand(iBand)->SetNoDataValue(
921
CPLAtofM(poHeader->Find( "RasterInfo.NullCellValue" )) );
923
CPLPopErrorHandler();
1109
poDS->bHasNoDataValue = TRUE;
1110
poDS->dfNoDataValue = CPLAtofM(poHeader->Find( "RasterInfo.NullCellValue" ));
1112
if (poDS->poDepFile != NULL)
1114
CPLPushErrorHandler( CPLQuietErrorHandler );
1116
for( iBand = 1; iBand <= poDS->nBands; iBand++ )
1117
poDS->GetRasterBand(iBand)->SetNoDataValue(poDS->dfNoDataValue);
1119
CPLPopErrorHandler();
926
1123
/* -------------------------------------------------------------------- */
1171
1368
/* -------------------------------------------------------------------- */
1173
1370
/* -------------------------------------------------------------------- */
1174
return (GDALDataset *) GDALOpen( osErsFile, GA_Update );
1371
GDALOpenInfo oOpenInfo( osErsFile, GA_Update );
1372
ERSDataset* poDS = (ERSDataset*) Open( &oOpenInfo );
1376
/* -------------------------------------------------------------------- */
1377
/* Fetch DATUM, PROJ and UNITS creation option */
1378
/* -------------------------------------------------------------------- */
1379
const char *pszDatum = CSLFetchNameValue( papszOptions, "DATUM" );
1381
poDS->osDatum = pszDatum;
1382
const char *pszProj = CSLFetchNameValue( papszOptions, "PROJ" );
1384
poDS->osProj = pszProj;
1385
const char *pszUnits = CSLFetchNameValue( papszOptions, "UNITS" );
1387
poDS->osUnits = pszUnits;
1389
if (pszDatum || pszProj || pszUnits)
1391
poDS->WriteProjectionInfo(pszProj ? pszProj : "RAW",
1392
pszDatum ? pszDatum : "RAW",
1393
pszUnits ? pszUnits : "METERS");
1177
1399
/************************************************************************/
1198
1420
poDriver->SetMetadataItem( GDAL_DMD_CREATIONOPTIONLIST,
1199
1421
"<CreationOptionList>"
1200
1422
" <Option name='PIXELTYPE' type='string' description='By setting this to SIGNEDBYTE, a new Byte file can be forced to be written as signed byte'/>"
1423
" <Option name='PROJ' type='string' description='ERS Projection Name'/>"
1424
" <Option name='DATUM' type='string' description='ERS Datum Name' />"
1425
" <Option name='UNITS' type='string-select' description='ERS Projection Units'>"
1426
" <Value>METERS</Value>"
1427
" <Value>FEET</Value>"
1201
1429
"</CreationOptionList>" );
1431
poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" );
1203
1433
poDriver->pfnOpen = ERSDataset::Open;
1434
poDriver->pfnIdentify = ERSDataset::Identify;
1204
1435
poDriver->pfnCreate = ERSDataset::Create;
1206
1437
GetGDALDriverManager()->RegisterDriver( poDriver );