kms
kms

Reputation: 2014

UserWarning: Geometry is in a geographic CRS. Results from 'buffer' are likely incorrect

I am create geopandas DataFrames and create a buffer to be able to do spatial joins. I set the crs for the DataFrame and then proceed to create buffers and encounter the warning then.

df1 = gpd.GeoDataFrame(df1, geometry=gpd.points_from_xy(df1['Long'], df1['Lat']))
# set crs for buffer calculations
df1.geometry.set_crs('EPSG:4326', inplace=True)

df2 = gpd.GeoDataFrame(df2, geometry=gpd.points_from_xy(df2['Long'], df2['Lat']))
# set crs for buffer calculations
df2.geometry.set_crs('EPSG:4326', inplace=True)

# Returns a geoseries of geometries representing all points within a given distance
df1['geometry'] = df2.geometry.buffer(0.001)

User Warning:

/var/folders/d0/gnksqzwn2fn46fjgrkp6045c0000gn/T/ipykernel_5601/4150826928.py:10: UserWarning: Geometry is in a geographic CRS. Results from 'buffer' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.

  df1['geometry'] = df2.geometry.buffer(0.001)

Upvotes: 6

Views: 14445

Answers (1)

Tim
Tim

Reputation: 563

You may need to project the coordinate system. From geodetic coordinates (e.g. 4826) to meters (e.g. 3857) and vice-versa. The calculation of the buffer is usually done in the projected meters system because it takes a distance as an argument. The shapely doc may be useful: http://shapely.readthedocs.io/en/latest/manual.html#object.buffer

Here is an example of what you could do, first you define the coordinate system. Then you do your projection in meters to calculate the buffer. And finally you project back to your original coordinate system.

df2.crs = "epsg:4326" #identical to df2 = df2.set_crs('epsg:4326')
df2 = df2.to_crs(crs=3857) 
df1.geometry = df2.buffer(0.001)
df1 = df1.to_crs(crs=4326) 

Upvotes: 11

Related Questions