Opened 17 years ago

Last modified 12 years ago

#1637 closed enhancement

patch for 1.4.x : frmts/netcdf (NC_GLOBAL#{spatial_ref/GeoTransform}) — at Version 6

Reported by: cermak@… Owned by: dnadeau
Priority: normal Milestone: 1.8.1
Component: GDAL_Raster Version: 1.4.1
Severity: normal Keywords: netcdf
Cc: cermak@…, warmerdam, Mateusz Łoskot, Markus Neteler, Kyle Shannon

Description (last modified by Mateusz Łoskot)

Recent events have us looking the the direct access Netcdf driver (frmts/netcdf). We discovered that the spatial_ref and GeoTransform global tags are ignored for non-complient CF-1.0 files.

Patch: http://ak.aoos.org/data/patch/frmts_netcdf_global_georef.patch

WRF data file, if needed: http://137.229.130.18/data/forecasts/AEFF/WRF/CIPWS12km/200705/14/00/wrfout_d01_2007-05-16_00.nc

(sorry about the size! 14 MB)

1.4.1:

gdalinfo NETCDF:"wrfout_d01_2007-05-16_00.nc":T2
  NC_GLOBAL#spatial_ref=+proj=stere +lon_0=-147.300003052 +lat_0=90
+lat_ts=60.2000007629 +a=6378273 +rf=298.279405043 +x_0=0 +y_0=0
  NC_GLOBAL#GeoTransform=-541931.561016 12045.5692702 0 -3610575.06283 0
12025.6894815
  T2#FieldType=104
  T2#MemoryOrder=XY
  T2#description=TEMP at 2 M
  T2#units=K
  T2#stagger=
  T2#coordinates=XLONG XLAT
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,   72.0)
Upper Right (   90.0,    0.0)
Lower Right (   90.0,   72.0)
Center      (   45.0,   36.0)
Band 1 Block=90x1 Type=Float32, ColorInterp=Undefined
  NoData Value=9.96920996838687e+36
  Metadata:
    NETCDF_VARNAME=T2
    NETCDF_DIMENSION_Time=1
GDAL: GDALClose(NETCDF:wrfout_d01_2007-05-16_00.nc:T2)
GDAL: GDALDeregister_GTiff() called.

With the above patch:

  NC_GLOBAL#spatial_ref=+proj=stere +lon_0=-147.300003052 +lat_0=90
+lat_ts=60.2000007629 +a=6378273 +rf=298.279405043 +x_0=0 +y_0=0
  NC_GLOBAL#GeoTransform=-541931.561016 12045.5692702 0 -3610575.06283 0
12025.6894815
  T2#FieldType=104
  T2#MemoryOrder=XY
  T2#description=TEMP at 2 M
  T2#units=K
  T2#stagger=
  T2#coordinates=XLONG XLAT
Corner Coordinates:
Upper Left  ( -541931.561,-3610575.063)
Lower Left  ( -541931.561,-2744725.420)
Upper Right (  542169.673,-3610575.063)
Lower Right (  542169.673,-2744725.420)
Center      (     119.056,-3177650.241)
Band 1 Block=90x1 Type=Float32, ColorInterp=Undefined
  NoData Value=9.96920996838687e+36
  Metadata:
    NETCDF_VARNAME=T2
    NETCDF_DIMENSION_Time=1
GDAL: GDALClose(NETCDF:wrfout_d01_2007-05-16_00.nc:T2)
GDAL: GDALDeregister_GTiff() called.

Change History (6)

comment:1 by guest, 17 years ago

Component: defaultGDAL_Raster
Owner: changed from warmerdam to cermak@…

Unfortunately, this only seems 1/2 the battle. I was hoping the dataset would then be accessible via Mapserver as we are able to do via OPeNDAP

I will reassign to myself until I can figure out the 2nd half.

I copied a bit of code to convert the spatial_ref if it was a PROJ.4 string to WKT. gdalwarp didn't like the PROJ.4 string we use.

Version 2 vs. 1.4.1: http://ak.aoos.org/data/patch/frmts_netcdf_global_georef.patch

