使用 pyproj 可视化开放街道 map 并收到以下错误:
> AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyproj\crs.py:77:
> FutureWarning: '+init=<authority>:<code>' syntax is deprecated.
> '<authority>:<code>' is the preferred initialization method. return
> _prepare_from_string(" ".join(pjargs))
程序运行,但输出的 map 是空白的。
我在谷歌上找不到太多东西。这是什么以及如何解决它?
请参阅下面的代码片段:
##Create map
crs = {'init': 'epsg:4326'}
new_df = gpd.GeoDataFrame(new_df, crs=crs)
#Contextly
new_df = new_df.to_crs(epsg=3857)
##Plot
variable = 'All' #set a variable that will call column
fig, ax = plt.subplots(1, figsize=(50, 50)) #create figure and axes for Matplotlib
ox = new_df.plot(column=variable, cmap='viridis', linewidth=0.3, ax=ax, edgecolor='0.8',alpha=0.5,scheme='equal_interval',k=10,legend=True,legend_kwds={'loc': 'lower left'})
##ADD BASEMAP
ctx.add_basemap(ox,zoom=15)
#Remove the axis
ox.set_axis_off()
##Save Map
plt.savefig('Latest_Map.png')
##Show Map
plt.show()
最佳答案
关于语法问题,当您重新投影时,警告来自 pyproj。 Geopandas 更改了其文档以反射(reflect)这一点(请参阅 https://github.com/geopandas/geopandas/pull/1101/files#diff-dc9328ce726fd6e58f466f7001f7a50e 和 https://github.com/geopandas/geopandas/blob/31b264fabb88367a63823da107c764ccec4d3e8f/doc/source/projections.rst )和建议:
- 手动设置
my_geoseries.crs = "EPSG:4326"
- 重新投影
world = world.to_crs("EPSG:3395") # world.to_crs(epsg=3395) would also work
注意:world.to_crs(epsg=3395)
确实可以工作,但它仍然会发出警告(因为 fiona 的
在内部调用并仍然使用 from_espg
函数.crs{'init':...
)。如果您不想收到警告:
new_df = gpd.GeoDataFrame(new_df)
new_df.crs = "EPSG:4326" # set it by hand
new_df = new_df.to_crs("EPSG:3857")
但是,这不应该,也可能不是您的 map 为空白的原因。在不知道你的实际 new_df
的情况下很难判断,但是使用 geopandas 数据集(naturalearth_lowres
)中的 df 尝试你的代码似乎工作得很好..遇到了一些问题缩放,我建议您调用 ctx.add_basemap
而不 zoom=15
参数(默认为 zoom="自动”
)并查看。
关于python - 打开街道 map (pyproj)。如何解决语法问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59596835/