From b1a575b8cf5efda3826085638302816daa5a7861 Mon Sep 17 00:00:00 2001 From: dieuska Date: Tue, 10 Sep 2024 11:03:57 +0200 Subject: [PATCH 1/3] prepare for release 0.2.1 --- CHANGES.md | 6 ++++++ brdr/__init__.py | 2 +- pyproject.toml | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 67f939a..83441c6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,3 +11,9 @@ features (([#50](https://github.com/OnroerendErfgoed/brdr/issues/50)) - fix bug reulting from overlapping features in thematic layer ([#46](https://github.com/OnroerendErfgoed/brdr/issues/46)) + +# 0.2.1 + +- fixed last_version_date in aligner.get_formula() +- fixed logic of evaluate() in grb.py +- added function to transform geojson to consistent geometry-type (MultiPolygon) \ No newline at end of file diff --git a/brdr/__init__.py b/brdr/__init__.py index 33b93db..b0515a9 100644 --- a/brdr/__init__.py +++ b/brdr/__init__.py @@ -6,4 +6,4 @@ datefmt="%d-%b-%y %H:%M:%S", ) -__version__ = "0.2.0" +__version__ = "0.2.1" diff --git a/pyproject.toml b/pyproject.toml index 7f91b98..7360032 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "brdr" -version = "0.2.0" +version = "0.2.1" description = "BRDR - a Python library to assist in realigning (multi-)polygons (OGC Simple Features) to reference borders " readme = { file = "README.md", content-type = "text/markdown" } license = { file = "LICENSE" } @@ -20,6 +20,7 @@ classifiers = [ "Operating System :: OS Independent", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.9", "Topic :: Scientific/Engineering :: GIS", ] From 5f7712682e6c6a8610a17b9af92dc77fb318fc5d Mon Sep 17 00:00:00 2001 From: dieuska Date: Tue, 10 Sep 2024 11:05:24 +0200 Subject: [PATCH 2/3] black formatted --- brdr/geometry_utils.py | 7 +++++-- brdr/grb.py | 30 ++++++++++++++---------------- examples/example_evaluate.py | 1 - 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/brdr/geometry_utils.py b/brdr/geometry_utils.py index a29ea89..396f43c 100644 --- a/brdr/geometry_utils.py +++ b/brdr/geometry_utils.py @@ -610,6 +610,7 @@ def get_bbox(geometry): """ return str(geometry.bounds).strip("()") + def geojson_polygon_to_multipolygon(geojson): """ Transforms a geojson: Checks if there are Polygon-features and transforms them into MultiPolygons, so all objects are of type 'MultiPolygon' (or null-geometry). @@ -621,6 +622,8 @@ def geojson_polygon_to_multipolygon(geojson): if f["geometry"] is None: continue if f["geometry"]["type"] == "Polygon": - f["geometry"] = {"type": "MultiPolygon", - "coordinates": [f["geometry"]["coordinates"]]} + f["geometry"] = { + "type": "MultiPolygon", + "coordinates": [f["geometry"]["coordinates"]], + } return geojson diff --git a/brdr/grb.py b/brdr/grb.py index d30f3c0..4f6e35d 100644 --- a/brdr/grb.py +++ b/brdr/grb.py @@ -265,6 +265,7 @@ def get_collection_grb_fiscal_parcels( url, geometry=geometry, partition=partition, limit=limit, crs=crs ) + def evaluate( actual_aligner, dict_series, @@ -329,16 +330,14 @@ def evaluate( ) prop_dictionary[0][theme_id]["evaluation"] = Evaluation.NO_PREDICTION_5 continue - #Add all predicted features so they can be manually checked - for dist in dict_predicted_keys[theme_id].keys(): + # Add all predicted features so they can be manually checked + for dist in dict_predicted_keys[theme_id].keys(): predicted_resultset = dict_predicted[dist][theme_id] dict_evaluated_result[dist][theme_id] = predicted_resultset prop_dictionary[dist][theme_id]["formula"] = json.dumps( actual_aligner.get_formula(predicted_resultset["result"]) ) - prop_dictionary[dist][theme_id][ - "evaluation" - ] = Evaluation.TO_CHECK_4 + prop_dictionary[dist][theme_id]["evaluation"] = Evaluation.TO_CHECK_4 for theme_id, geom in dict_unchanged.items(): result = {"result": geom} @@ -349,6 +348,7 @@ def evaluate( ) return dict_evaluated_result, prop_dictionary + def check_equality( base_formula, actual_formula, threshold_area=5, threshold_percentage=1 ): @@ -373,21 +373,19 @@ def check_equality( elif base_formula["reference_od"] is None or actual_formula["reference_od"] is None: od_alike = False elif ( - ( - abs( - base_formula["reference_od"]["area"] - - actual_formula["reference_od"]["area"] - ) - * 100 - / base_formula["reference_od"]["area"] - ) - < threshold_percentage - ): + abs( + base_formula["reference_od"]["area"] + - actual_formula["reference_od"]["area"] + ) + * 100 + / base_formula["reference_od"]["area"] + ) < threshold_percentage: od_alike = True if ( base_formula["reference_features"].keys() - == actual_formula["reference_features"].keys() and od_alike + == actual_formula["reference_features"].keys() + and od_alike ): if base_formula["full"] and base_formula["full"]: return True, Evaluation.EQUALITY_FORMULA_GEOM_1 diff --git a/examples/example_evaluate.py b/examples/example_evaluate.py index 01dd55c..f32f43b 100644 --- a/examples/example_evaluate.py +++ b/examples/example_evaluate.py @@ -13,7 +13,6 @@ from brdr.utils import get_series_geojson_dict - def fid_to_geojson(geojson): fid = 1 for f in geojson["features"]: From 01779507c19365761348fb85700e40188d6c836e Mon Sep 17 00:00:00 2001 From: dieuska Date: Tue, 10 Sep 2024 11:08:29 +0200 Subject: [PATCH 3/3] black formatted --- brdr/loader.py | 2 +- examples/example_evaluate.py | 29 ++++++++++++-------- examples/example_evaluate_multi_to_single.py | 8 +++--- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/brdr/loader.py b/brdr/loader.py index d2e74ec..8242333 100644 --- a/brdr/loader.py +++ b/brdr/loader.py @@ -22,7 +22,7 @@ def load_data(self): class DictLoader(Loader): def __init__(self, data_dict: dict[str:BaseGeometry]): - #TODO: add dict_properties & dict_source? + # TODO: add dict_properties & dict_source? super().__init__() self.data_dict = data_dict diff --git a/examples/example_evaluate.py b/examples/example_evaluate.py index f32f43b..46aa494 100644 --- a/examples/example_evaluate.py +++ b/examples/example_evaluate.py @@ -16,14 +16,17 @@ def fid_to_geojson(geojson): fid = 1 for f in geojson["features"]: - f["properties"]["fid"]= str(fid) + f["properties"]["fid"] = str(fid) fid = fid + 1 if f["geometry"]["type"] == "Polygon": - f["geometry"]={"type":"MultiPolygon", - "coordinates": [f["geometry"]["coordinates"]]} - + f["geometry"] = { + "type": "MultiPolygon", + "coordinates": [f["geometry"]["coordinates"]], + } return geojson + + # # thematic_dict = { # "theme_id_1": from_wkt( @@ -102,7 +105,7 @@ def fid_to_geojson(geojson): for key in base_process_result: thematic_dict_result[key] = base_process_result[key]["result"] thematic_dict_formula[key] = base_aligner.get_formula(thematic_dict_result[key]) - print (key + ": "+thematic_dict_result[key].wkt) + print(key + ": " + thematic_dict_result[key].wkt) print(key + ": " + str(thematic_dict_formula[key])) base_aligner_result = Aligner() base_aligner_result.load_thematic_data(DictLoader(thematic_dict_result)) @@ -117,11 +120,13 @@ def fid_to_geojson(geojson): print("No affected dicts") exit() for key, value in dict_affected.items(): - print (key + ": "+ value.wkt) + print(key + ": " + value.wkt) actual_aligner = Aligner() loader = DictLoader(dict_affected) actual_aligner.load_thematic_data(DictLoader(dict_affected)) -actual_aligner.load_reference_data(GRBActualLoader(grb_type=GRBType.ADP, partition=1000, aligner=actual_aligner)) +actual_aligner.load_reference_data( + GRBActualLoader(grb_type=GRBType.ADP, partition=1000, aligner=actual_aligner) +) series = np.arange(0, 200, 10, dtype=int) / 100 dict_series, dict_predicted, diffs_dict = actual_aligner.predictor(series) @@ -148,11 +153,13 @@ def fid_to_geojson(geojson): print(fcs["result"]) for feature in fc["result"]["features"]: - print(feature["properties"][actual_aligner.name_thematic_id] + ": "+feature["properties"]["evaluation"]) + print( + feature["properties"][actual_aligner.name_thematic_id] + + ": " + + feature["properties"]["evaluation"] + ) geojson = fid_to_geojson(fc["result"]) -print (geojson) - - +print(geojson) diff --git a/examples/example_evaluate_multi_to_single.py b/examples/example_evaluate_multi_to_single.py index f26b9dd..3a68ca8 100644 --- a/examples/example_evaluate_multi_to_single.py +++ b/examples/example_evaluate_multi_to_single.py @@ -73,9 +73,9 @@ # } thematic_dict = get_oe_dict_by_ids([9946]) # Align the multipolygon to the fiscal parcels 2022 -#thematic_dict = multipolygons_to_singles(thematic_dict) +# thematic_dict = multipolygons_to_singles(thematic_dict) base_aligner = Aligner() -base_aligner.multi_as_single_modus=False +base_aligner.multi_as_single_modus = False base_aligner.load_thematic_data(DictLoader(thematic_dict)) base_year = "2022" base_aligner.load_reference_data( @@ -95,7 +95,7 @@ thematic_dict_result = multipolygons_to_singles(thematic_dict_result) # Determine all features that are possibly changed during timespan base_aligner_result = Aligner() -#base_aligner.multi_as_single_modus=False +# base_aligner.multi_as_single_modus=False base_aligner_result.load_thematic_data(DictLoader(thematic_dict_result)) dict_affected, dict_unchanged = get_geoms_affected_by_grb_change( base_aligner_result, @@ -106,7 +106,7 @@ ) # Align the possibly affected geometry on the actual GRB parcels (evaluation) -#dict_affected = multipolygons_to_singles(dict_affected) +# dict_affected = multipolygons_to_singles(dict_affected) actual_aligner = Aligner() loader = DictLoader(dict_affected) actual_aligner.load_thematic_data(loader)