I have a GeoDataframe that contains thousands of points with a corresponding timestamp (milliseconds), which is an amalgamation of many gps trajectories.
I must check the distance between each point and its neighbors. If their geometries are the same or nearby (e.g. within 20 metres), delete all but the most recent point. This will remove all 'superceded' points where newer data is available.
In the example GeoDataframe below, points #2, #3 and #4 are definitely within 20m of one another (same geometry). But only #4 should remain in the dataframe because it has the most recent timestamp.
Example GeoDataframe:
id captured_at geometry
0 1632410217000 POINT (-525919.001 7186220.048)
1 1632410219000 POINT (-525950.054 7186212.882)
2 1632410221000 POINT (-526009.173 7186211.688)
3 1632410223000 POINT (-526009.173 7186211.688)
4 1632410225000 POINT (-526009.173 7186211.688)
Full replicable example:
import geopandas as gpd
import pandas as pd
df = pd.DataFrame(
{'captured_at': [1632410217000, 1632410219000, 1632410221000, 1632410223000, 1632410225000],
'geometry': ['POINT (-525919.001 7186220.048)', 'POINT (-525950.054 7186212.882)',
'POINT (-526009.173 7186211.688)', 'POINT (-526009.173 7186211.688)',
'POINT (-526009.173 7186211.688)']})
df['geometry'] = gpd.GeoSeries.from_wkt(df['geometry'])
gdf = gpd.GeoDataFrame(df, geometry='geometry')
gdf
How might I go about this problem?