Reputation: 41
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
Upvotes: 2
Views: 1748
Reputation: 7814
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)
Upvotes: 2