Open Street Map (pyproj). How to solve syntax issue?

余生颓废 提交于 2021-02-19 05:41:50

问题


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.

There's not much I could find on google. What is this and how to fix it?

See code snippet below:

##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()


回答1:


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:

  • setting by hand

my_geoseries.crs = "EPSG:4326"

  • reprojecting

world = world.to_crs("EPSG:3395") # world.to_crs(epsg=3395) would also work

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")

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.



来源:https://stackoverflow.com/questions/59596835/open-street-map-pyproj-how-to-solve-syntax-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!