Skip to content

Replace gdal/osgeo dependencies with rasterio and geopandas - #38

Merged
mmacferrin merged 2 commits into
mainfrom
remove-gdal-osgeo
Jul 17, 2026
Merged

Replace gdal/osgeo dependencies with rasterio and geopandas#38
mmacferrin merged 2 commits into
mainfrom
remove-gdal-osgeo

Conversation

@mmacferrin

Copy link
Copy Markdown
Collaborator

Closes #21.

The osgeo Python bindings require platform-specific GDAL binaries that are difficult to install, particularly on Windows (see the pip install failure reported in #21). This replaces every gdal, ogr, and osr call with rasterio/geopandas equivalents — both ship binary wheels and were already declared project dependencies.

Changes

  • src/ivert/validate_dem.py — DEMs are opened with rasterio.open; existing geotransform math is preserved unchanged via ds.transform.to_gdal(), which returns the same 6-tuple GDAL ordering. generate_result_geotiff now writes through rasterio, and _export_errors_vector builds a geopandas.GeoDataFrame and calls to_file() instead of the ogr/osr feature-by-feature loop.
  • src/ivert/utils/split_dem.py — the gdal_translate subprocess call (which required the GDAL CLI binaries — the same installability problem) is replaced by a rasterio windowed read/write with identical -srcwin semantics and creation options. Also no longer reads the full raster just to get its shape.
  • src/ivert/utils/create_empty_tiff.py, src/ivert/plot_results_slope_centrality.py — trivial one-spot ports.
  • src/ivert/utils/pyproj_funcs.py — deleted; dead code with zero callers anywhere in the repo.
  • pyproject.tomlgdal removed from dependencies.
  • .github/workflows/publish-to-pypi.yml — the pixi/libgdal-core wrapper on the install-test step existed only to supply GDAL binaries; it and the setup-pixi step are removed.

Verification

  • Exercised generate_result_geotiff, all four error-export formats (tif/gpkg/shp/xyz), and split_dem with the pre-port GDAL code, then re-ran identically after the port: all 63 comparisons match exactly (pixel values, transforms, CRS, nodata, dtypes, point geometries, and attribute values).
  • All ported modules plus ivert.cli import cleanly with osgeo import-blocked, simulating an environment without GDAL.
  • grep -r osgeo src/ returns nothing; all pre-commit hooks pass.

Two known, intentional behavior differences: output GeoTIFFs no longer have band statistics pre-baked into their metadata (GIS software computes these on open), and integer attribute fields in vector exports are written from int32 arrays (identical values and field types).

The osgeo Python bindings require platform-specific GDAL binaries that
are difficult to install, particularly on Windows. Replace all gdal,
ogr, and osr calls with rasterio/geopandas equivalents, which ship
binary wheels and were already project dependencies.

- validate_dem.py: open DEMs with rasterio (geotransform math preserved
  via transform.to_gdal()); write result geotiffs with rasterio; export
  vector errors via geopandas instead of an ogr/osr feature loop.
- split_dem.py: replace the gdal_translate subprocess call with a
  rasterio windowed read/write using the same -srcwin semantics.
- create_empty_tiff.py, plot_results_slope_centrality.py: trivial ports.
- pyproj_funcs.py: delete (dead code, no callers).
- pyproject.toml: drop the gdal dependency.
- publish-to-pypi.yml: remove the pixi/libgdal-core workaround that
  existed only to supply GDAL binaries for the install test.

Outputs verified identical against a GDAL baseline across all export
formats (tif/gpkg/shp/xyz) and split tiles: pixel values, transforms,
CRS, nodata, geometries, and attribute values all match.
The package install test ran on Python 3.14 (python-version: "3.x"),
where fiona -- a transitive dependency via globato -- has no binary
wheel and fails to build from source without GDAL headers. Pin to 3.13,
the newest version with full wheel coverage for the dependency tree.
@mmacferrin

Copy link
Copy Markdown
Collaborator Author

All CI hooks passed except Codacy, which is having persistent issues. We are dropping the Codacy dependency in Issue #28.

@mmacferrin
mmacferrin merged commit 6ef5146 into main Jul 17, 2026
5 of 6 checks passed
@mmacferrin
mmacferrin deleted the remove-gdal-osgeo branch July 17, 2026 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove gdal and osgeo dependencies.

1 participant