I successfully extracted some data from a netCDF file with a single variable E. (the original file was taking ages to load). I used the following code to extract the data:

ncks -d lon,24.,36. -d lat,21.,32. E_2015.nc extracted_E.nc

The resulting file I open using the popular python plugin "NetCDF Browser" by Mr Etienne Tourigny. Usually, the file opens and displays fantastically. However, I have come across some that have rather peculiar behaviour. (Please see below)

netCDF data in B/W Vector layer of where the data should be in purple

The purple layer is a vector layer for correct orientation reference, the netCDF data appears to be mirrored (with longitudes/latitudes switched and transversed).

gdalinfo gives me :

Driver: netCDF/Network Common Data Format
Files: extracted_E.nc
Size is 44, 48
Coordinate System is `'
Origin = (32.000000000000000,36.000000000000000)
Pixel Size = (-0.250000000000000,-0.250000000000000)
  E#long_name=Some Variable
  E#standard_name=Some Variable
  NC_GLOBAL#history=Sun Nov 20 16:14:38 2016: ncks -d lon,24.,36. -d lat,21.,32. E_2015.nc extracted_E.nc
  time#units=days since 1970-01-01 00:00:00 UTC
Corner Coordinates:
Upper Left  (  32.0000000,  36.0000000) 
Lower Left  (  32.0000000,  24.0000000) 
Upper Right (  21.0000000,  36.0000000) 
Lower Right (  21.0000000,  24.0000000)
(followed by band data)

Both the original netCDF and the extracted display correctly in netCDF browsers/viewers such as PanoplyJ. Other extracted netCDF files also display correctly in QGIS. Is there something special about this file? How can I fix this?

I have tried gdalwarp:

gdalwarp -t_srs '+proj=lonlat +datum=WGS84 +no_defs t_srs EPSG:4326' -of E_2015.nc x.nc

I get:

ERROR 1: Translating source or target SRS failed:


gdal_translate -a_ullr 24.0 32.0 36.0 21.0 -a_srs 'EPSG:4326' -of netCDF E_2015.nc x.nc


Warning 1: No UNIDATA NC_GLOBAL:Conventions attribute

With the resulting image as shown below.

enter image description here

B/W file is the new data. This needs to be at right angles to what it is.

The resulting file when treated with the same code as above returns the original rotation (see first image above), but bound within the area of the purple vector reference. It is almost as if the Image is rotated around those two points the (ulx,uly) and (lrx,lry) overridden by gdal_translate (similar to flipping a card around it's diagonals). Also no amount of swapping x and y, or entering the opposing diagonal points in the gdal_translate command results in the correct orientation(on either the original data, or the result of gdal_translate).

I've also attempted to convert to Geotiff and reproject with no luck.

3 Answers 3


You can use the netCDF operators (NCO) to add spatial reference information that will be understood by QGIS. Essentially, we need to:

  1. Create a crs variable that has no associated dimensions
  2. Attach attributes to the crs variable that describe our coordinate system
  3. Use a grid_mapping attribute to associate the variables that contain spatial data to attributes defined under crs.

Here's an example in WGS84:

ncap -h -O -s 'crs=-9999' my_data.nc my_data.nc
ncatted -h -O \
    -a spatial_ref,crs,c,c,'GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.017453292519943295]]' \
    -a grid_mapping_name,crs,c,c,'latitude_longitude' \
    -a longitude_of_prime_meridian,crs,c,d,0 \
    -a semi_major_axis,crs,c,d,6378137 \
    -a inverse_flattening,crs,c,d,298.257223563 \
    -a grid_mapping,my_var_1,c,c,'crs' \
    -a grid_mapping,my_var_2,c,c,'crs' \

The problem is that the NetCDF file is not arranged in Climate and Forecast conventions and contains a grid of values without those being linked to a particular map projection and coordinates. However, looking at your gdalinfo output, it seems like the latitude and longitude values at each grid point are stored along with the grid of values.

A solution I worked out with similarly formatted NetCDF files:

1) Use a NetCDF utility to determine the lat/lon corner points. I've used ncdump for this though one of the NCO utilities should work as well, e.g.

ncdump -v latitude -f f (NetCDF file) | grep "latitude(1,maxy)"    # ULY
ncdump -v latitude -f f (NetCDF file) | grep "latitude(maxx,1)"    # LRY
ncdump -v latitude -f f (NetCDF file) | grep "latitude(1,1)"       # LLY
ncdump -v latitude -f f (NetCDF file) | grep "latitude(maxx,maxy)" # URY

repeat with longitude substituted above. maxx and maxy for your data is the maximum x and y values (44 and 48(?), respectively). You may not need all of these to georeference the data but might have a need later.

2) Once you find these coordinates, you'll need the upper left and lower right coordinates, i.e. longitude/latitude for 1,maxy and for maxx,1.

3) Knowing those, you can use gdal_translate to georeference the data in EPSG:4326 and save it in preferred format such as GeoTiff:

gdal_translate -a_srs EPSG:4326 -a_ullr ULX ULY LRX LRY (input) (output)

Performing gdalinfo on the resulting file will display the output file being georeferenced with the values used in gdal_translate.

4) You can use gdalwarp to then transform the resulting file into other projections.

NOTE: considering how the image seemed to have the x and y coordinates transposed when you used ncBrowse on the extracted file, you may have work with latitude and longitude values of the data. Just make sure since I can't grab the data you were working with.

Also, you may be able to avoid this if any of the NCO commands will also create the NetCDF file using CF conventions.


The netcdf does not have a CRS stored inside, so gdalwarp can not reproject to any CRS.

You better use

gdal_translate -a_srs 'EPSG:4326' -of netCDF E_2015.nc x.nc
  • Still the same orientation with output : Warning 1: No UNIDATA NC_GLOBAL:Conventions attribute
    – mmfl
    Nov 20, 2016 at 19:27
  • Can you share the file, or give a link to the original data? You might have to apply -a_ullr to set the file correctly.
    – AndreJ
    Nov 21, 2016 at 6:31
  • Original files can be found here overriding with -a_ullr does change the orientation of the data by mirroring it across the x plane, but it still needs to be at right angles to the way it is now. Further translation with the resultant file doesn't adjust the data. is there a way to georeference the 4 corners rather than just ulx uly lrx lry?
    – mmfl
    Nov 21, 2016 at 9:26
  • You can transform the file to tif and put it in the QGIS georeferencer.
    – AndreJ
    Nov 21, 2016 at 20:14
  • Maybe related: gis.stackexchange.com/questions/185616/…
    – AndreJ
    Nov 21, 2016 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.