Opened 5 years ago

Closed 4 years ago

#4660 closed enhancement (fixed)

GTX NoData value

Reported by: Kurt Schwehr Owned by: Kurt Schwehr
Priority: normal Milestone:
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords: gtx nodata
Cc:

Description

It appears that the GTX files all use -88.8888 as the NoData? value. Would it be reasonable to hard code that in the driver? Not sure if this is safe to do.

http://vdatum.noaa.gov/dev/gtx_info.html

Change History (5)

comment:1 Changed 5 years ago by warmerdam

Component: defaultGDAL_Raster
Keywords: gtx nodata added

Hmm, I'm afraid I have created these files without using -88.8888 as my nodata value.

I'll take this under advisement.

comment:2 Changed 4 years ago by Kurt Schwehr

Owner: changed from warmerdam to Kurt Schwehr
Status: newassigned

I think I've got it figured. Does this patch look sane? If so, I'll commit it to trunk.

--- frmts/raw/gtxdataset.cpp	(revision 26477)
+++ frmts/raw/gtxdataset.cpp	(working copy)
@@ -213,12 +213,14 @@
 /* -------------------------------------------------------------------- */
 /*      Create band information object.                                 */
 /* -------------------------------------------------------------------- */
-    poDS->SetBand( 
-        1, new RawRasterBand( poDS, 1, poDS->fpImage, 
+    RawRasterBand *poBand = new RawRasterBand( poDS, 1, poDS->fpImage, 
                               (poDS->nRasterYSize-1)*poDS->nRasterXSize*nDTSize + 40,
                               nDTSize, poDS->nRasterXSize * -nDTSize,
                               eDT,
-                              !CPL_IS_LSB, TRUE, FALSE ) );
+                              !CPL_IS_LSB, TRUE, FALSE );
+    /* The published nodata value is -88.8888 */
+    poBand->SetNoDataValue( -88.88880157470703125 );
+    poDS->SetBand( 1, poBand );
 
 /* -------------------------------------------------------------------- */
 /*      Initialize any PAM information.                                 */
@@ -405,4 +407,3 @@
         GetGDALDriverManager()->RegisterDriver( poDriver );
     }
 }

With the above patch:

gdalinfo -mm -stats -hist data/hydroc1.gtx

Driver: GTX/NOAA Vertical Datum .GTX
Files: data/hydroc1.gtx
Size is 21, 11
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        TOWGS84[0,0,0,0,0,0,0],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9108"]],
    AUTHORITY["EPSG","4326"]]
Origin = (276.725000000000023,42.774999999999999)
Pixel Size = (0.050000000000000,-0.050000000000000)
Corner Coordinates:
Upper Left  (     276.725,      42.775) (276d43'30.00"E, 42d46'30.00"N)
Lower Left  (     276.725,      42.225) (276d43'30.00"E, 42d13'30.00"N)
Upper Right (     277.775,      42.775) (277d46'30.00"E, 42d46'30.00"N)
Lower Right (     277.775,      42.225) (277d46'30.00"E, 42d13'30.00"N)
Center      (     277.250,      42.500) (277d15' 0.00"E, 42d30' 0.00"N)
Band 1 Block=21x1 Type=Float32, ColorInterp=Undefined
    Computed Min/Max=-0.008,0.889
  Minimum=-0.008, Maximum=0.889, Mean=0.008, StdDev=0.093
0...10...20...30...40...50...60...70...80...90...100 - done.
  256 buckets from -0.00960814 to 0.890558:
  7 28 39 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 
  NoData Value=-88.8888015747070312
  Metadata:
    STATISTICS_MAXIMUM=0.88880002498627
    STATISTICS_MEAN=0.0079685717094805
    STATISTICS_MINIMUM=-0.0078499997034669
    STATISTICS_STDDEV=0.09289099269752

comment:3 Changed 4 years ago by Kurt Schwehr

I'll likely commit this tomorrow:

Index: frmts/raw/gtxdataset.cpp
===================================================================
--- frmts/raw/gtxdataset.cpp	(revision 26477)
+++ frmts/raw/gtxdataset.cpp	(working copy)
@@ -213,13 +213,19 @@
 /* -------------------------------------------------------------------- */
 /*      Create band information object.                                 */
 /* -------------------------------------------------------------------- */
-    poDS->SetBand( 
-        1, new RawRasterBand( poDS, 1, poDS->fpImage, 
+    RawRasterBand *poBand = new RawRasterBand( poDS, 1, poDS->fpImage, 
                               (poDS->nRasterYSize-1)*poDS->nRasterXSize*nDTSize + 40,
                               nDTSize, poDS->nRasterXSize * -nDTSize,
                               eDT,
-                              !CPL_IS_LSB, TRUE, FALSE ) );
+                              !CPL_IS_LSB, TRUE, FALSE );
+    if (eDT == GDT_Float64)
+      poBand->SetNoDataValue( -88.8888 );
+    else
+      /* GDT_Float32 */
+      poBand->SetNoDataValue( (double)-88.8888f );
 
+    poDS->SetBand( 1, poBand );
+
 /* -------------------------------------------------------------------- */
 /*      Initialize any PAM information.                                 */
 /* -------------------------------------------------------------------- */
@@ -405,4 +411,3 @@
         GetGDALDriverManager()->RegisterDriver( poDriver );
     }
 }

examples of it working (clipped)... Float32 and Float64

gdalinfo -mm -stats mllw.gtx 
Driver: GTX/NOAA Vertical Datum .GTX
Files: mllw.gtx

[SNIP]

Band 1 Block=2735x1 Type=Float32, ColorInterp=Undefined
    Computed Min/Max=-0.250,-0.105
  Minimum=-0.250, Maximum=-0.105, Mean=-0.203, StdDev=0.007
  NoData Value=-88.8888015747070312
  Metadata:
    STATISTICS_MAXIMUM=-0.10499999672174
    STATISTICS_MEAN=-0.20285526143051
    STATISTICS_MINIMUM=-0.25
    STATISTICS_STDDEV=0.0071759497517278


gdalinfo -mm -stats mlw.gtx 
Driver: GTX/NOAA Vertical Datum .GTX
Files: mlw.gtx

[SNIP]

Band 1 Block=1577x1 Type=Float64, ColorInterp=Undefined
    Computed Min/Max=-1.028,-0.590
  Minimum=-1.028, Maximum=-0.590, Mean=-0.815, StdDev=0.129
  NoData Value=-88.8888000000000034
  Metadata:
    STATISTICS_MAXIMUM=-0.5897
    STATISTICS_MEAN=-0.81528148243098
    STATISTICS_MINIMUM=-1.028
    STATISTICS_STDDEV=0.1285893765501

comment:4 Changed 4 years ago by warmerdam

Kurt,

Looks good to me.

BTW, there is no harm in setting the nodata value after the SetBand?() call.

comment:5 Changed 4 years ago by Kurt Schwehr

Resolution: fixed
Status: assignedclosed

Fixed in trunk (r26478)

Note: See TracTickets for help on using tickets.