Skip to content
Snippets Groups Projects

Resolve "Create a rule that gets the construction date from cadaster data for Tabula dataset."

Compare and Show latest version
1 file
+ 17
10
Compare changes
  • Side-by-side
  • Inline
@@ -13,27 +13,31 @@
#
# 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 databaselib import PostGISDatabase
from rulelib import AbstractRule
class DateFromValencianCadasterRule(AbstractRule):
from databaselib import PostGISDatabase
def __call__(self, database: PostGISDatabase, geometry: str, *args, **kwargs):
"""
A building's geometry is tested for intersection with a cadastral parcel in the source
database, if there is cadaster data for this location. There is currently only
cadastral data available for the Valencia Province in Spain, as reflected by this
rule's geographic boundary filter. If an intersection exists, the construction date
from this parcel is taken from the related cadastral buildings table using an inner
join. This source complements OSM for data about construction dates of buildings.
This rule is to provide an additional source for a building's construction year, when
it is not available in OSM. A building's geometry is tested for intersection with a
cadastral parcel in the source database, if there is cadaster data for this location.
There is currently only cadastral data available for the Valencia Province in Spain, as
reflected by this rule's geographic boundary filter. If an intersection exists, the
construction date from this parcel is taken from the related cadastral buildings table
using an inner join. This source complements OSM for data about construction dates of
buildings.
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.
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.
@@ -41,10 +45,13 @@ class DateFromValencianCadasterRule(AbstractRule):
"""
sql_statement = f"""
WITH b (geom) AS (VALUES ({geometry})
SELECT construction_year
FROM Parcels
INNER JOIN cadaster_buildings USING parcel_id
WHERE ST_Intersects({geometry}, Parcels.geom)
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()
Loading