Skip to main content

BRDR - a Python library to assist in realigning (multi-)polygons (OGC Simple Features) to reference borders

Project description

brdr

a Python library to assist in realigning (multi-)polygons (OGC Simple Features) to reference borders

PyPI - Version

DOI

Quick links:

Description

Intro

brdr is a Python package that assists in aligning geometric boundaries to reference boundaries. This is an important task in geographic data management to enhance data quality.

  • In the context of geographic data management, it is important to have accurate and consistent boundaries for a variety of applications such as calculating areas, analyzing spatial relationships, and visualizing and querying geographic information.
  • When creating geographic data, it is often more efficient to derive boundaries from existing reference data rather than collecting new data in the field.
  • brdr can be used to align boundaries from new data to reference data, ensuring that the boundaries are accurate and consistent.

Example

The figure below shows:

  • the original thematic geometry (blue),
  • A reference layer (yellow-black).
  • The resulting geometry after alignment with brdr (green)

Functionalities

brdr provides a variety of side-functionalities to assist in aligning boundaries, including:

  • Loading thematic data ((Multi-)Polygons): as a dict, geojson or Web Feature Service (WFS-url)
  • Loading reference data ((Multi-)Polygons): as a dict, geojson or Web Feature Service (WFS-url)
  • (Flanders-specific) Download reference data from GRB-Flanders
  • Align thematic boundaries to reference boundaries with a specific relevant distance (process_dict_thematic)
  • Align thematic boundaries to reference boundaries with a series of specified relevant distances (process_series)
  • Make use of a 'predictor'-function that aligns thematic boundaries to reference boundaries for 'predicted' interesting relevant distances (predictor)
  • Calculating a descriptive formulation of a thematic boundary based on a reference layer

Possible application fields

  • Geodata-management:
    • Implementation of brdr in business-processes and tooling
    • Bulk geodata-alignment
    • Alignment after reprojection of data
    • Cleaning data: In a postprocessing-phase, the algorithm executes sliver-cleanup and validity-cleaning on the resulting geometries
    • ...
  • Data-Analysis: Investigate the pattern in deviation and change between thematic and reference boundaries
  • Update-detection: Investigate the descriptive formulation before and after alignment to check for (automatic) alignment of geodata
  • ...

QGIS-script

An implementation of brdr for QGIS can be found at GitHub-brdrQ. This QGIS- script provides a User Interface to align thematic data to a reference layer, showing the results in the QGIS Table of Contents.

Installation

You can install the latest release of brdr from GitHub or PyPi:

pip install brdr

Basic example

from brdr.aligner import Aligner
from brdr.enums import OpenbaarDomeinStrategy
from brdr.geometry_utils import geom_from_wkt
from brdr.loader import DictLoader

# CREATE AN ALIGNER
aligner = Aligner(
    relevant_distance=1,
    od_strategy=OpenbaarDomeinStrategy.SNAP_SINGLE_SIDE,
    threshold_overlap_percentage=50,
    crs="EPSG:31370",
)
# ADD A THEMATIC POLYGON TO THEMATIC DICTIONARY and LOAD into Aligner
thematic_dict = {"theme_id_1": geom_from_wkt("POLYGON ((0 0, 0 9, 5 10, 10 0, 0 0))")}
loader = DictLoader(thematic_dict)
aligner.load_thematic_data(loader)
# ADD A REFERENCE POLYGON TO REFERENCE DICTIONARY and LOAD into Aligner
reference_dict = {"ref_id_1": geom_from_wkt("POLYGON ((0 1, 0 10,8 10,10 1,0 1))")}
loader = DictLoader(reference_dict)
aligner.load_reference_data(loader)
# EXECUTE THE ALIGNMENT
process_result = aligner.process_dict_thematic(relevant_distance=1)
# PRINT RESULTS IN WKT
print("result: " + process_result["theme_id_1"]["result"].wkt)
print("added area: " + process_result["theme_id_1"]["result_diff_plus"].wkt)
print("removed area: " + process_result["theme_id_1"]["result_diff_min"].wkt)
# SHOW RESULTING GEOMETRY AND CHANGES
# from examples import show_map
# show_map(
#     {aligner.relevant_distance:(result, result_diff, result_diff_plus, result_diff_min, relevant_intersection, relevant_diff)},
#     thematic_dict,
#     reference_dict)

The resulting figure shows:

  • the reference polygon (yellow-black)
  • the original geometry (blue)
  • the resulting geometry (green line)
  • the added zone (green squares)
  • the removed zone (red squares)

More examples can be found in Examples

Workflow

(see also Basic example)

