Skip to content

improved support of CRS and projection operations

King, Jonathan M requested to merge ghsc/users/jking/pfdf:proj into main

Summary

This merge request migrates the codebase to use pyproj.CRS objects to manage CRS operations. It also adds two spatial metadata classes to further support operations between CRSs.

Notes

I doubt the Gitlab UI will be useful for this one, so here are the important changes.

Projection Subpackage

This is the core of this update, as the modules in this subpackage provide the machinery for spatial conversions. The modules are as follows:

  • _crs: Includes some utility functions for working with pyproj and pyproj.CRS objects. The most important are the functions that convert to/from CRS units and meters
  • transform: A class to represent Raster affine transforms
  • bbox: A class to represent Raster bounding boxes
  • _locator: Abstract base class for the Transform and BoundingBox classes. Provides a few misc shared utility methods

Changes to Raster

from_points/from_polygons: These commands now allow you to specify resolution in meters. They also include a "bounds" option, which lets you build a raster from a subset of features in a shapefile. (The latter addition is intended to solve the issue of the large-scale US-Soils KF-factor data taking forever to load).

reproject/clip/buffer: The functionality of these commands has not changed. However, they now use the Transform and BoundingBox classes to support more intelligent spatial preprocessing.

Added a number of spatial properties - basically just returns properties from the underlying Transform and BoundingBox objects.

_utils.features

Not much new here, but I wrapped a bunch of existing utilities in a context manager to help improve the processing of vector feature files (i.e. the KF factors). Feel free to have a look, but again most of this already existed.

Changes to Segments

Segments.init: Now allows you to specify a maximum length in meters

Segments.lengths: Returns the length of each stream segment, optionally in meters

area/burned_area/developed_area: Now include an option to return catchment areas in square kilometers

Unimportant Changes

You'll see a bunch of functions removed from Raster, and a bunch of new functions in the _utils subpackage. Also the _utils.validate module has been replaced with a _validate subpackage. Nothing much has actually changed here, I just did some reorganizing to help manage the larger files.

Merge request reports