def trip_to_geojson(trip, tl): """ Trips are the main focus of our current visualization, so they are most complex. Each trip is represented as a feature collection with the following features: - two features for the start and end places - features for each stop in the trip - features for each section in the trip :param trip: the trip object to be converted :param tl: the timeline used to retrieve related objects :return: the geojson version of the trip """ feature_array = [] curr_start_place = tl.get_object(trip.data.start_place) curr_end_place = tl.get_object(trip.data.end_place) start_place_geojson = place_to_geojson(curr_start_place) start_place_geojson["properties"]["feature_type"] = "start_place" feature_array.append(start_place_geojson) end_place_geojson = place_to_geojson(curr_end_place) end_place_geojson["properties"]["feature_type"] = "end_place" feature_array.append(end_place_geojson) trip_tl = esdt.get_cleaned_timeline_for_trip(trip.user_id, trip.get_id()) stops = trip_tl.places for stop in stops: feature_array.append(stop_to_geojson(stop)) for i, section in enumerate(trip_tl.trips): section_gj = section_to_geojson(section, tl) feature_array.append(section_gj) trip_geojson = gj.FeatureCollection(features=feature_array, properties=trip.data) trip_geojson.id = str(trip.get_id()) feature_array.extend( geojson_incidents_in_range(trip.user_id, curr_start_place.data.exit_ts, curr_end_place.data.enter_ts)) if trip.metadata.key == esda.CLEANED_UNTRACKED_KEY: # trip_geojson.properties["feature_type"] = "untracked" # Since the "untracked" type is not correctly handled on the phone, we just # skip these trips until # https://github.com/e-mission/e-mission-phone/issues/118 # is fixed # TODO: Once it is fixed, re-introduce the first line in this block # and remove the None check in get_geojson_for_timeline return None else: trip_geojson.properties["feature_type"] = "trip" return trip_geojson
def trip_to_geojson(trip, tl): """ Trips are the main focus of our current visualization, so they are most complex. Each trip is represented as a feature collection with the following features: - two features for the start and end places - features for each stop in the trip - features for each section in the trip :param trip: the trip object to be converted :param tl: the timeline used to retrieve related objects :return: the geojson version of the trip """ feature_array = [] curr_start_place = tl.get_object(trip.data.start_place) curr_end_place = tl.get_object(trip.data.end_place) start_place_geojson = place_to_geojson(curr_start_place) start_place_geojson["properties"]["feature_type"] = "start_place" feature_array.append(start_place_geojson) end_place_geojson = place_to_geojson(curr_end_place) end_place_geojson["properties"]["feature_type"] = "end_place" feature_array.append(end_place_geojson) trip_tl = esdt.get_cleaned_timeline_for_trip(trip.user_id, trip.get_id()) stops = trip_tl.places for stop in stops: feature_array.append(stop_to_geojson(stop)) for i, section in enumerate(trip_tl.trips): section_gj = section_to_geojson(section, tl) feature_array.append(section_gj) trip_geojson = gj.FeatureCollection(features=feature_array, properties=trip.data) trip_geojson.id = str(trip.get_id()) feature_array.extend(geojson_incidents_in_range(trip.user_id, curr_start_place.data.exit_ts, curr_end_place.data.enter_ts)) if trip.metadata.key == esda.CLEANED_UNTRACKED_KEY: # trip_geojson.properties["feature_type"] = "untracked" # Since the "untracked" type is not correctly handled on the phone, we just # skip these trips until # https://github.com/e-mission/e-mission-phone/issues/118 # is fixed # TODO: Once it is fixed, re-introduce the first line in this block # and remove the None check in get_geojson_for_timeline return None else: trip_geojson.properties["feature_type"] = "trip" return trip_geojson
def trip_to_geojson(trip, tl): """ Trips are the main focus of our current visualization, so they are most complex. Each trip is represented as a feature collection with the following features: - two features for the start and end places - features for each stop in the trip - features for each section in the trip :param trip: the trip object to be converted :param tl: the timeline used to retrieve related objects :return: the geojson version of the trip """ feature_array = [] curr_start_place = tl.get_object(trip.data.start_place) curr_end_place = tl.get_object(trip.data.end_place) start_place_geojson = place_to_geojson(curr_start_place) start_place_geojson["properties"]["feature_type"] = "start_place" feature_array.append(start_place_geojson) end_place_geojson = place_to_geojson(curr_end_place) end_place_geojson["properties"]["feature_type"] = "end_place" feature_array.append(end_place_geojson) trip_tl = esdt.get_cleaned_timeline_for_trip(trip.user_id, trip.get_id()) stops = trip_tl.places for stop in stops: feature_array.append(stop_to_geojson(stop)) for i, section in enumerate(trip_tl.trips): # TODO: figure out whether we should do this at the model. # The first section starts with the start of the trip. But the trip itself starts at the first # point where we exit the geofence, not at the start place. That is because we don't really know when # we left the start place. We can fix this in the model through interpolation. For now, we assume that the # gap between the real departure time and the time that the trip starts is small, and just combine it here. section_gj = section_to_geojson(section, tl) feature_array.append(section_gj) trip_geojson = gj.FeatureCollection(features=feature_array, properties=trip.data) trip_geojson.id = str(trip.get_id()) trip_geojson.properties["feature_type"] = "trip" return trip_geojson
def trip_to_geojson(trip, tl): """ Trips are the main focus of our current visualization, so they are most complex. Each trip is represented as a feature collection with the following features: - two features for the start and end places - features for each stop in the trip - features for each section in the trip :param trip: the trip object to be converted :param tl: the timeline used to retrieve related objects :return: the geojson version of the trip """ feature_array = [] curr_start_place = tl.get_object(trip.data.start_place) curr_end_place = tl.get_object(trip.data.end_place) start_place_geojson = place_to_geojson(curr_start_place) start_place_geojson["properties"]["feature_type"] = "start_place" feature_array.append(start_place_geojson) end_place_geojson = place_to_geojson(curr_end_place) end_place_geojson["properties"]["feature_type"] = "end_place" feature_array.append(end_place_geojson) trip_tl = esdt.get_cleaned_timeline_for_trip(trip.user_id, trip.get_id()) stops = trip_tl.places for stop in stops: feature_array.append(stop_to_geojson(stop)) for i, section in enumerate(trip_tl.trips): # TODO: figure out whether we should do this at the model. # The first section starts with the start of the trip. But the trip itself starts at the first # point where we exit the geofence, not at the start place. That is because we don't really know when # we left the start place. We can fix this in the model through interpolation. For now, we assume that the # gap between the real departure time and the time that the trip starts is small, and just combine it here. section_gj = section_to_geojson(section, tl) feature_array.append(section_gj) trip_geojson = gj.FeatureCollection(features=feature_array, properties=trip.data) trip_geojson.id = str(trip.get_id()) trip_geojson.properties["feature_type"] = "trip" return trip_geojson