I try to convert netcdf4 file to raster by using gdal and python. The netcdf4 file is in the WGS84 geographic coordinate system. When I use "Make NetCDF Raster Layer" in ArcMap, the netcdf file is converted to raster and placed on the right spatial location.

However,when I use the commandline gdal_translate as below, the translated raster is placed on the wrong spatial location.

'gdal_translate -of Gtiff -a_srs "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" NETCDF:"precip.nc4":precipitationCal "RasterPrecip.tiff"'

I get same result for gdal python as shown below also. The converted raster is placed on wrong spatial location

from osgeo import gdal filename = "precip.nc4" data = gdal.Open('NETCDF:"'+filename+'":precipitationCal') Dataset = driver.Create(Newfile, xsize, ysize) Dataset.SetGeoTransform(geo_transform) Dataset.SetProjection(spatialRefProj) Dataset.GetRasterBand(1).WriteArray(rain)

I am unable to get the projection from the file. data.GetProjection() gives invalid (' ') projection. As the file coordiante system is as WGS84, I used.

spatialRef = osr.SpatialReference() spatialRef.ImportFromEPSG(4326)

Further, data.GetGeoTransform() gives (57.4, 0.1, 0.0, 14.8, 0.0, -0.1). The first value should be top lext, x (longitude). Here comes latitude value(57.4). I expected to get (6.4,0.1,0,62.0,0,-0.1). However, if I set this as geotransform, I still get wrong result.

I think that wrong geotransform which is read from the netcdf file may be the reason for wrong result but how is ArcMap reading correctly?

Additional information: By commandline gdalinfo NETCDF:"precip.nc4":precipitationCal gives

Warning 1: No UNIDATA NC_GLOBAL:Conventions attribute Driver: netCDF/Network Common Data Format Files:C:\precip.nc4 Size is 46, 84 Coordinate System is '' Origin = (57.400000762939456,14.800000001149005) Pixel Size = (0.100000000000000,-0.100000002298010) Geolocation: LINE_OFFSET=0 LINE_STEP=1 PIXEL_OFFSET=0 PIXEL_STEP=1 SRS=GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] AUTHORITY["EPSG","4326"]] X_BAND=1 X_DATASET=NETCDF:"C:\precip.nc4":lon Y_BAND=1 Y_DATASET=NETCDF:"C:\precip.nc4":lat Corner Coordinates: Upper Left ( 57.4000008, 14.8000000) Lower Left ( 57.4000008, 6.3999998) Upper Right ( 62.0000008, 14.8000000) Lower Right ( 62.0000008, 6.3999998) Center ( 59.7000008, 10.5999999)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.