Guest User

Untitled

a guest
Oct 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. entity_id lat lon time
  2.  
  3. 1001 34.5 14.2 4:55 pm
  4. 1001 34.7 14.5 4:58 pm
  5. 1001 35.0 14.6 5.03 pm
  6.  
  7. 1002 27.1 19.2 2:01 pm
  8. 1002 27.4 19.3 2:08 pm
  9. 1002 27.4 19.9 2:09 pm
  10.  
  11. import pandas as pd
  12. import numpy as np
  13. from geopandas import GeoDataFrame
  14. from shapely.geometry import Point, LineString
  15.  
  16. # Zip the coordinates into a point object and convert to a GeoDataFrame
  17. geometry = [Point(xy) for xy in zip(df.lon, df.lat)]
  18. df = GeoDataFrame(df, geometry=geometry)
  19.  
  20. # Aggregate these points with the GroupBy
  21. df = df.groupby(['entity_id'])['geometry'].apply(lambda x: LineString(x.tolist()) if x.size > 1 else x.tolist())
  22. df = GeoDataFrame(df, geometry='geometry')
  23.  
  24. df = df.groupby(['entity_id'])['geometry'].apply(lambda x: LineString(x.tolist()) if x.size > 1 else x.tolist())
Add Comment
Please, Sign In to add comment