我正在尝试添加一些形状文件到一个卡通基础地图。结果发现有些形状文件有用,而另一些不起作用。我在谷歌上搜索了一整天,没有任何运气。你能帮忙吗。 下面是我正在使用的代码。可在此处下载两个形状文件:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.io.img_tiles import OSM
from cartopy.io import shapereader
#%% ======== map paramters =================
map_extent_eastings=(378000,390000)
map_extent_northings=(6427500,6443000)
#%%
plt.subplots(1,1,figsize=(10,10))
ax = plt.axes(projection=ccrs.epsg(28350))
ax.set_extent([map_extent_eastings[0],map_extent_eastings[1],map_extent_northings[0],map_extent_northings[1]],crs=ccrs.epsg(28350))
tiler = OSM()
cur_CRS = tiler.crs
zoom = 8 #12 for the final
ax.add_image(tiler, zoom, interpolation='bilinear' )
#============= Figure out why this deosn't work ===================
### this one doesn't work
ax.add_geometries(shapereader.Reader('data/AdditionalPumping_south_v2_test.shp').geometries(),
ccrs.epsg(28350),facecolor='none',edgecolor='r',linewidth=1.5,zorder=10)
# This one works
ax.add_geometries(shapereader.Reader('data/MAR_locations_v2.shp').geometries(),
ccrs.epsg(28350),facecolor='none',edgecolor='r',linewidth=1.5,zorder=10)
plt.show()
===============================
Github上的Cartopy社区已经找到了解决方案。任何对此感兴趣的人,请参见https://github.com/SciTools/cartopy/issues/1217
我检查了你上传到dropbox上的shapefile。结果是形状文件没有被正确读取。在
当我打印出MAR_locations_v2.shp的记录时,这就是我得到的
当我打印南加泵v2的记录时_测试.shp我明白了
这并不是这个问题的完整答案,但是它回答了为什么你没有得到剧情的部分。您可能希望以不同的方式保存形状文件,以便打印。在
相关问题 更多 >
编程相关推荐