To crack the 2nd half of the nut, I need to get a working example from the OPeNDAP side. Right now, I get a blank image.

gdalwarp NETCDF:/space/data/forecasts/AEFF/WRF/CIPWS12km/200705/14/00/wrfout_d01_2007-05-16_00.nc:T2 x.tiff GDAL: GDALOpen(x.tiff) succeeds as GTiff. GDAL_netCDF: dim_count = 9

Warning 1: No UNIDATA NC_GLOBAL:Conventions attribute GDAL_netCDF: var_count = 130

GDAL_netCDF: Found NC_GLOBAL#spatial_ref

GDAL_netCDF: Fetching NC_GLOBAL#spatial_ref

GDAL_netCDF: WKT = PROJCS["unnamed",GEOGCS["unnamed ellipse",DATUM["unknown",SPHEROID["unnamed",6378273,298.279405043]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTIONPolar_Stereographic,PARAMETER["latitude_of_origin",60.2000007629],PARAMETER["central_meridian",-147.300003052],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0]]

GDAL_netCDF: Fetching NC_GLOBAL#GeoTransform

GDAL: GDALOpen(NETCDF:/space/data/forecasts/AEFF/WRF/CIPWS12km/200705/14/00/wrfout_d01_2007-05-16_00.nc:T2) succeeds as netCDF. Processing input file NETCDF:/space/data/forecasts/AEFF/WRF/CIPWS12km/200705/14/00/wrfout_d01_2007-05-16_00.nc:T2. GDAL: GDALWarpKernel()::GWKNearestNoMasksFloat() Src=0,0,90x72 Dst=0,0,90x72 :0...11...20...30...40...50...61...70...80...90...100 - done. GDAL: GDALClose(NETCDF:/space/data/forecasts/AEFF/WRF/CIPWS12km/200705/14/00/wrfout_d01_2007-05-16_00.nc:T2) GDAL: GDALClose(x.tiff) GDAL: GDALDeregister_GTiff() called.

comment:2 by guest, 17 years ago

Owner: changed from cermak@… to warmerdam

Ok. As it turns out, the patch works fine.

I happen to have a THREDDS OPeDNAP server to help me reproduce the graphics for both drivers.

The one major difference is that the Netcdf driver does not allow selection of bands like the OPeNDAP driver. Typically, we have all the time dimensions stacked together so we can do something like: T2?[3][y][x] where 3 points to the timeslice we want out of the dataset. If there are multiple times, the NETCDF driver likes to create multiple bands and then the behavior gets a little wierd... the WKT gets stomped somehow.

Creating output file that is 319P x 224L. GDAL: GDALDriver::Create(GTiff,test.tif,319,224,17,Int16,(nil)) ERROR 1: Only OGC WKT Projections supported for writing to GeoTIFF. (X17�unnamed",GEOGCS["unnamed ellipse",DATUM["unknown",SPHEROID["unnamed",6378273,298.279405043]],P RIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTIONPolar_Stereographic,PARAMETER ["latitude_of_origin",67.5],PARAMETER["central_meridian",-150],PARAMETER["scale_factor",1],PARAMETE R["false_easting",0],PARAMETER["false_northing",0]] not supported.

Overall, this patch will allow georeferencing to work if the global attributes are defined. I think someone else noticed that this stopped working as a couple versions ago.

comment:3 by warmerdam, 17 years ago

Cc: warmerdam added
Milestone: 1.5.0
Owner: changed from warmerdam to dnadeau
Reporter: changed from guest to cermak@…

Denis,

Can you review this and consider applying the patch? I'm a bit lost.

in reply to:  3 comment:4 by guest, 17 years ago

Replying to warmerdam:

Denis,

Can you review this and consider applying the patch? I'm a bit lost.

The patch allows spatial_ref and GeoTransform work via NC_GLOBAL metadata tags. As of 1.4.1, even with the metadata tags, it would not georeference properly.

comment:5 by Mateusz Łoskot, 16 years ago

Cc: Mateusz Łoskot added

comment:6 by Mateusz Łoskot, 16 years ago

Description: modified (diff)
Keywords: netcdf added
Note: See TracTickets for help on using tickets.