'how to transform image w/ cartopy & rioxarray ...?
I'd like to read an image (w/ georef info) w/ rioxarray (or rasterio) and plot it w/ cartopy w/ a transform :
import rioxarray
fn2 = 'https://eoimages.gsfc.nasa.gov/images/imagerecords/144000/144898/BlackMarble_2016_01deg_geo.tif'
da0 = rioxarray.open_rasterio(fn2)
import matplotlib.pyplot as plt
fig0 = plt.figure()
import cartopy
proj0 = cartopy.crs.LambertConformal(-100)
ax0 = fig0.add_subplot(111, projection = proj0)
ax0.coastlines()
ax0.gridlines()
da0.plot.imshow(ax = ax0, transform = da0.rio.crs)
plt.show()
... but I get an error :
ValueError: Expected a projection subclass. Cannot handle a <class 'rasterio.crs.CRS'> in imshow
Solution 1:[1]
This is because cartopy only deals with projections defined as subclasses of cartopy.CRS (as far as i know there's not yet a support for arbitrary projections defined via wkt-strings etc.)
However, I'm the dev of EOmaps which is based on cartopy but handles re-projections directly with pyproj.
As such it is perfectly capable of using arbitrary input projections:
from eomaps import Maps
import rioxarray
fn2 = 'https://eoimages.gsfc.nasa.gov/images/imagerecords/144000/144898/BlackMarble_2016_01deg_geo.tif'
da0 = rioxarray.open_rasterio(fn2)
# EOmaps expects a xar.Dataset not a xar.DataArray
da0 = da0.to_dataset(name="blackmarble")
m = Maps(Maps.CRS.LambertConformal(-100))
m.new_layer_from_file.GeoTIFF(da0, set_extent=False)
m.ax.gridlines()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | raphael |

