我认为您可能希望将数据读取到numpy.ndarray 并使用ax.imshow 绘制它,其中ax 是您的cartopy.GeoAxes(因为您已经拥有它)。我在下面提供了一个例子来说明我的意思。
为了这个例子,我截取了一小块 Landsat 地表温度和一些农田。让他们上这个drive link。
注意字段位于 WGS 84 (epsg 4326) 中,Landsat 图像位于 UTM Zone 12 (epsg 32612),我希望我的地图采用 Lambert Conformal Conic。 Cartopy 让这一切变得简单。
import numpy as np
import cartopy.crs as ccrs
from cartopy.io.shapereader import Reader
from cartopy.feature import ShapelyFeature
import rasterio
import matplotlib.pyplot as plt
def cartopy_example(raster, shapefile):
with rasterio.open(raster, 'r') as src:
raster_crs = src.crs
left, bottom, right, top = src.bounds
landsat = src.read()[0, :, :]
landsat = np.ma.masked_where(landsat <= 0,
landsat,
copy=True)
landsat = (landsat - np.min(landsat)) / (np.max(landsat) - np.min(landsat))
proj = ccrs.LambertConformal(central_latitude=40,
central_longitude=-110)
fig = plt.figure(figsize=(20, 16))
ax = plt.axes(projection=proj)
ax.set_extent([-110.8, -110.4, 45.3, 45.6], crs=ccrs.PlateCarree())
shape_feature = ShapelyFeature(Reader(shapefile).geometries(),
ccrs.PlateCarree(), edgecolor='blue')
ax.add_feature(shape_feature, facecolor='none')
ax.imshow(landsat, transform=ccrs.UTM(raster_crs['zone']),
cmap='inferno',
extent=(left, right, bottom, top))
plt.savefig('surface_temp.png')
feature_source = 'fields.shp'
raster_source = 'surface_temperature_32612.tif'
cartopy_example(raster_source, feature_source)
使用 Cartopy 的诀窍是记住为您的坐标区对象使用 projection 关键字,因为这会在您选择的良好投影中呈现地图(在我的例子中是 LCC)。使用 transform 关键字指明您的数据所在的投影系统,以便 Cartopy 知道如何渲染它。