Commit 8014b816 authored by Marius Kriegerowski's avatar Marius Kriegerowski
Browse files

Added building to retrieve land use of buildings

parent ba438333
Pipeline #23805 passed with stage
in 2 minutes
#!/usr/bin/env python3
# Copyright (C) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
from typing import Tuple, Iterator
from rabotnik import Rule
class GetBuildingLandUse(Rule):
"""A rule to get the land use of a building."""
def __init__(self, storage):
self.storage = storage
async def evaluate(self, payload: dict) -> Iterator[Tuple[int]]:
building_id = payload["building_id"]
async for land_use in self.storage.iter_results(
f"""SELECT land.class
FROM osm_building_relations AS building, osm_lands AS land
WHERE {building_id} = building.id
AND ST_INTERSECTS(land.geometry, building.geometry);
"""
):
yield land_use
#!/usr/bin/env python3
# Copyright (C) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import pytest
from rabotnikobm.rules.get_building_land_use import (
GetBuildingLandUse,
)
@pytest.mark.requires_storage
@pytest.mark.asyncio
async def test_get_points_in_building(connected_storage):
rule = GetBuildingLandUse(storage=connected_storage)
payload = {"building_id": 193799}
result = [result async for result in rule.evaluate(payload=payload)]
assert result == [("forest",)]
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