Adds CRS.geodetic_crs property#3218
Conversation
* inspired by pyproj's .geodetic_crs function to return the corresponding base geographic CRS for a given CRS * helpful for projections that may not use common geographic CRSs
sgillies
left a comment
There was a problem hiding this comment.
@AndrewAnnex I'm in favor. I think to_geodetic() is fine.
|
test failure looks unrelated to changes made in this PR and occur in tests/test_warpedvrt.py |
|
I am a little late to the party here, but figured this insight may be helpful when deciding on naming in
from pyproj.crs import GeographicCRS, ProjectedCRS
from pyproj.crs.coordinate_operation import UTMConversion
from pyproj.crs.datum import CustomDatum, CustomEllipsoid
ell = CustomEllipsoid(semi_major_axis=6378137, semi_minor_axis=6356752)
cd = CustomDatum(ellipsoid=ell, prime_meridian="Lisbon")
proj_crs = ProjectedCRS(
conversion=UTMConversion(14), geodetic_crs=GeographicCRS(datum=cd)
)In this example, calling |
|
Also, |
|
@snowman2 That makes sense regarding the naming. I wanted to keep the scope of this PR limited to make it easier to merge, but we could update the pr to go the route of Pyproj to make the api more equivalent. But it would require the similar caching mechanism. But it is unclear given the prior approval from @sgillies if that's the desired outcome for this PR. |
|
The information above was for informational purposes for decision making and design considerations only. Caching is not a requirement, just sharing so you are aware. |
|
@snowman2 that appeals to me, and it's good to have Rasterio and Pyproj agree, even though I think Rasterio can be less complete than Pyproj (there's a lot of other stuff to be concerned about). For example, Rasterio doesn't need (as far as I can tell) to be able to create generic projected CRS, passing a geodetic CRS to the constructor. Rasterio really only needs to work with standardized CRS. Engineering CRS might be an exception to this. @AndrewAnnex are you okay with making this an attribute instead of a method? |
|
@sgillies yep I am happy to implement that, I'll get to it later today or tomorrow |
|
okay I think this does what's needed but happy to respond to feedback. I'd also wonder if there is a good example projected CRS that doesn't have a resolvable geodetic CRS to test that case but that might require making a projection with a custom geographic crs that doesn't compare to anything... something I'll think more about |
sgillies
left a comment
There was a problem hiding this comment.
@AndrewAnnex I'm suggesting a pattern for this kind of property that we use elsewhere in Rasterio.
@AndrewAnnex this is an interesting question. Let me know what you discover. |
sgillies
left a comment
There was a problem hiding this comment.
@AndrewAnnex thanks for the contribution and bearing with me. I made two suggestions that you can commit if you like.
Co-authored-by: Sean Gillies <[email protected]>
Co-authored-by: Sean Gillies <[email protected]>
|
I forgot to ask "what is the geodetic CRS corresponding to a geodetic CRS?" but it seems that GDAL and PROJ do the least surprising thing 👍 >>> from rasterio.crs import CRS
>>> CRS.from_epsg(32618).geodetic_crs
CRS.from_wkt('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]')
>>> CRS.from_epsg(32618).geodetic_crs.geodetic_crs
CRS.from_wkt('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]') |
Following a discussion on the rasterio groups.io email list,
This PR adds a new function
.to_geodeticthat is inspired by pyproj's.geodetic_crsfunction to return the corresponding base geographic CRS for a given CRS. This is helpful for projections that may not use common geographic CRSs and for cases when you want to know what geographic CRS to use for vector features that minimizes the work needed to get to projected coordinates or vice versa.I went with the name
to_geodeticfor the moment as it is returning a new object that is transformed from the parent object, and reflects the intent imho better than.geodetic_crswhich reads more as a property of the CRS, but as a new object is created... Anyways I don't hold a strong desire here on the name of the function.geodeticis retained because of this heritage, the vocabulary here is majorly overloaded but maybeto_geographicwould be better here? Happy to look into this more. It could also make sense to just keep it aligned to pyproj to maintain compatibility better.