Posts

Showing posts with the label gdal

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 file.nc' not recognized as a supported file format. Raster layer Provider is not valid (provider: gdal, URI: file.nc 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.nc 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: gdalinfo file.nc Subdatasets:   SUBDATASET_1_NAME=NETCDF:"FWI.GPM.LATE.v5.Monthly.Defau...

How to convert from kml to GeoJson with python3

To do it, you can import ogr from osgeo from osgeo import ogr def kml2geojson(kml_file):     drv = ogr.GetDriverByName('KML')     kml_ds = drv.Open(kml_file)     for kml_lyr in kml_ds:         for feat in kml_lyr:             print feat.ExportToJson() kml2geojson('/path/to/your.kml') But, if you try to run it, maybe you will see the following error: ImportError: No module named 'osgeo' This means that you need gdal libraries. If you try to install it with pip3 you will see the following: pip3 install gdal ... cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++     extensions/gdal_wrap.cpp:3168:22: fatal error: cpl_port.h: No such file or directory     compilation terminated.     error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 We search which pakage includes cpl_port.h: apt-file search cpl_por...