Skip to content
Snippets Groups Projects

Added endpoint to query buildings by bounding box

Merged Felix Delattre requested to merge feature/bbox-query into master
All threads resolved!
2 files
+ 33
4
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 31
3
@@ -79,8 +79,36 @@ async def heartbeat() -> dict:
@app.api.add_function
async def get_building(osm_id) -> dict:
building = await app.db.fetch_val(
"SELECT osm_id FROM osm_building_polygons WHERE osm_id = :osm_id",
result = await app.db.fetch_all(
"SELECT * FROM osm_building_polygons WHERE osm_id = :osm_id",
values={"osm_id": int(osm_id)},
)
return {"building": str(building)}
values = {}
for building in result:
for key, value in building.items():
values[key] = value
return {"building": values}
@app.api.add_function
async def get_buildings_by_bbox(xmin, ymin, xmax, ymax) -> dict:
buildings = await app.db.fetch_all(
"SELECT * FROM osm_building_polygons \
WHERE geometry && ST_MakeEnvelope(:xmin, :ymin, :xmax, :ymax, 4326)",
values={
"xmin": float(xmin),
"ymin": float(ymin),
"xmax": float(xmax),
"ymax": float(ymax),
},
)
buildings_data_object = {}
for building in buildings:
osm_id = 0
values = {}
for key, value in building.items():
values[key] = value
if key == "osm_id":
osm_id = value
buildings_data_object[osm_id] = values
return {"buildings": buildings_data_object}
Loading