Showing posts from April, 2019

An example to read a NetCDF file with Python

For this post I'm going to use this post and the following files as reference.

NetCDF files: Source code:

If you want to see content you can try with Integrated Data Viewer (IDV).
To download just execute:


Now, execute the python example file:
You probably will get the following errors:
ImportError: No module named functools_lru_cache ImportError: No module named basemap
You can install modules from pip, but in my case I can't solve the issue. To fix it install them from apt as follows:
sudo apt install python-backports.functools-lru-cache  python-mpltoolkits.basemap
Enjoy it!

How to convert a NetCDF file TIFF to import in QGIS 3.x

NetCDF is a data format and library designed to store multidimensional arrays of scientific data.
If you try to load it in Qgis, probably you will get the following message:

Invalid Layer: GDAL provider Cannot open GDAL dataset' not recognized as a supported file format. Raster layer Provider is not valid (provider: gdal, URI:

In QGIS 2.x you can use NetCDF plugin to load the layer, but it not exist yet in QGIS 3.x
To import the layer you need to convert the .nc file to another like .tiff

To do it, you can use gdal toolkit as follows:

gdal_translate file.tiff 
Warning 1: No UNIDATA NC_GLOBAL:Conventions attribute
Input file contains subdatasets. Please, select one of them for reading.

This issue is because the .nc contains subdatasets and you must specify only one.

To see the subdatasets names just execute the following sentence in your terminal:



ERROR (internal_error): Operation on mixed SRID geometries

I got this issue when I tried to optimize a pgsql code with postgis.
See the following example that works with if you join it with other sentence:

SELECT ST_SetSRID(ST_MakeLine(ST_MakePoint(4.51, 52.2), ST_MakePoint(23.42, 37.58)),4326)

But, if you only replace ST_MakePoint by a geom selection you will have an error:

SELECT ST_SetSRID(ST_MakeLine( (select point from nodes where name='3'), (select point from nodes where name='20')) ,4326)

ERROR: Operation on mixed SRID geometries SQL state: XX000

To solve it just delete ST_SetSRID as follows:

SELECT ST_MakeLine( (select point from nodes where name='3'), (select point from nodes where name='20'))

Now it works
Enjoy it!