Ejemplo n.º 1
0
def to_geojson(row, trip, max_distance, max_time):
    timestamps = []
    points = []
    trip_id = row[0]
    nclob = row[1].read()
    samples = json.loads(nclob)
    start_is_in_distance = False
    end_is_in_distance = False
    geojson = None

    for sample in samples:
        timestamp = sample[0]
        timestamps.append(timestamp)
        points.append((sample[1], sample[2]))

        if euclidean_distance(sample[1], trip['start_point'][0], sample[2], trip['start_point'][1]) <= max_distance \
                and abs(trip['start_time'] - timestamp) <= max_time:
            start_is_in_distance = True

        if euclidean_distance(sample[1], trip['end_point'][0], sample[2], trip['end_point'][1]) <= max_distance \
                and abs(trip['end_time'] - timestamp) <= max_time:
            end_is_in_distance = True

    if start_is_in_distance and end_is_in_distance:
        start = timestamps[0]
        end = timestamps[-1]
        duration = end - start
        geojson = create_geojson(trip_id, points, timestamps, start, end,
                                 duration)

    return geojson
Ejemplo n.º 2
0
def all_trips_to_geojson(cursor):
    trips = []
    trip_to_data = dict()

    for row in cursor:
        trip_id = row[0]

        if trip_id not in trip_to_data:
            trip_to_data[trip_id] = {'points': [], 'timestamps': []}

        timestamp = row[1]
        lon = row[2]
        lat = row[5]
        trip_to_data[trip_id]['points'].append((lon, lat))
        trip_to_data[trip_id]['timestamps'].append(timestamp)

    for trip_id, data in trip_to_data.items():
        points = data['points']
        timestamps = data['timestamps']
        start = timestamps[0]
        end = timestamps[-1]
        duration = end - start
        trips.append(
            create_geojson(trip_id, points, timestamps, start, end, duration))

    return trips
Ejemplo n.º 3
0
def to_geojson(cursor):
    timestamps = []
    points = []
    trip_id = int(cursor[0])
    nclob = cursor[1].read()
    samples = json.loads(nclob)

    for sample in samples:
        time = sample[0]
        timestamps.append(time)
        points.append((sample[1], sample[2]))

    start = timestamps[0] if len(timestamps) > 0 else 0
    end = timestamps[-1] if len(timestamps) > 0 else 0
    duration = end - start

    return create_geojson(trip_id, points, timestamps, start, end, duration)
Ejemplo n.º 4
0
def to_geojson(trip_id, cursor):
    timestamps = []
    points = []
    start = 0
    end = 0
    duration = 0

    for row in cursor:
        timestamps.append(row[0])
        points.append((row[1], row[2]))

    if len(timestamps) > 0:
        start = timestamps[0]
        end = timestamps[-1]
        duration = end - start

    return create_geojson(trip_id, points, timestamps, start, end, duration)
Ejemplo n.º 5
0
def to_geojson(trip_id, points, timestamps):
    start = timestamps[0] if len(timestamps) > 0 else 0
    end = timestamps[-1] if len(timestamps) > 0 else 0
    duration = end - start
    return create_geojson(trip_id, points, timestamps, start, end, duration)