-
Notifications
You must be signed in to change notification settings - Fork 366
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
How to mediate between cartopy vs. rasterio CRS? #923
Comments
(or I guess more generally, what's the right way to create a cartopy CRS using a rasterio / geopandas CRS object?) |
ping |
Changed the title because really that's the main goal here - I'm trying to read in TIFF files with either rasterio or geopandas (which reads in a CRS as a rasterio CRS), and I'd like to do plotting with cartopy if possible. However I can't for the life of me figure out how to turn the rasterio CRS into something I can use with cartopy... |
I don't know much about it really, but since your currently alone on this... the |
Hmm, interesting. Thanks for raising @choldgraf. The CRS object is indeed documented, and available at http://scitools.org.uk/cartopy/docs/v0.15/crs/index.html#cartopy.crs.CRS. Be aware though, you are constructing a CRS - not a projection. That means you aren't able to produce a map with it, and you will find a number of places when CRSes can't be used directly as the coordinate system of data (e.g. imshow, but plot & text are fine). Given the above caveat, and the fact that I needed to make a code change to get it to work, I can't recommend creating CRSes directly in this way. We definitely want to be able to create projections from proj4 strings, but we aren't there yet. #153 relates. Perhaps we need to add some detail to the docs to state that it is not recommended to create CRSes directly... FWIW, the changes I needed to make were:
And I was then able to construct a CRS with:
|
I'd like to add on to this that this is something I'd like to make easier with the xarray library and other projection-heavy libraries (satpy, metpy, etc). I started pydata/xarray#2288 to hopefully find a way to easily convert between different libraries implementations. I haven't had much time to work on it but I do have a geoxarray package that I started (https://github.com/geoxarray/geoxarray) that in the future will probably use the pycrs library: https://github.com/karimbahgat/PyCRS I was hoping to add some conversion functions to pycrs for converting to/from rasterio and cartopy CRS objects. CC'ing @karimbahgat |
https://pyproj4.github.io/pyproj/latest/crs_compatibility.html The latest versions of geopandas now use the import rasterio
import rasterio.crs
from cartopy.crs import Projection
with rasterio.Env(OSR_WKT_FORMAT="WKT2_2018"):
rio_crs = rasterio.crs.CRS.from_epsg(32613)
cart_crs = Projection(rio_crs) |
I'm trying to create a CRS from a geopandas CRS, and I'm getting a weird error:
As an example:
(I know it's using a string to create the CRS but it feels a bit like the
globe
error is a bug which is why I'm posting this, since IIRC that's an optional parameter)The text was updated successfully, but these errors were encountered: