Add filter functionalities by geo data
This commit is contained in:
parent
df5084bf21
commit
dfd53a6623
@ -26,12 +26,37 @@ def get_traffic_lights():
|
|||||||
tl_id = query_parameters.get('id')
|
tl_id = query_parameters.get('id')
|
||||||
|
|
||||||
if tl_id is not None:
|
if tl_id is not None:
|
||||||
traffic_lights = [traffic_light for traffic_light in mongo.db.trafficLights.find({'id': tl_id})]
|
traffic_lights = [traffic_light for traffic_light in
|
||||||
|
mongo.db.trafficLights.find({'id': tl_id})]
|
||||||
else:
|
else:
|
||||||
traffic_lights = [traffic_light for traffic_light in mongo.db.trafficLights.find({})]
|
traffic_lights = [traffic_light for traffic_light in mongo.db.trafficLights.find({})]
|
||||||
|
|
||||||
return json_util.dumps({'cursor': traffic_lights})
|
return json_util.dumps({'cursor': traffic_lights})
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/v1/resources/traffic_lights_geo', methods=['GET'])
|
||||||
|
def get_traffic_lights_geo():
|
||||||
|
query_parameters = request.args
|
||||||
|
|
||||||
|
lat = float(query_parameters.get('lat'))
|
||||||
|
lon = float(query_parameters.get('lon'))
|
||||||
|
distance = float(query_parameters.get('distance'))
|
||||||
|
|
||||||
|
traffic_lights = [
|
||||||
|
traffic_light for traffic_light in
|
||||||
|
mongo.db.trafficLights.find({'location': {
|
||||||
|
'$near': {
|
||||||
|
'$geometry': {
|
||||||
|
'type': "Point",
|
||||||
|
'coordinates': [lon, lat]
|
||||||
|
},
|
||||||
|
'$maxDistance': distance
|
||||||
|
}
|
||||||
|
}})
|
||||||
|
]
|
||||||
|
|
||||||
|
return json_util.dumps({'cursor': traffic_lights})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0')
|
app.run(host='0.0.0.0')
|
||||||
|
|||||||
@ -2,3 +2,5 @@
|
|||||||
|
|
||||||
mongoimport --db entities --collection cars --type json --file cars.json --jsonArray
|
mongoimport --db entities --collection cars --type json --file cars.json --jsonArray
|
||||||
mongoimport --db entities --collection trafficLights --type json --file traffic_lights.json --jsonArray
|
mongoimport --db entities --collection trafficLights --type json --file traffic_lights.json --jsonArray
|
||||||
|
|
||||||
|
mongo --eval 'db.trafficLights.ensureIndex({location:"2dsphere"})' entities
|
||||||
@ -1,16 +1,10 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"location": {
|
"location": [16.315283, 48.190331]
|
||||||
"type": "Point",
|
|
||||||
"coordinates": [-73.856077, 40.848447]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "2",
|
"id": "2",
|
||||||
"location": {
|
"location": [16.316331, 48.192382]
|
||||||
"type": "Point",
|
|
||||||
"coordinates": [-73.856077, 40.848447]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Loading…
x
Reference in New Issue
Block a user