Commit ba438333 authored by Marius Kriegerowski's avatar Marius Kriegerowski
Browse files

Added floorspace calculation rule

parent ede57bfc
Pipeline #23996 passed with stage
in 1 minute and 14 seconds
#!/usr/bin/env python3
import logging
from rabotnik.storages.base import StorageBase as RabotnikStorage
from rabotnik import Rule # pylint: disable=import-error
logger = logging.getLogger()
class Floorspace(Rule):
def __init__(self, storage: RabotnikStorage):
"""Calculate floorspace of buildings.
Args:
storage: Storage serving building data.
"""
self.storage = storage
async def evaluate(self, payload: dict) -> tuple:
building_id = payload["building_id"]
async for data in self.storage.iter_results(
f"""
SELECT ST_Area(ST_Transform(geometry, 4326)) *
CAST(br.tags->'building:levels' AS float)
FROM osm_building_relations AS br
UNION ALL
SELECT ST_Area(ST_Transform(geometry, 4326)) *
CAST(bp.tags->'building:levels' AS float)
FROM osm_building_polygons AS bp
WHERE id = {building_id};
"""
):
yield data
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment