Skip to content

Instantly share code, notes, and snippets.

@franTarkenton
Last active October 12, 2023 01:18
Show Gist options
  • Save franTarkenton/d1f52901677f5395c731c7cbbf460cd8 to your computer and use it in GitHub Desktop.
Save franTarkenton/d1f52901677f5395c731c7cbbf460cd8 to your computer and use it in GitHub Desktop.
Getting Started wtih GDAL

Installing

Not Easy!

Using Windows Subsystem 4 Linux (WSL):

sudo apt-get install gdal-bin
sudo apt-get install libgdal-dev
sudo apt-get install python3-gdal

Install python bindings with pip

# create virtualenv
python3 -m virtualenv gdal_ve
source gdal_ve/bin/activate
pip install pygdal=="`gdal-config --version`.*"

Other options:

WINDOZE

Bottom line, getting it installed on Windoze is a PAIN

What is GDAL

  • opensource ETL Tool
  • Currently supports around 100 vector formats and 150 raster
  • GDAL = Geospatial Data Abstraction Library, Raster
  • OGR = OpenGIS Simple Features Reference Implementation?? Vector
  • GDAL 2.0 sees GDAL and OGR components integrated together, used to be separate

Using GDAL/OGR with python

Programming flow / object hierarchy

  • Driver (Defines data type, ex, FGDB, shape file, postgis etc)
    • Data Source (Defines source, path, db connection params etc)
      • Layer (A collection of features)
        • Feature (individual row in a table with a geometry)
          • Attributes - tabular goodness
          • Geometry - where?

Read Features from FGDB

comparison of opensource vs esri driver

dataPath = r'./data/BCTS_OPERATING_AREAS_SP.gdb'
# proprietary ESRI driver, read only, requires separate install
#driver = ogr.GetDriverByName("FileGDB")
# opensource driver, use this!
driver = ogr.GetDriverByName("OpenFileGDB")
ds = driver.Open(dsath, 0)


More Info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment