3

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

enter image description here

RageAgainstheMachine
  • 901
  • 2
  • 11
  • 28

1 Answers1

2

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.

adatzer
  • 556
  • 1
  • 4
  • 6
  • 1
    Changed the syntax to `new_df.crs = "EPSG:4326"` in my code, but still get the FutureWarning. The `from_espg` function of `fiona.crs` is indeed changing the crs string to `{'init': ...}` format. It seems like there won't be any changes in the new version of Fiona (2.0 dev) regarding the `from_espg` behavior. Is there any way to silence this warning or should we wait for Geopandas update? – Tim Nikitin Jan 21 '20 at 13:42
  • the warning comes when you re-project, not from just setting the crs, so check also how you apply the `to_crs` method later on. Fiona's `from_epsg` will get called if you apply it like this: `new_df.to_crs(epsg=xxxx)` (because you provide the epsg argument). So, you need *both* to set the `.crs` like you do *and* also apply the `.to_crs` like in the answer above. If i do *both* like this i get no warning (pyproj v2.4.2, geopandas v0.6.2). Concerning updates and future versions, i am not involved, so i don't know what to expect. – adatzer Jan 22 '20 at 07:02
  • thanks for clarification. in my case `new_df.to_crs(epsg=xxxx)` is being internally called by `folium.GeoJson()` with only epsg passed and no crs. – Tim Nikitin Jan 22 '20 at 08:43