Skip to content

Instantly share code, notes, and snippets.

@lmeulen
Created April 4, 2021 11:26
Show Gist options
  • Save lmeulen/f51344abfe4939d06de52e0b0e178e80 to your computer and use it in GitHub Desktop.
Save lmeulen/f51344abfe4939d06de52e0b0e178e80 to your computer and use it in GitHub Desktop.
crowdedness_create_features
features=[]
for rn in timedata.ritnumber.unique():
total_trip = timedata[timedata.ritnumber == rn].dropna()
for sq in total_trip.sequence.unique():
trip = total_trip[total_trip.sequence == sq]
tripfirst = trip.iloc[0]
triplast = trip.iloc[-1]
name = str(tripfirst["ritnumber"]) + " : " + tripfirst["stop_code"] + \
" - " + triplast["stop_code"]
ls = LineString(trip[['lon', 'lat', 'elevation', 'timestamp']]. \
to_numpy().tolist())
features.append(
Feature(geometry=ls ,
properties=dict(label=str(tripfirst["ritnumber"]),
name=name,
capacity=str(tripfirst["seats"]),
passengers=str(tripfirst["passengers"]),
crowding=str(tripfirst["classification"])))
)
with open('trainpag.geojson', 'w') as outfile:
dump(FeatureCollection(features), outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment