Skip to content
Snippets Groups Projects
Commit c3023e57 authored by Felix Delattre's avatar Felix Delattre
Browse files

Added endpoint to query buildings by bounding box

parent 167f5275
No related branches found
No related tags found
1 merge request!7Added endpoint to query buildings by bounding box
Pipeline #26427 passed
......@@ -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}
......@@ -40,4 +40,5 @@ def test_heartbeat(client) -> None:
def test_get_building(client) -> None:
response = request("http://127.0.0.1:5000/v1", "get_building", "-12412416").data.result
assert "-12412416" in response["building"]
print(response["building"]["osm_id"])
assert -12412416 == response["building"]["osm_id"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment