~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to frmts/ers/ersdataset.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: ersdataset.cpp 17867 2009-10-21 21:04:49Z rouault $
 
2
 * $Id: ersdataset.cpp 23029 2011-09-03 10:15:51Z rouault $
3
3
 *
4
4
 * Project:  ERMapper .ers Driver
5
5
 * Purpose:  Implementation of .ers driver.
32
32
#include "cpl_string.h"
33
33
#include "ershdrnode.h"
34
34
 
35
 
CPL_CVSID("$Id: ersdataset.cpp 17867 2009-10-21 21:04:49Z rouault $");
 
35
CPL_CVSID("$Id: ersdataset.cpp 23029 2011-09-03 10:15:51Z rouault $");
36
36
 
37
37
/************************************************************************/
38
38
/* ==================================================================== */
39
 
/*                              ERSDataset                              */
 
39
/*                              ERSDataset                              */
40
40
/* ==================================================================== */
41
41
/************************************************************************/
42
42
 
44
44
 
45
45
class ERSDataset : public RawDataset
46
46
{
47
 
    FILE        *fpImage;       // image data file.
 
47
    friend class ERSRasterBand;
 
48
 
 
49
    VSILFILE    *fpImage;       // image data file.
48
50
    GDALDataset *poDepFile;
49
51
 
50
52
    int         bGotTransform;
63
65
    char          *pszGCPProjection;
64
66
 
65
67
    void          ReadGCPs();
 
68
 
 
69
    int         bHasNoDataValue;
 
70
    double      dfNoDataValue;
 
71
 
 
72
    CPLString      osProj;
 
73
    CPLString      osDatum;
 
74
    CPLString      osUnits;
 
75
    void           WriteProjectionInfo(const char* pszProj,
 
76
                                       const char* pszDatum,
 
77
                                       const char* pszUnits);
 
78
 
 
79
    CPLStringList oERSMetadataList;
 
80
 
 
81
  protected:
 
82
    virtual int         CloseDependentDatasets();
 
83
 
66
84
  public:
67
85
                ERSDataset();
68
86
               ~ERSDataset();
80
98
    virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
81
99
                            const char *pszGCPProjection );
82
100
 
 
101
    virtual const char *GetMetadataItem( const char * pszName,
 
102
                                     const char * pszDomain = "" );
 
103
    virtual char      **GetMetadata( const char * pszDomain = "" );
 
104
 
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 );
87
110
};
88
111
 
89
112
/************************************************************************/
90
 
/* ==================================================================== */
91
 
/*                              ERSDataset                              */
92
 
/* ==================================================================== */
93
 
/************************************************************************/
94
 
 
95
 
/************************************************************************/
96
113
/*                            ERSDataset()                             */
97
114
/************************************************************************/
98
115
 
114
131
    nGCPCount = 0;
115
132
    pasGCPList = NULL;
116
133
    pszGCPProjection = CPLStrdup("");
 
134
 
 
135
    bHasNoDataValue = FALSE;
 
136
    dfNoDataValue = 0.0;
117
137
}
118
138
 
119
139
/************************************************************************/
130
150
        VSIFCloseL( fpImage );
131
151
    }
132
152
 
 
153
    CloseDependentDatasets();
 
154
 
 
155
    CPLFree( pszProjection );
 
156
 
 
157
    CPLFree( pszGCPProjection );
 
158
    if( nGCPCount > 0 )
 
159
    {
 
160
        GDALDeinitGCPs( nGCPCount, pasGCPList );
 
161
        CPLFree( pasGCPList );
 
162
    }
 
163
 
 
164
    if( poHeader != NULL )
 
165
        delete poHeader;
 
166
}
 
167
 
 
168
/************************************************************************/
 
169
/*                      CloseDependentDatasets()                        */
 
170
/************************************************************************/
 
171
 
 
172
int ERSDataset::CloseDependentDatasets()
 
173
{
 
174
    int bHasDroppedRef = RawDataset::CloseDependentDatasets();
 
175
 
133
176
    if( poDepFile != NULL )
134
177
    {
135
178
        int iBand;
136
179
 
 
180
        bHasDroppedRef = TRUE;
 
181
 
137
182
        for( iBand = 0; iBand < nBands; iBand++ )
138
183
            papoBands[iBand] = NULL;
 
184
        nBands = 0;
139
185
 
140
186
        GDALClose( (GDALDatasetH) poDepFile );
141
 
    }
142
 
 
143
 
    CPLFree( pszProjection );
144
 
 
145
 
    CPLFree( pszGCPProjection );
146
 
    if( nGCPCount > 0 )
147
 
    {
148
 
        GDALDeinitGCPs( nGCPCount, pasGCPList );
149
 
        CPLFree( pasGCPList );
150
 
    }
151
 
 
152
 
    if( poHeader != NULL )
153
 
        delete poHeader;
 
187
        poDepFile = NULL;
 
188
    }
 
189
 
 
190
    return bHasDroppedRef;
154
191
}
155
192
 
156
193
/************************************************************************/
162
199
{
163
200
    if( bHDRDirty )
164
201
    {
165
 
        FILE * fpERS = VSIFOpenL( GetDescription(), "w" );
 
202
        VSILFILE * fpERS = VSIFOpenL( GetDescription(), "w" );
166
203
        if( fpERS == NULL )
167
204
        {
168
205
            CPLError( CE_Failure, CPLE_OpenFailed, 
182
219
}
183
220
 
184
221
/************************************************************************/
 
222
/*                           GetMetadataItem()                          */
 
223
/************************************************************************/
 
224
 
 
225
const char *ERSDataset::GetMetadataItem( const char * pszName,
 
226
                                         const char * pszDomain )
 
227
{
 
228
    if (pszDomain != NULL && EQUAL(pszDomain, "ERS") && pszName != NULL)
 
229
    {
 
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;
 
236
    }
 
237
    return GDALPamDataset::GetMetadataItem(pszName, pszDomain);
 
238
}
 
239
 
 
240
/************************************************************************/
 
241
/*                            GetMetadata()                             */
 
242
/************************************************************************/
 
243
 
 
244
char **ERSDataset::GetMetadata( const char *pszDomain )
 
245
 
 
246
{
 
247
    if( pszDomain != NULL && EQUAL(pszDomain, "ERS") )
 
248
    {
 
249
        oERSMetadataList.Clear();
 
250
        if (osProj.size())
 
251
            oERSMetadataList.AddString(CPLSPrintf("%s=%s", "PROJ", osProj.c_str()));
 
252
        if (osDatum.size())
 
253
            oERSMetadataList.AddString(CPLSPrintf("%s=%s", "DATUM", osDatum.c_str()));
 
254
        if (osUnits.size())
 
255
            oERSMetadataList.AddString(CPLSPrintf("%s=%s", "UNITS", osUnits.c_str()));
 
256
        return oERSMetadataList.List();
 
257
    }
 
258
    else
 
259
        return GDALPamDataset::GetMetadata( pszDomain );
 
260
}
 
261
 
 
262
/************************************************************************/
185
263
/*                            GetGCPCount()                             */
186
264
/************************************************************************/
187
265
 
260
338
    char szERSProj[32], szERSDatum[32], szERSUnits[32];
261
339
 
262
340
    oSRS.exportToERM( szERSProj, szERSDatum, szERSUnits );
263
 
    
 
341
 
 
342
    /* Write the above computed values, unless they have been overriden by */
 
343
    /* the creation options PROJ, DATUM or UNITS */
 
344
 
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", 
273
357
                   "0:0:0.0" );
274
358
 
337
421
    char szERSProj[32], szERSDatum[32], szERSUnits[32];
338
422
 
339
423
    oSRS.exportToERM( szERSProj, szERSDatum, szERSUnits );
340
 
    
 
424
 
 
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 );
 
430
 
 
431
    return CE_None;
 
432
}
 
433
 
 
434
/************************************************************************/
 
435
/*                         WriteProjectionInfo()                        */
 
436
/************************************************************************/
 
437
 
 
438
void ERSDataset::WriteProjectionInfo(const char* pszProj,
 
439
                                     const char* pszDatum,
 
440
                                     const char* pszUnits)
 
