Skip to content

Commit

Permalink
Merge pull request #61 from OnroerendErfgoed/main
Browse files Browse the repository at this point in the history
merge release 0.2.1 into development
  • Loading branch information
dieuska authored Sep 10, 2024
2 parents 902b24b + 97314d6 commit f1c6334
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 37 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion brdr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
datefmt="%d-%b-%y %H:%M:%S",
)

__version__ = "0.2.0"
__version__ = "0.2.1"
7 changes: 5 additions & 2 deletions brdr/geometry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
30 changes: 14 additions & 16 deletions brdr/grb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand All @@ -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
):
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion brdr/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 18 additions & 12 deletions examples/example_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
from brdr.utils import get_series_geojson_dict



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(
Expand Down Expand Up @@ -103,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))
Expand All @@ -118,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)

Expand All @@ -149,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)
8 changes: 4 additions & 4 deletions examples/example_evaluate_multi_to_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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" }
Expand All @@ -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",
]
Expand Down

0 comments on commit f1c6334

Please sign in to comment.