Forked from scascketta/11106@2015-01-20T14:57:00-06:00<---->2015-01-20T15:31:00-06:00.geojson
Last active
August 29, 2015 14:13
-
-
Save luqmaan/833cb3fdfbef1b61cd2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [-97.748856, 30.264645]}, "type": "Feature", "id": 0, "properties": {"time": "2015-01-20T14:42:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.756493, 30.267588]}, "type": "Feature", "id": 1, "properties": {"time": "2015-01-20T14:43:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.756683, 30.265663]}, "type": "Feature", "id": 2, "properties": {"time": "2015-01-20T14:45:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.758865, 30.260218]}, "type": "Feature", "id": 3, "properties": {"time": "2015-01-20T14:47:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.762413, 30.254635]}, "type": "Feature", "id": 4, "properties": {"time": "2015-01-20T14:48:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.764946, 30.251499]}, "type": "Feature", "id": 5, "properties": {"time": "2015-01-20T14:49:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.7696, 30.248529]}, "type": "Feature", "id": 6, "properties": {"time": "2015-01-20T14:51:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.773087, 30.247623]}, "type": "Feature", "id": 7, "properties": {"time": "2015-01-20T14:52:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.777802, 30.246742]}, "type": "Feature", "id": 8, "properties": {"time": "2015-01-20T14:54:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.781067, 30.24457]}, "type": "Feature", "id": 9, "properties": {"time": "2015-01-20T14:55:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.789993, 30.2383]}, "type": "Feature", "id": 10, "properties": {"time": "2015-01-20T14:57:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.792809, 30.236292]}, "type": "Feature", "id": 11, "properties": {"time": "2015-01-20T14:58:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.792145, 30.230986]}, "type": "Feature", "id": 12, "properties": {"time": "2015-01-20T15:01:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.799522, 30.229115]}, "type": "Feature", "id": 13, "properties": {"time": "2015-01-20T15:03:00-06:00"}}, {"geometry": {"type": "Point", "coordinates": [-97.799965, 30.229088]}, "type": "Feature", "id": 14, "properties": {"time": "2015-01-20T15:04:00-06:00"}}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import rethinkdb as r | |
import geojson as gj | |
import arrow | |
import sys | |
def make_feature(vehicle, id): | |
point = gj.Point(tuple(vehicle['location']['coordinates'])) | |
time = arrow.get(vehicle['timestamp']).to('America/Chicago') | |
f = { | |
'geometry': point, | |
'properties': {'time': time.isoformat()}, | |
'id': id | |
} | |
return gj.Feature(**f) | |
def make_featcoll(vehicle_id, limit): | |
docs = get_vehicle_data(vehicle_id, limit) | |
features = [] | |
for ind, doc in enumerate(docs): | |
features.append(make_feature(doc, ind)) | |
feat_coll = gj.FeatureCollection(features) | |
start = arrow.get(docs[0]['timestamp']).to('America/Chicago').isoformat() | |
end = arrow.get(docs[-1]['timestamp']).to('America/Chicago').isoformat() | |
fname = '{vid}@{start}<-->{end}.geojson'.format(vid=vehicle_id, start=start, end=end) | |
with open(fname, 'w') as f: | |
gj.dump(feat_coll, f) | |
def get_vehicle_data(vehicle_id, limit): | |
return list(r.table('vehicle_position') \ | |
.filter(r.row['vehicle_id'] == vehicle_id) \ | |
.order_by('timestamp') \ | |
.limit(int(limit)).run()) | |
if __name__ == '__main__': | |
if len(sys.argv) < 3: | |
print 'Usage: explore.py <vehicle_id> <limit>' | |
sys.exit(-1) | |
r.connect('localhost', 28015).repl() | |
make_featcoll(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment