1

How to read netCDF raster data in GRASS or QGIS?

I have a file with this characteristics:

Command: gdalinfo C:\Users\XXXX\gisdata\Test\mb.grd

Output:

Driver: netCDF/Network Common Data Format
Files: C:\Users\XXXX\gisdata\Test\mb.grd
Size is 412, 433
Coordinate System is `'
Origin = (-87.389553008819831,11.262298195006528)
Pixel Size = (0.000778017639680,-0.000768428196547)
Metadata:
  NC_GLOBAL#Conventions=COARDS, CF-1.5
  NC_GLOBAL#description=
    Projection: Geographic
    Grid created by mbgrid
    MB-system Version 5.5.2318
    Run by <gery> on <gery> at <Wed Nov  1 19:56:46 2017>
  NC_GLOBAL#GMT_version=5.2.1 (r15220) [64-bit] [MP]
  NC_GLOBAL#history=mbgrid
  NC_GLOBAL#title=Topography Grid
  x#actual_range={-87.38916399999999,-87.06939875009137}
  x#long_name=Longitude
  y#actual_range={10.929953,11.26191398090825}
  y#long_name=Latitude
  z#actual_range={-4783.08984375,-760.27880859375}
  z#long_name=Topography (m)
  z#_FillValue=1.#QNAN
Corner Coordinates:
Upper Left  ( -87.3895530,  11.2622982) 
Lower Left  ( -87.3895530,  10.9295688) 
Upper Right ( -87.0690097,  11.2622982) 
Lower Right ( -87.0690097,  10.9295688) 
Center      ( -87.2292814,  11.0959335) 
Band 1 Block=412x1 Type=Float32, ColorInterp=Undefined
  NoData Value=nan
  Metadata:
    actual_range={-4783.08984375,-760.27880859375}
    long_name=Topography (m)
    NETCDF_VARNAME=z
    _FillValue=1.#QNAN

My first attemp to read it was with the standard gdal procedure

command: r.in.gdal -o -k input="C:\Users\XXXX\gisdata\Test\mb.grd" outpu\ | | t="mb" memory=300 offset=0 num_digits=0

but it looks to have just zeros, not the z#actual_range={-4783.08984375,-760.27880859375}

Here the r.info map=mb

|----------------------------------------------------------------------------|
 |                                                                            |
 |   Type of Map:  raster               Number of Categories: 0               |
 |   Data Type:    FCELL                                                      |
 |   Rows:         433                                                        |
 |   Columns:      412                                                        |
 |   Total Cells:  178396                                                     |
 |        Projection: Latitude-Longitude                                      |
 |            N: 11:15:44.273502N    S: 10:55:46.447629N   Res: 0:00:02.76634 |
 |            E: 87:04:08.435069W    W: 87:23:22.390832W   Res: 0:00:02.80086 |
 |   Range of data:    min = 0  max = 0                                       |
 |                                                                            |
 |   Data Description:                                                        |
 |    generated by r.in.gdal        

There is a link with the file https://ufile.io/3i2ix and this belongs to this question How to restore a scarp surface grid to calculate material loss

System info:

GRASS version: 7.2.0                                                            
GRASS SVN revision: r70156                                                      
Build date: 2016-12-29                                                          
Build platform: x86_64-w64-mingw32                                              
GDAL: 2.1.2                                                                     
PROJ.4: 4.9.3                                                                   
GEOS: 3.5.0                                                                     
SQLite: 3.14.1                                                                  
Python: 2.7.5                                                                   
wxPython: 2.8.12.1                                                              
Platform: Windows-7-6.1.7601-SP1 (OSGeo4W)  
  • 1
    Change .grd to .nc (for this case, filename becomes mb.nc). Then QGIS reads the file as a Raster (GMT NetCDF Grid Format). – Kazuhito Nov 4 '17 at 14:49
  • @Kazuhito I did so also , but QGIS reads a raster with NaN values. did you tried the file in the link? – Marco Nov 5 '17 at 17:15
  • Yes I have so far tested three options (1) QGIS menu Layer | Add Layer | Add Raster Layer. (2) Through QGIS Browser Panel (both drag&drop to Map window, and right click to add layer) (3) QGIS+GRASS7 r.in.gdal. All worked at my end. I am working in QGIS 2.18.14 (stand alone) on Windows10. – Kazuhito Nov 5 '17 at 18:38
  • ?! What is wrong with my reading then? Did the data move between -4783 and -760? I am trying with qgis 2.18.7 for windows and I cannot update easily. I read something about the gdal compilation, but I do not know how to check what it has in it – Marco Nov 5 '17 at 18:59
  • QGIS 2.18.14 (Win) here is running against GDAL 2.2.2. Your system info says 2.1.2. Could it potentially be the difference? ... ... I don't know. BTW, yes the data range is as you (and gdalinfo) have described. – Kazuhito Nov 5 '17 at 19:18
1

@Kazuhito pointed me to the solution, it was solved with the update of QGIS from 2.18.7 to 2.18.14, which comes with GDAL 2.2.2 and GRASS 7.2.2.

It worked smoothly in both QGIS and GRASS.

r.import input=C:\Users\XXXX\gisdata\Test\mb.grd output=mb -o --overwrite
r.info map=mb                                                         
 +----------------------------------------------------------------------------+
 |                                                                            |
 |   Type of Map:  raster               Number of Categories: 0               |
 |   Data Type:    FCELL                                                      |
 |   Rows:         433                                                        |
 |   Columns:      412                                                        |
 |   Total Cells:  178396                                                     |
 |        Projection: Latitude-Longitude                                      |
 |            N: 11:15:44.273502N    S: 10:55:46.447629N   Res: 0:00:02.76634 |
 |            E: 87:04:08.435069W    W: 87:23:22.390832W   Res: 0:00:02.80086 |
 |   Range of data:    min = -4783.09  max = -760.2788                        |
 |                                                                            |
 |   Data Description:                                                        |
 |    generated by r.in.gdal                                                  |

Your Answer

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

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