Skip to main content

Get Started

Process
Minimal end-to-end alignment example with in-memory data
Author

Karel Dieussaert

Published

January 7, 2026

Get Started

This is the smallest complete brdr workflow:

  1. Create an Aligner.
  2. Load one thematic geometry and one reference geometry with DictLoader.
  3. Run process(...) for one relevant_distance.
  4. Inspect the aligned result and the added/removed differences.

Use this example as the baseline before trying external loaders or advanced processors.

Input and Output

  • Input: two small polygons created from WKT.
  • Output:
    • result: aligned geometry
    • result_diff_plus: area added by alignment
    • result_diff_min: area removed by alignment
from brdr.aligner import Aligner
from brdr.enums import AlignerResultType
from brdr.geometry_utils import geom_from_wkt
from brdr.loader import DictLoader

THEME_ID = "theme_id_1"
REFERENCE_ID = "ref_id_1"

aligner = Aligner(crs="EPSG:31370")

# Load thematic geometry.
thematic_geometries = {THEME_ID: geom_from_wkt("POLYGON ((0 0, 0 9, 5 10, 10 0, 0 0))")}
aligner.load_thematic_data(DictLoader(thematic_geometries))

# Load reference geometry.
reference_geometries = {
    REFERENCE_ID: geom_from_wkt("POLYGON ((0 1, 0 10,8 10,10 1,0 1))")
}
aligner.load_reference_data(DictLoader(reference_geometries))

# Run alignment for a single relevant distance.
aligner_result = aligner.predict()
prediction_results = aligner_result.get_results(
    aligner=aligner,
    result_type=AlignerResultType.PREDICTIONS,
)


# Print all predicted candidates and their differences in WKT.
feature_predictions = prediction_results.get(THEME_ID, {})
print(f"Number of PREDICTIONS: {len(feature_predictions)}")

for prediction_number, (relevant_distance, result) in enumerate(
    sorted(feature_predictions.items()), start=1
):
    prediction_score = result["properties"].get("brdr_prediction_score")
    print(
        f"\nPREDICTION {prediction_number} "
        f"(relevant distance: {relevant_distance} m, score: {prediction_score})"
    )
    print(f"result: {result['result'].wkt}")
    print(f"added area: {result['result_diff_plus'].wkt}")
    print(f"removed area: {result['result_diff_min'].wkt}")

# OPTIONAL - export results to GeoDataFrame

# results_gdf = aligner_result.get_results_as_geodataframe(
#     aligner=aligner,
#     add_metadata=True,
#     add_original_attributes=True,
# )
# # GeoDataFrame export (one row per theme_id + relevant_distance).
# print("gdf columns: " + ", ".join(results_gdf.columns.astype(str)))
# print(results_gdf[[aligner.thematic_data.id_fieldname, "relevant_distance"]].head())
Number of PREDICTIONS: 3

PREDICTION 1 (relevant distance: 0.0 m, score: 22.5)
result: POLYGON ((0 0, 0 9, 5 10, 10 0, 0 0))
added area: GEOMETRYCOLLECTION EMPTY
removed area: GEOMETRYCOLLECTION EMPTY

PREDICTION 2 (relevant distance: 1.1 m, score: 32.5)
result: POLYGON ((5 10, 5.514659142482544 8.97068171503491, 9.500000000000007 1, 0 1, 0 10, 5 10))
added area: POLYGON ((0 10, 4.998508657095121 10, 4.998537617966647 9.99970752359333, 0 9, 0 10))
removed area: POLYGON ((0 1, 9.5 1, 10 0, 0 0, 0 1))

PREDICTION 3 (relevant distance: 2.5 m, score: 37.5)
result: POLYGON ((7.999999999999999 10, 9.999999999999995 1, 0 1, 0 10, 7.999999999999999 10))
added area: MULTIPOLYGON (((9.999999999999995 1, 9.5 1, 5 10, 7.999999999999999 10, 9.999999999999995 1)), ((0 10, 4.998508657095121 10, 4.998537617966647 9.99970752359333, 0 9, 0 10)))
removed area: POLYGON ((0 1, 9.5 1, 10 0, 0 0, 0 1))

<- Back to examples overview