打开街道地图(pyproj).如何解决语法问题? [英] Open Street Map (pyproj). How to solve syntax issue?
问题描述
使用pyproj可视化开放的街道地图并出现以下错误:
Using pyproj for visualizing open street map and getting the following error:
> 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))
程序运行,但会弹出空白地图.
The program runs but spits out a map that is blank.
我在Google上找不到很多东西.这是什么以及如何解决?
There's not much I could find on google. What is this and how to fix it?
请参见下面的代码段
##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已更改其文档以反映这一点(请参见 https://github.com/geopandas/geopandas/pull/1101/files#diff-dc9328ce726fd6e58f466f7001f7a50e 和 https://github.com/geopandas/geopandas/blob/31b264fabb88367a63823da107c764ccec4d3e8f/doc/source/projections.rst )和建议:
Concerning the syntax issue, the warning comes from pyproj, when you reproject. Geopandas has changed its docs to reflect that (see https://github.com/geopandas/geopandas/pull/1101/files#diff-dc9328ce726fd6e58f466f7001f7a50e and https://github.com/geopandas/geopandas/blob/31b264fabb88367a63823da107c764ccec4d3e8f/doc/source/projections.rst) and advices:
- 手动设置
my_geoseries.crs ="EPSG:4326"
my_geoseries.crs = "EPSG:4326"
- 重新投影
world = world.to_crs("EPSG:3395")#world.to_crs(epsg = 3395)也会起作用
world = world.to_crs("EPSG:3395") # world.to_crs(epsg=3395) would also work
注意: world.to_crs(epsg = 3395)
确实可以工作,但是仍然会发出警告(由于 fiona的
在内部被调用,但仍使用 from_espg
函数.crs {'init':...
).如果您不希望出现警告,则:
Note: the world.to_crs(epsg=3395)
will indeed work, but it will still issue a warning (because of the from_espg
function of fiona.crs
that gets called internally and still uses the {'init':...
). If you want no warnings:
new_df = gpd.GeoDataFrame(new_df)
new_df.crs = "EPSG:4326" # set it by hand
new_df = new_df.to_crs("EPSG:3857")
但是,这不应该,并且可能不是地图空白的原因.不知道您的实际 new_df
很难说,但是尝试使用Geopandas数据集( naturalearth_lowres
)的df尝试您的代码,似乎可以正常工作.缩放,建议您在不使用 zoom = 15
参数的情况下调用 ctx.add_basemap
(默认值为 zoom =自动"
),然后查看.
However, this should not be, and probably is not the reason why your map is blank. Without knowing your actual new_df
is hard to tell, but trying your code with a df from geopandas datasets(naturalearth_lowres
) it seems to work fine.. having had some issues with the zoom, i'd suggest that you call the ctx.add_basemap
without the zoom=15
argument (the default is zoom="auto"
) and see.
这篇关于打开街道地图(pyproj).如何解决语法问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!