如何使用 cartopy & 转换图像里奥克斯阵列...?

发布于 2025-01-16 20:24:41 字数 614 浏览 5 评论 0 原文

我想读取带有 rioxarray (或 rasterio)的图像(带有 georef 信息),并使用 cartopy 和转换来绘制它:

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()

...但我收到错误:

ValueError:预期有一个投影子类。无法处理在imshow中

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

む无字情书 2025-01-23 20:24:41

这是因为 cartopy 仅处理定义为 cartopy.CRS 子类的投影(据我所知,尚不支持通过 wkt-strings 等定义的任意投影)。

但是,我是EOmaps 的开发,它基于 cartopy 但处理直接使用 pyproj 重新投影。
因此,它完全能够使用任意输入投影:

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()

在此处输入图像描述

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()

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文