Skip to content
Snippets Groups Projects
Commit 3dd68d44 authored by Pablo de la Mora's avatar Pablo de la Mora
Browse files

Add date from Valencian cadaster rule

parent ca750c99
No related branches found
No related tags found
1 merge request!15Resolve "Create a rule that gets the construction date from cadaster data for Tabula dataset."
Pipeline #78957 passed
......@@ -34,7 +34,8 @@ tests:
- virtualenv venv
- source venv/bin/activate
- pip3 install pytest
- pip3 install https://git.gfz-potsdam.de/globaldynamicexposure/libraries/rule-lib/-/archive/main/rule-lib-main.zip
- pip3 config set global.extra-index-url https://git.gfz-potsdam.de/api/v4/projects/2940/packages/pypi/simple
- pip3 install rulelib>=0.1.1
script:
- pytest tests
......
......@@ -8,4 +8,5 @@
<output>
<param type="dict">building_information</param>
</output>
</rule>
class GeometryRule:
from rulelib import AbstractRule
class GeometryRule(AbstractRule):
def __call__(self, geometry, *args, **kwargs):
"""
Wrap the WKT formatted geometry of a building in the `ST_GeomFromText()` function
......
class OccupancyRule:
from rulelib import AbstractRule
class OccupancyRule(AbstractRule):
def __call__(self, tags, osm_spots, osm_lands, *args, **kwargs):
"""
Define the occupancy type of the building. There are 10 sequential rules that can
......
class QuadkeyRule:
from rulelib import AbstractRule
class QuadkeyRule(AbstractRule):
def __call__(self, longitude, latitude, *args, **kwargs):
"""
Determine the Quadkey of the tile in which the building centroid is located given its
......
class RelationIDRule:
from rulelib import AbstractRule
class RelationIDRule(AbstractRule):
def __call__(self, relations, *args, **kwargs):
"""
Determine the building relation OSM ID.
......
source diff could not be displayed: it is too large. Options to address this: view the blob.
# Copyright (c) 2023-2024:
# 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 rulelib import AbstractRule
class DateFromValencianCadasterRule(AbstractRule):
from databaselib import PostGISDatabase
def __call__(self, database: PostGISDatabase, geometry: str, *args, **kwargs):
"""
This rule provides an additional source for a building's construction year for the
Valencia province in Spain if it is not available in OSM. A building's geometry is
tested for intersection with a cadastral parcel in the source database. If such a parcel
exists, its construction date is taken from the related cadastral buildings table.
Args:
database (PostGISDatabase):
Source database that contains the cadastral data, including the two necessary
tables `parcels` and `cadaster_buildings`.
geometry (str):
Geometry of the building being currently processed. The geometry is a WKT
formatted string wrapped in the `ST_GeomFromText()` function.
Returns:
Integer that represents the building's construction year.
"""
sql_statement = f"""
WITH b (geom) AS (VALUES ({geometry})
SELECT construction_year
FROM Parcels
INNER JOIN cadaster_buildings USING(parcel_id)
INNER JOIN b ON ST_Intersects(b.geom, Parcels.geom)
WHERE b.geom && Parcels.geom
-- WHERE ST_Intersects({geometry}, Parcels.geom)
"""
database.cursor.execute(sql_statement)
construction_year = database.cursor.fetchone()
if construction_year is None or construction_year == "":
return {"date_cadaster": None}
else:
return {"date_cadaster": int(construction_year[0])}
<?xml version="1.0" encoding="UTF-8" ?>
<rule name="DateFromValencianCadasterRule">
<input>
<param type="str">geometry</param>
<param type="PostGISDatabase">database</param>
<param type="float">longitude</param>
<param type="float">latitude</param>
</input>
<function filepath="date_from_valencian_cadaster.py"/>
<database name="source"/>
<dependencies>
<dependency name="GeometryRule"/>
<dependency name="SelectRule"/>
</dependencies>
<output>
</output>
<filter filepath="boundary.txt"/>
</rule>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment