我有两个 shapefile。一个是点特征 shapefile,名为“point.shp”,另一个是多边形 shapefile,名为“polygon.shp”。两者我都想使用 cartopy 添加到地图中。我设法添加了“polygon.shp”,但“point.shp”失败了。
这是我的代码:
import matplotlib.pyplot as plt
from cartopy import crs
from cartopy.io.shapereader import Reader
from cartopy.feature import ShapelyFeature
ax = plt.axes(projection=crs.PlateCarree())
# add the polygon file, worked
ax.add_geometries(Reader("polygon.shp").geometries(), crs.PlateCarree(), facecolor='w')
# or(also worked):
ax.add_feature(ShapelyFeature(Reader("polygon.shp").geometries(), crs.PlateCarree(), facecolor='r'))
# but these two ways both failed with the "point.shp"
ax.add_geometries(Reader("point.shp").geometries(), crs.PlateCarree())
# or, this doesn't work neither:
ax.add_feature(ShapelyFeature(Reader("polygon.shp").geometries(), crs.PlateCarree(), facecolor='r'))
有谁知道如何做到这一点,或者为什么不检索所有点的 x、y 坐标然后绘制它们?
并且使用坐标(x,y 值),ax.plot()
可以工作,但ax.scatter()
失败,为什么?
谢谢