Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ RasterioRasterizer for burning vector shapes to xarray grids #32

Closed
wants to merge 2 commits into from

Conversation

weiji14
Copy link
Owner

@weiji14 weiji14 commented Jul 24, 2022

An iterable-style DataPipe for turning vector geometries into raster images! Uses rasterio to do the rasterization.

Preview at https://zen3geo--32.org.readthedocs.build/en/32/api.html#zen3geo.datapipes.RasterioRasterizer

Note that I had thought about using a vendored version of rasterio.features.rasterize from another library. These are some bullet points:

Alternatively, rasterization can also be done using datashader which is super fast as it uses numba (see e.g. code snippet at https://github.com/weiji14/deepicedrain/blob/41917ea515edbe548975e2a25c25ff55c6eb4b1a/deepicedrain/spatiotemporal.py#L109-L133). However, on the dependencies front:

That said, the turning point to switch to datashader-based rasterization might be when shapely 2.0 gets released and matures enough to the point that the geospatial vector Python ecosystem starts using it.

TODO:

  • Initial implementation of RasterioRasterizerIterDataPipe
  • Add unit test and enhancement to pass xarray.DataArray inputs to out parameter in rasterio.features.rasterize
  • Think about refactoring PyogrioReader to not return tuples of (filename, dataobj) (maybe do in separate PR)

An iterable-style DataPipe for turning vector geometries into raster images! Uses rasterio to do the rasterization. Included a doctest and a minimal unit test for geopandas.GeoSeries to numpy.ndarray. Added a new section in the API docs and intersphinx mappings for numpy and shapely.
@weiji14 weiji14 added the feature New feature or request label Jul 24, 2022
@weiji14 weiji14 added this to the 0.3.0 milestone Jul 24, 2022
@weiji14 weiji14 self-assigned this Jul 24, 2022
@weiji14 weiji14 modified the milestones: 0.4.0, 0.3.0 Jul 24, 2022
Convenient but complicated way of rasterizing vector data into a template xarray.DataArray. The vector and raster IterDataPipe objects are Zipped, with the vector IterDataPipe being broadcast/repeated to match the length of the raster IterDataPipe. Affine transformation is obtained directly from xarray.Datarray via the `.rio.transform()` accessor property whenever possible. Automatic reprojection to the xarray.DataArray's coordinate reference system is done if needed (and assuming both have a `crs` attribute). The unit test feels like the length of an integration test, but it captures the key functionalities needed and uses a real-ish dataset.
@weiji14 weiji14 changed the title ✨ RasterioRasterizerIterDataPipe for rasterizing vector shapes ✨ RasterioRasterizer for rasterizing vector shapes to xarray grids Jul 25, 2022
@weiji14 weiji14 changed the title ✨ RasterioRasterizer for rasterizing vector shapes to xarray grids ✨ RasterioRasterizer for burning vector shapes to xarray grids Jul 25, 2022
@weiji14
Copy link
Owner Author

weiji14 commented Aug 14, 2022

Closing as superseded by datashader-based method #34 and #35 which offers a faster and more customizable (albeit more steps) way of performing rasterization.

@weiji14 weiji14 closed this Aug 14, 2022
@weiji14 weiji14 deleted the rasterio/rasterize branch August 14, 2022 17:32
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant