-2

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)


/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)
1

2 Answers 2

3

You need to understand Geographic coordinate systems and Projected coordinate systems.

Geographic CRS(such as 'EPSG:4326') is not suitable for measuring distance. Converting degree to distance requires additional work. Use a different coordinate as the warning message shows. The coordinates you usually use depend on the area you want to analyze.It will be common to use a coordinate system based on UTM.

4
  • We'll mostly be calculating distance within the United States.
    – kms
    May 1 at 16:58
  • And typically distance within 50m as we're looking for points in close proximity.
    – kms
    May 1 at 17:04
  • 2
    @kms I'm not sure what you mean. I'd like to recommend a specific coordinate system, but I don't know much about the United States. I searched and it seems that one of the coordinates of EPSG 26910 to 26919 can be used. Transform your coordinate system using gpd.GeoDataFrame.to_crs('EPSG:26910') and run the buffer.
    – Urban87
    May 2 at 0:42
  • Like what different coordinate system?
    – ifly6
    yesterday
2

Reproject your data to a coordinate system with meters as units using to_crs. Right now you are buffering with a distance of 0.001 degrees which means the distance will not be the same depending on where on earth you are.

df1 = gpd.GeoDataFrame(df1, geometry=gpd.points_from_xy(df1['Long'], df1['Lat']))
df1.geometry.set_crs('EPSG:4326', inplace=True)
df1['geometry'] = df1.geometry.to_crs("epsg:32633") #Change 32633 to a coordinate system which suits your data/requirements

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.