441
{
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", 
351
452
                   "0:0:0.0" );
352
453
 
389
490
            poHeader->papszItemValue[i-1] = pszTemp;
390
491
        }
391
492
    }
392
 
    
393
 
    return CE_None;
394
493
}
395
494
 
396
495
/************************************************************************/
459
558
 
460
559
    if( CSLCount(papszTokens) != 3 )
461
560
    {
 
561
        CSLDestroy(papszTokens);
462
562
        return CPLAtof( pszDMS );
463
563
    }
464
564
    else
536
636
        nItemsPerLine = 8;
537
637
    else if( nItemCount < 14 )
538
638
    {
539
 
        CPLAssert( FALSE );
 
639
        CPLDebug("ERS", "Invalid item count for ControlPoints");
 
640
        CSLDestroy( papszTokens );
540
641
        return;
541
642
    }
542
643
    else if( EQUAL(papszTokens[8],"Yes") || EQUAL(papszTokens[8],"No") )
545
646
        nItemsPerLine = 8;
546
647
    else
547
648
    {
548
 
        CPLAssert( FALSE );
 
649
        CPLDebug("ERS", "Invalid format for ControlPoints");
 
650
        CSLDestroy( papszTokens );
549
651
        return;
550
652
    }
551
653
 
581
683
/* -------------------------------------------------------------------- */
582
684
    OGRSpatialReference oSRS;
583
685
 
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", "" );
590
689
 
591
 
    oSRS.importFromERM( osProjection, osDatum, osUnits );
 
690
    oSRS.importFromERM( osProj.size() ? osProj : "RAW",
 
691
                        osDatum.size() ? osDatum : "WGS84",
 
692
                        osUnits.size() ? osUnits : "METERS" );
592
693
 
593
694
    CPLFree( pszGCPProjection );
594
695
    oSRS.exportToWkt( &pszGCPProjection );
595
696
}
596
697
 
597
698
/************************************************************************/
598
 
/*                                Open()                                */
599
 
/************************************************************************/
600
 
 
601
 
GDALDataset *ERSDataset::Open( GDALOpenInfo * poOpenInfo )
 
699
/* ==================================================================== */
 
700
/*                             ERSRasterBand                            */
 
701
/* ==================================================================== */
 
702
/************************************************************************/
 
703
 
 
704
class ERSRasterBand : public RawRasterBand
 
705
{
 
706
    public:
 
707
 
 
708
                 ERSRasterBand( GDALDataset *poDS, int nBand, void * fpRaw,
 
709
                                vsi_l_offset nImgOffset, int nPixelOffset,
 
710
                                int nLineOffset,
 
711
                                GDALDataType eDataType, int bNativeOrder,
 
712
                                int bIsVSIL = FALSE, int bOwnsFP = FALSE );
 
713
 
 
714
    virtual double GetNoDataValue( int *pbSuccess = NULL );
 
715
    virtual CPLErr SetNoDataValue( double );
 
716
};
 
717
 
 
718
/************************************************************************/
 
719
/*                           ERSRasterBand()                            */
 
720
/************************************************************************/
 
721
 
 
722
ERSRasterBand::ERSRasterBand( GDALDataset *poDS, int nBand, void * fpRaw,
 
723
                                vsi_l_offset nImgOffset, int nPixelOffset,
 
724
                                int nLineOffset,
 
725
                                GDALDataType eDataType, int bNativeOrder,
 
726
                                int bIsVSIL, int bOwnsFP ) :
 
727
    RawRasterBand(poDS, nBand, fpRaw, nImgOffset, nPixelOffset,
 
728
                  nLineOffset, eDataType, bNativeOrder, bIsVSIL, bOwnsFP)
 
729
{
 
730
}
 
731
 
 
732
/************************************************************************/
 
733
/*                           GetNoDataValue()                           */
 
734
/************************************************************************/
 
735
 
 
736
double ERSRasterBand::GetNoDataValue( int *pbSuccess )
 