To use brdr, follow these steps:

  • Create a Aligner-class with specific parameters:
    • relevant_distance (m) (default: 1): Distance-parameter used to decide which parts will be aligned, and which parts remain unchanged.
    • od_strategy (enum) (default: SNAP_SINGLE_SIDE): Strategy to align geodata that is not covered by reference-data
    • threshold_overlap_percentage (%)(0-100) (default 50)
    • crs: The Coordinate Reference System (CRS) (default: EPSG:31370 - Belgian Lambert72)
  • Load thematic data
  • Load reference data
  • Process (align) the thematic data
  • Results are returned:
    • Resulting geometry
    • Differences: parts that are 'different' from the original geometry (positive or negative)
    • Positive differences: parts that are added to the original geometry
    • Negative differences: parts that are removed form the original geometry
    • Relevant intersections: relevant intersecting parts of the reference geometries
    • Relevant differences: relevant differences of the reference geometries

The brdr-algorithm

The algorithm for alignment is based on 2 main principles:

  • Principle of intentionality: Thematic boundaries can consciously or unconsciously deviate from the reference borders. The algorithm should keep notice of that.
  • Selective spatial conservation of shape: The resulting geometry should re-use the shape of the reference borders where aligned is of relevance.

The figure below shows a schematic overview of the algorithm:

The algorithm can be split into 3 main phases:

  • Initialisation:
    • Deciding which reference polygons are candidate-polygons to re-use its shape. The reference candidate polygons are selected based on spatial intersection with the thematic geometry.
  • Processing:
    • Process all candidate-reference polygons one-by-one
    • Calculate relevant zones for each candidate-reference-polygon
      • relevant intersections: zones that must be present in the final result
      • relevant differences: zones that must be excluded from the final result
    • Evaluate each candidate based on their relative zones: which parts must be kept and which parts must be excluded
    • Union all kept parts to recompose a resulting geometry
  • Post-processing:
    • Validation/correction of differences between the original input geometry and the composed intermediate resulting geometry after processing the algorithm
    • Technical validation of inner holes and multipolygons that are created by processing the algorithm
    • Clean-up slivers
    • Make the resulting geometry valid

RESULT:

A new resulting output geometry, aligned to the reference-polygons

Development

pip-compile

PIP_COMPILE_ARGS="-v --strip-extras --no-header --resolver=backtracking --no-emit-options --no-emit-find-links"
pip-compile $PIP_COMPILE_ARGS
pip-compile $PIP_COMPILE_ARGS -o requirements-dev.txt --all-extras

tests

python -m pytest --cov=brdr tests/ --cov-report term-missing

Motivation & citation

A more in-depth description of the algorithm can be found in the following article (in dutch):

  • Dieussaert, K., Vanvinckenroye, M., Vermeyen, M., & Van Daele, K. (2024). Grenzen verleggen. Automatische correcties van geografische afbakeningen op verschuivende onderlagen Onderzoeksrapporten Agentschap Onroerend Erfgoed, 332. https://doi.org/10.55465/SXCW6218.

Comments and contributions

We would love to hear from you and your experiences with brdr or its sister project brdrQ. The discussions forum is the place to be when:

  • You have any questions on using brdr or brdrQ or their applicability to your use cases
  • Want to share your experiences with the library
  • Have any suggestions for improvements or feature requests

If you have discovered a bug in the brdr library you can report it here:

https://github.com/OnroerendErfgoed/brdr/issues

We try to keep the list of issues as clean as possible. If you're unsure whether something is a bug, or whether the bug is in brdr or brdrQ, we encourage you to go through the discussions forum first.

Acknowledgement

This software was created by Athumi, the Flemish data utility company, and Flanders Heritage Agency.

https://athumi.be/en/ https://www.onroerenderfgoed.be/flanders-heritage-agency

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brdr-0.2.1.tar.gz (19.7 MB view details)

Uploaded Source

Built Distribution

brdr-0.2.1-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file brdr-0.2.1.tar.gz.

File metadata

  • Download URL: brdr-0.2.1.tar.gz
  • Upload date:
  • Size: 19.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for brdr-0.2.1.tar.gz
Algorithm Hash digest
SHA256 48bb9503399e0074a7851d81ee29b6e9b689cca3293ffda9de0b279c2723540f
MD5 f2175bed635d49d49a3a53935ce349cc
BLAKE2b-256 4d85d263646bf07746ca3ddc17c519a19026ac7f3dd091ee444155530292688a

See more details on using hashes here.

File details

Details for the file brdr-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: brdr-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for brdr-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 645d1dd89d4f2e8f4db074e010e04b07fcb4aff35a44feee6add0ab3b688b066
MD5 397d275277d67474c0b8d9a9d21d77e7
BLAKE2b-256 f50bb40aea9f1453a6c8f4f373a948b0821c6b02045c4026b830f6fbb3019953

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page