GDAL/OGR primer

Author

Paul van Genuchten

Published

January 5, 2023

OGR/GDAL is a swiss army knife for spatial data. It can read u multitude of grid and vector formats and interact with OGC services. The tool includes 2 clusters of scripts:

Installation

GDAL exersize

  • Get details of a gridded dataset
gdalinfo https://files.isric.org/soilgrids/latest/data/bdod/bdod_0-5cm_mean.vrt
  • Get details of a geojson file
ogrinfo https://github.com/gregoiredavid/france-geojson/raw/master/cantons-avec-outre-mer.geojson
  • Convert geojson to shapefile
ogr2ogr cantons.shp https://github.com/gregoiredavid/france-geojson/raw/master/cantons-avec-outre-mer.geojson

GML Application Schema

In 2017 a large work on GDAL introduced support for GML Application Schema. GDAL will read the schema of the xml and generate a relational database schema required to store the data. Verify that the build of GDAL includes GMLAS, it needs a special library XERCES

  • Convert a gml file to geopackage
ogr2ogr -f GPKG test.gpkg GMLAS:/path/to/the.gml
  • Use DBeaver or similar to evaluate the contents of the GeoPackage

GDAL and Python

GDAL includes python bindings, but many prefer the Fiona and Rasterio library, which do the same in a more pythonic way.

GDAL and R

RGDAL and sf provide bindings to GDAL within R.

Read more