737
{
 
738
    ERSDataset* poGDS = (ERSDataset*) poDS;
 
739
    if (poGDS->bHasNoDataValue)
 
740
    {
 
741
        if (pbSuccess)
 
742
            *pbSuccess = TRUE;
 
743
        return poGDS->dfNoDataValue;
 
744
    }
 
745
 
 
746
    return RawRasterBand::GetNoDataValue(pbSuccess);
 
747
}
 
748
 
 
749
/************************************************************************/
 
750
/*                           SetNoDataValue()                           */
 
751
/************************************************************************/
 
752
 
 
753
CPLErr ERSRasterBand::SetNoDataValue( double dfNoDataValue )
 
754
{
 
755
    ERSDataset* poGDS = (ERSDataset*) poDS;
 
756
    if (!poGDS->bHasNoDataValue || poGDS->dfNoDataValue != dfNoDataValue)
 
757
    {
 
758
        poGDS->bHasNoDataValue = TRUE;
 
759
        poGDS->dfNoDataValue = dfNoDataValue;
 
760
 
 
761
        poGDS->bHDRDirty = TRUE;
 
762
        poGDS->poHeader->Set( "RasterInfo.NullCellValue",
 
763
                    CPLString().Printf( "%.16g", dfNoDataValue) );
 
764
    }
 
765
    return CE_None;
 
766
}
 
767
 
 
768
/************************************************************************/
 
769
/*                              Identify()                              */
 
770
/************************************************************************/
 
771
 
 
772
int ERSDataset::Identify( GDALOpenInfo * poOpenInfo )
602
773
 
603
774
{
604
775
/* -------------------------------------------------------------------- */
607
778
    if( poOpenInfo->nHeaderBytes > 15
608
779
        && EQUALN((const char *) poOpenInfo->pabyHeader,"Algorithm Begin",15) )
609
780
    {
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 );
613
 
        return NULL;
 
784
        return FALSE;
614
785
    }
615
786
 
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) )
 
792
        return FALSE;
 
793
 
 
794
    return TRUE;
 
795
}
 
796
 
 
797
/************************************************************************/
 
798
/*                                Open()                                */
 
799
/************************************************************************/
 
800
 
 
801
GDALDataset *ERSDataset::Open( GDALOpenInfo * poOpenInfo )
 
802
 
 
803
{
 
804
    if( !Identify( poOpenInfo ) )
621
805
        return NULL;
622
806
 
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" );
627
811
    
628
812
    if( fpERS == NULL )
629
813
        return NULL;
795
979
                // Assume pixel interleaved.
796
980
                poDS->SetBand( 
797
981
                    iBand+1, 
798
 
                    new RawRasterBand( poDS, iBand+1, poDS->fpImage,
 
982
                    new ERSRasterBand( poDS, iBand+1, poDS->fpImage,
799
983
                                       nHeaderOffset 
800
984
                                       + iWordSize * iBand * poDS->nRasterXSize,
801
985
                                       iWordSize,
841
1025
                poDS->GetRasterBand( iBand )->SetDescription( pszValue );
842
1026
                CPLPopErrorHandler();
843
1027
            }
 
1028
 
 
1029
            pszValue = poRI->papoItemChild[iChild]->Find( "Units", NULL );
 
1030
            if ( pszValue )
 
1031
            {
 
1032
                CPLPushErrorHandler( CPLQuietErrorHandler );
 
1033
                poDS->GetRasterBand( iBand )->SetUnitType( pszValue );
 
1034
                CPLPopErrorHandler();
 
1035
            }
844
1036
        }
845
1037
    }
846
1038
 
849
1041
/* -------------------------------------------------------------------- */
850
1042
    OGRSpatialReference oSRS;
851
1043
 
852
 
    CPLString osProjection = poHeader->Find( "CoordinateSpace.Projection", 
853
 
                                             "RAW" );
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", "" );
856
1047
 
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" );
858
1051
 
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 ) )
867
1059
    {
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" ));
879
1071
    }
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 ) )
916
1108
    {
917
 
        CPLPushErrorHandler( CPLQuietErrorHandler );
918
 
 
919
 
        for( iBand = 1; iBand <= poDS->nBands; iBand++ )
920
 
            poDS->GetRasterBand(iBand)->SetNoDataValue(
921
 
                CPLAtofM(poHeader->Find( "RasterInfo.NullCellValue" )) );
922
 
        
923
 
        CPLPopErrorHandler();
 
1109
        poDS->bHasNoDataValue = TRUE;
 
1110
        poDS->dfNoDataValue = CPLAtofM(poHeader->Find( "RasterInfo.NullCellValue" ));
 
1111
 
 
1112
        if (poDS->poDepFile != NULL)
 
1113
        {
 
1114
            CPLPushErrorHandler( CPLQuietErrorHandler );
 
1115
 
 
1116
            for( iBand = 1; iBand <= poDS->nBands; iBand++ )
 
1117
                poDS->GetRasterBand(iBand)->SetNoDataValue(poDS->dfNoDataValue);
 
1118
 
 
1119
            CPLPopErrorHandler();
 
1120
        }
924
1121
    }
