I have a dataframe of X,Y coordinates that represent points along the paths taken by several different entities. Pseudo-data here, but it is roughly of the form:
entity_id lat lon time
1001 34.5 14.2 4:55 pm
1001 34.7 14.5 4:58 pm
1001 35.0 14.6 5.03 pm
1002 27.1 19.2 2:01 pm
1002 27.4 19.3 2:08 pm
1002 27.4 19.9 2:09 pm
What I would like to do is group these points by entity_id, and then arrange the points sequentially in time to create a LineString object for each entity_id. The output will be several lines/paths, with each corresponding to an entity_id.
I can do this by looping through each entity_id and each point in entity_id and using the instructions provided here, but is there a faster/more efficient way to do this leveraging GeoPandas or Shapely, perhaps with groupby?
df.groupby('entity_id', as_index=False).agg({'geometry': lambda x: ...})– Ufos Aug 30 '18 at 17:25df = gpd.GeoDataFrame(df, geometry = gpd.points_from_xy(df.x, df.y))– Felipe D. Sep 02 '20 at 21:31