2

I have two lists of points (latitudes, longitudes) - locations & events:

locations = [[54.156014, 53.017209], [2.74284, 103.68141], [3.133688, 102.688424], [24.499918, 55.388891], [21.488382, 61.395062], [24.479778, 59.354986], [25.180161, 78.269545], [-31.5796783, -58.5812265]]
events = [[-15.794157,  -47.882529],[33.319392, 44.347046],[26.225653, 50.535556],[50.447336, 30.536875],[50.447336, 30.536875],[50.442721, 30.52179],[50.442721, 30.52179],[-15.794157, -47.882529],[3.848032, 11.502075],[-12.97304, -38.502304],[26.226559, 50.54591],[-34.603684, -58.381559],[32.094771, 20.187911],[48.868472, 2.330211],[-30.032056, -51.208428],[32.887209, 13.191338],[13.767966, 100.534526],[-34.92849, 138.60074],[32.887209, 13.191338],[26.230536, 50.527792],[50.4501, 30.5234],[50.4501, 30.5234],[50.442721, 30.52179],[50.442721, 30.52179],[50.447137, 30.537357],[50.447137, 30.537357],[12.81063, 45.035019],[26.225653, 50.535556],[-12.97304, -38.502304],[26.226559, 50.54591],[35.675888, 139.744858],
[12.813674, 45.034161],[54.156014, 53.017210]]

I would like to check which of the events occurred in the 2 kilometer radius buffer from locations.

If one event occurred in multiple buffers I would like to have this event attached to multiple locations that it occurred in the nearby.

What I have tried: I have converted locations list and events list to dataframes and did following:

locations_gpd = gpd.GeoDataFrame(locations, geometry=gpd.points_from_xy(locations.longitude, locations.lattitude).buffer(2, 16), crs = {'init':'epsg:4326'})

events_gpd = gpd.GeoDataFrame(events, geometry=gpd.points_from_xy(events.longitude, events.latitude), crs = {'init':'epsg:4326'})

intersection = gpd.sjoin(locations_gpd, events_gpd, how='left')

This actually performs the intersection well, but the buffer zone is bigger than 2km (I plotted the results and can see on the map) I cant figure out how to apply correct distance/resolution parameters (2km) in GeoDataFrame.buffer(distance, resolution)

PS. I am beginner with GeoPandas, could you give me a lead how to perform this intersection?

2
1

I think the issue is the you buffer the locations while using the EPSG 4326 projection. This doesn't use meters as the unit so the buffer zones might not all be 2km.

Here I re-project the data to the WGS 84 / Pseudo-Mercator projection. Depending on where you're points are located there might be a more suitable projection also.

locations = [[54.156014, 53.017209], [2.74284, 103.68141], [3.133688, 102.688424], [24.499918, 55.388891], [21.488382, 61.395062], [24.479778, 59.354986], [25.180161, 78.269545], [-31.5796783, -58.5812265]]

events = [[-15.794157,  -47.882529],[33.319392, 44.347046],[26.225653, 50.535556],[50.447336, 30.536875],[50.447336, 30.536875],[50.442721, 30.52179],[50.442721, 30.52179],[-15.794157, -47.882529],[3.848032, 11.502075],[-12.97304, -38.502304],[26.226559, 50.54591],[-34.603684, -58.381559],[32.094771, 20.187911],[48.868472, 2.330211],[-30.032056, -51.208428],[32.887209, 13.191338],[13.767966, 100.534526],[-34.92849, 138.60074],[32.887209, 13.191338],[26.230536, 50.527792],[50.4501, 30.5234],[50.4501, 30.5234],[50.442721, 30.52179],[50.442721, 30.52179],[50.447137, 30.537357],[50.447137, 30.537357],[12.81063, 45.035019],[26.225653, 50.535556],[-12.97304, -38.502304],[26.226559, 50.54591],[35.675888, 139.744858],[12.813674, 45.034161],[54.156014, 53.017210]]

dfLocations = pd.DataFrame(columns = ['longitude', 'latitude'], data = locations)
dfEvents = pd.DataFrame(columns = ['longitude', 'longitude'] , data = events)
gdfLocations = gpd.GeoDataFrame(dfLocations, geometry=gpd.points_from_xy(dfLocations.longitude, dfLocations.latitude), crs = {'init':'epsg:4326'})
gdfEvents = gpd.GeoDataFrame(dfEvents, geometry=gpd.points_from_xy(dfEvents.longitude, dfEvents.latitude), crs = {'init':'epsg:4326'})

# Now reproject to a crs using meters
gdfLocations = gdfLocations.to_crs({'init':'epsg:3857'})
gdfEvents = gdfEvents.to_crs({'init':'epsg:3857'})

# Buffer and join
gdfLocations['geometry'] = gdfLocations['geometry'].buffer(2000)
intersection = gpd.sjoin(gdfLocations, gdfEvents, how='left')

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