New API call to get items in a place
This commit is contained in:
parent
a81cedaae0
commit
87005dea18
|
@ -914,3 +914,21 @@ def isa_incremental_search(search_terms):
|
||||||
}
|
}
|
||||||
ret.append(cur)
|
ret.append(cur)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def get_place_items(osm_type, osm_id):
|
||||||
|
src_id = osm_id * {'way': 1, 'relation': -1}[osm_type]
|
||||||
|
|
||||||
|
q = (model.Item.query
|
||||||
|
.join(model.ItemLocation)
|
||||||
|
.join(model.Polygon, func.ST_Covers(model.Polygon.way, model.ItemLocation.location))
|
||||||
|
.filter(model.Polygon.src_id == src_id))
|
||||||
|
# sql = q.statement.compile(compile_kwargs={"literal_binds": True})
|
||||||
|
|
||||||
|
item_count = q.count()
|
||||||
|
items = []
|
||||||
|
for item in q:
|
||||||
|
keys = ["item_id", "labels", "descriptions", "aliases", "sitelinks", "claims"]
|
||||||
|
item_dict = {key: getattr(item, key) for key in keys}
|
||||||
|
items.append(item_dict)
|
||||||
|
|
||||||
|
return {"count": item_count, "items": items}
|
||||||
|
|
|
@ -450,6 +450,15 @@ def api_wikidata_items():
|
||||||
t1 = time() - t0
|
t1 = time() - t0
|
||||||
return cors_jsonify(success=True, duration=t1, **ret)
|
return cors_jsonify(success=True, duration=t1, **ret)
|
||||||
|
|
||||||
|
@app.route("/api/1/place/<osm_type>/<int:osm_id>")
|
||||||
|
def api_place_items(osm_type, osm_id):
|
||||||
|
t0 = time()
|
||||||
|
|
||||||
|
ret = api.get_place_items(osm_type, osm_id)
|
||||||
|
|
||||||
|
t1 = time() - t0
|
||||||
|
return cors_jsonify(success=True, duration=t1, **ret)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/1/osm")
|
@app.route("/api/1/osm")
|
||||||
def api_osm_objects():
|
def api_osm_objects():
|
||||||
|
|
Loading…
Reference in a new issue