1

I get this error: FutureWarning: '+init=:' syntax is deprecated. ':' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 return _prepare_from_string(" ".join(pjargs))

I crawled data of US cities from a website with google maps embedded. My data did not have crs, so I did research and found out that the epsg from google maps is 3857. So I set it to 3857 with

gdf.crs = {'init': 'epsg:3857'}

In the end I want to create a map of the USA with the cities marked in it. I know how to do this. The map that I have is in epsg:4269. Thats why I changed the crs of the data with:

gdf = gdf.to_crs({'init': 'epsg:4269'})

When I then create the excel file with:

points_within = gp.sjoin(gdf, US, op='within')
writer = pd.ExcelWriter('locationsUS3.xlsx', engine='xlsxwriter') 
points_within.to_excel(writer, sheet_name='Sheet1', index=False)  
writer.save()

the excel file is empty.

It is not when I don't do the gdf = gdf.to_crs({'init': 'epsg:4269'}) step,, but then I get a 'UserWarning: CRS of frames being joined does not match!' error

So what does this FutureWarning error describe and how can I solve this respectively how do I get my data in this excel file?

Thanks for helping me out here!

PS: 'US' is the data from the USA

petezurich
  • 9,280
  • 9
  • 43
  • 57
Kamel
  • 141
  • 1
  • 9

1 Answers1

2

Your issue has two parts.

1) FutureWarning error tells you, that you should not use {'init': 'epsg:3857'} but some other way of CRS specification. It can be just 'epsg:3857' or even 3857 would do.

2) The reason why your excel is empty if you do to_crs reprojection and is not if you don't is that your US and gdf GeoDataFrames are in the same projection in the beginning. You just assigned incorrect one in gdf.crs = {'init': 'epsg:3857'}. It seems that your code should look like this:

gdf.crs = 'epsg:4269'  # assign correct CRS in the correct format here

points_within = gp.sjoin(gdf, US, op='within')
writer = pd.ExcelWriter('locationsUS3.xlsx', engine='xlsxwriter') 
points_within.to_excel(writer, sheet_name='Sheet1', index=False)
martinfleis
  • 7,124
  • 2
  • 22
  • 30
  • I always check with `print(gdf.crs)` what I am doing. When I do `gdf.crs = 'epsg:4269' I get `epsg:4269` and when I do `gdf = 4269` I get `4269` and both ends with the error: UserWarning: CRS of frames being joined does not match!(epsg:4269 != {'init': 'epsg:4269'}) Only with `print(gdf.crs = {'init': 'epsg:4269'}` I get not this error, but the FutureWarning... – Kamel Jun 18 '20 at 17:45
  • Are you using the recent version of GeoPandas? This should not happen. – martinfleis Jun 18 '20 at 18:47
  • I had 0.6.1, now I have 0.7.0. Now it works! One question about your suggested code: why do I not need to start with `gdf.crs = 'epsg:3857'`? My source is google maps, so I thought I need to tell the program that the data have to be epsg:3857 before I convert it to epsg:4269? Can I skip this step without a loss of accuracy? Don't I have to use `gdf = gdf.to_crs('epsg:4269')`? – Kamel Jun 18 '20 at 19:55
  • That comment might not be accurate, I was assuming that you have 0.7.0, which behaves differently. Google Maps show lat/lon coordinates don't they? In that case, you should assign epsg:4326 and then reproject to 4269. – martinfleis Jun 18 '20 at 19:59
  • Did it. It worked. Where do you have the 4326 from? I now also have a new error: RuntimeWarning: invalid value encountered in ? (vectorized) outputs = ufunc(*inputs) what can this '?' be? – Kamel Jun 18 '20 at 20:10
  • 4326 is epsg code for World Geodetic System, i.e. lat lon coordinates. Not sure about the warning. – martinfleis Jun 18 '20 at 20:22