python - 打开街道 map (pyproj)。如何解决语法问题?

标签 python geopandas pyproj contextily

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

enter image description here

最佳答案

关于语法问题,当您重新投影时,警告来自 pyproj。 Geopandas 更改了其文档以反射(reflect)这一点(请参阅 https://github.com/geopandas/geopandas/pull/1101/files#diff-dc9328ce726fd6e58f466f7001f7a50ehttps://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/

相关文章:

python - 为什么使用 cv2.findContours 将 Boudary 检测为轮廓?

python - 从类定义中的列表理解访问类变量

python - 在区域的部分区域添加边框,matplotlib/geopandas

python - 值错误: Attempt to have a second RNNCell use the weights of a variable scope that already has weights

python - PostgreSQL:如何安装 plpythonu 扩展

python-3.6 - 使用 pyinstaller 将 .py 转换为 .exe 后,出现错误 "No module named ' pyproj._datadir'"

python - pyproj - 导入错误 : cannot import name '_datadir'

python - 如何使用 Python 获取 GeoJSON 多边形的面积

python - 属于线列表的连续点(x,y 元组)之间的迭代欧氏距离计算

python - 将一个 GeoPandas 数据框中的每个点链接到另一个数据框中的多边形