925
1122
 
926
1123
/* -------------------------------------------------------------------- */
1103
1300
    GUIntBig nSize;
1104
1301
    GByte byZero = 0;
1105
1302
 
1106
 
    FILE *fpBin = VSIFOpenL( osBinFile, "w" );
 
1303
    VSILFILE *fpBin = VSIFOpenL( osBinFile, "w" );
1107
1304
 
1108
1305
    if( fpBin == NULL )
1109
1306
    {
1130
1327
/* -------------------------------------------------------------------- */
1131
1328
/*      Try writing header file.                                        */
1132
1329
/* -------------------------------------------------------------------- */
1133
 
    FILE *fpERS = VSIFOpenL( osErsFile, "w" );
 
1330
    VSILFILE *fpERS = VSIFOpenL( osErsFile, "w" );
1134
1331
    
1135
1332
    if( fpERS == NULL )
1136
1333
    {
1171
1368
/* -------------------------------------------------------------------- */
1172
1369
/*      Reopen.                                                         */
1173
1370
/* -------------------------------------------------------------------- */
1174
 
    return (GDALDataset *) GDALOpen( osErsFile, GA_Update );
 
1371
    GDALOpenInfo oOpenInfo( osErsFile, GA_Update );
 
1372
    ERSDataset* poDS = (ERSDataset*) Open( &oOpenInfo );
 
1373
    if (poDS == NULL)
 
1374
        return NULL;
 
1375
 
 
1376
/* -------------------------------------------------------------------- */
 
1377
/*      Fetch DATUM, PROJ and UNITS creation option                     */
 
1378
/* -------------------------------------------------------------------- */
 
1379
    const char *pszDatum = CSLFetchNameValue( papszOptions, "DATUM" );
 
1380
    if (pszDatum)
 
1381
        poDS->osDatum = pszDatum;
 
1382
    const char *pszProj = CSLFetchNameValue( papszOptions, "PROJ" );
 
1383
    if (pszProj)
 
1384
        poDS->osProj = pszProj;
 
1385
    const char *pszUnits = CSLFetchNameValue( papszOptions, "UNITS" );
 
1386
    if (pszUnits)
 
1387
        poDS->osUnits = pszUnits;
 
1388
 
 
1389
    if (pszDatum || pszProj || pszUnits)
 
1390
    {
 
1391
        poDS->WriteProjectionInfo(pszProj ? pszProj : "RAW",
 
1392
                                  pszDatum ? pszDatum : "RAW",
 
1393
                                  pszUnits ? pszUnits : "METERS");
 
1394
    }
 
1395
    
 
1396
    return poDS;
1175
1397
}
1176
1398
 
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>"
 
1428
"   </Option>"
1201
1429
"</CreationOptionList>" );
1202
1430
 
 
1431
        poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" );
 
1432
 
1203
1433
        poDriver->pfnOpen = ERSDataset::Open;
 
1434
        poDriver->pfnIdentify = ERSDataset::Identify;
1204
1435
        poDriver->pfnCreate = ERSDataset::Create;
1205
1436
 
1206
1437
        GetGDALDriverManager()->RegisterDriver( poDriver );