typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

[rasterio] `pyproj.CRS` typing

Open jack-volantautonomy opened this issue 4 months ago • 4 comments

As far as I'm aware, all methods that take a CRSInput should be able to take pyproj.CRS so this type should be added to the TypeAlias. Is there any objections, limitations, or considerations before I take a look into adding this @thomas-maschler ?

I raise this as our codebase supplies a few differernt rasterio methods we use with a pyproj.CRS, and now these get flagged by our linting tools as invalid argument types. Methods we use with pyproj.CRS and work include:

  • rasterio.warp.transform_bounds
  • rasterio.warp.reproject
  • rasterio.io.MemoryFile.open

jack-volantautonomy avatar Aug 03 '26 08:08 jack-volantautonomy

I have no experience with the rasterio package, but maybe the CRSInput type should be extended according to what is accepted by CRS.from_user_input?

https://github.com/rasterio/rasterio/blob/5044f0c8cd08655c63c8b2e452618254c15d8f29/rasterio/crs.pyx#L816

srittau avatar Aug 03 '26 10:08 srittau

Last thing I recall is that they have similar features but are not the same

I am currently traveling and don't have access for my keyboard to verify. I can check once back in two weeks.

thomas-maschler avatar Aug 03 '26 11:08 thomas-maschler

@jack-volantautonomy I looked into this. pyproj is not part of the dependency tree. rasterio converts the foreign CRS type into rasterio.CRS using CRS.from_user_input. This will work for all objects that expose a to_wkt method, not just pyproj.CRS. In my PR I added a protocol to capture this, similar to what we already have for geometries with a geo_interface.

thomas-maschler avatar Aug 24 '26 18:08 thomas-maschler

Have reviewed the PR and approved. Nice work.

jack-volantautonomy avatar Aug 25 '26 16:08 jack-volantautonomy