diff --git a/CHANGES.md b/CHANGES.md index 7248ff5..027f7c4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -40,7 +40,24 @@ - Bugfixing: - adding a safe_equals-function to catch GEOsException bug [#71] +# 0.4.0 +! Not Backwards compatable ! + +- Refactoring: + - Possibility for parallel processing [#97] + - Changed Aligner constants to init-settings [#83] + - Refactored ID-handling so strings,integers,... can be used as ID[#110] + - Cleaned examples [#100] + + - Functionalities: + - Added evaluation-attributes to evaluate()-function [#99] + - processing-remarks available in geojson-output [#103] + - Added warning when input/output changed from polygon/multipolygon [#107] + +- Bugfixing: + - Bugfix on version_date [#96] + - Bugfix on disappearing features [#105] diff --git a/brdr/__init__.py b/brdr/__init__.py index 493f741..6a9beea 100644 --- a/brdr/__init__.py +++ b/brdr/__init__.py @@ -1 +1 @@ -__version__ = "0.3.0" +__version__ = "0.4.0" diff --git a/brdr/aligner.py b/brdr/aligner.py index 3cd4aec..43c3536 100644 --- a/brdr/aligner.py +++ b/brdr/aligner.py @@ -623,10 +623,7 @@ def predictor( diffs_dict, ) - def evaluate( - self, - ids_to_evaluate=None, base_formula_field= FORMULA_FIELD_NAME - ): + def evaluate(self, ids_to_evaluate=None, base_formula_field=FORMULA_FIELD_NAME): """ Compares and evaluate input-geometries (with formula). Attributes are added to evaluate and decide if new @@ -657,7 +654,7 @@ def evaluate( props = self._evaluate( id_theme=theme_id, geom_predicted=dict_predictions_results[dist]["result"], - base_formula_field=base_formula_field, + base_formula_field=base_formula_field, ) dict_predictions_evaluated[theme_id][dist] = dict_affected_predictions[ theme_id @@ -670,7 +667,11 @@ def evaluate( for theme_id, geom in dict_unaffected.items(): dict_predictions_evaluated[theme_id] = {} prop_dictionary[theme_id] = {relevant_distance: {}} - props = self._evaluate(id_theme=theme_id, geom_predicted=geom,base_formula_field=base_formula_field) + props = self._evaluate( + id_theme=theme_id, + geom_predicted=geom, + base_formula_field=base_formula_field, + ) props[EVALUATION_FIELD_NAME] = Evaluation.NO_CHANGE_6 dict_predictions_evaluated[theme_id][relevant_distance] = {"result": geom} prop_dictionary[theme_id][relevant_distance] = props @@ -840,9 +841,9 @@ def get_results_as_geojson( ): # and not (theme_id in prop_dictionary and relevant_distance in prop_dictionary[theme_id] and NEW_FORMULA_FIELD_NAME in prop_dictionary[theme_id][relevant_distance]): result = process_results["result"] formula = self.get_brdr_formula(result) - prop_dictionary[theme_id][relevant_distance][ - FORMULA_FIELD_NAME - ] = json.dumps(formula) + prop_dictionary[theme_id][relevant_distance][FORMULA_FIELD_NAME] = ( + json.dumps(formula) + ) return get_series_geojson_dict( dict_series, crs=self.CRS, @@ -1354,7 +1355,9 @@ def _postprocess_preresult( "remark": remark, } - def _evaluate(self, id_theme, geom_predicted,base_formula_field=FORMULA_FIELD_NAME): + def _evaluate( + self, id_theme, geom_predicted, base_formula_field=FORMULA_FIELD_NAME + ): """ function that evaluates a predicted geometry and returns a properties-dictionary """ diff --git a/brdr/constants.py b/brdr/constants.py index d3d0508..4fbdfb1 100644 --- a/brdr/constants.py +++ b/brdr/constants.py @@ -8,7 +8,9 @@ MULTI_SINGLE_ID_SEPARATOR = "*$*" PREFIX_FIELDNAME = "brdr_" -BASE_FORMULA_FIELD_NAME = PREFIX_FIELDNAME + "base_formula"# for use in grb_actualisation +BASE_FORMULA_FIELD_NAME = ( + PREFIX_FIELDNAME + "base_formula" +) # for use in grb_actualisation FORMULA_FIELD_NAME = PREFIX_FIELDNAME + "formula" EVALUATION_FIELD_NAME = PREFIX_FIELDNAME + "evaluation" DIFF_PERCENTAGE_FIELD_NAME = PREFIX_FIELDNAME + "diff_percentage" diff --git a/brdr/geometry_utils.py b/brdr/geometry_utils.py index 2840522..89b1aaa 100644 --- a/brdr/geometry_utils.py +++ b/brdr/geometry_utils.py @@ -23,7 +23,7 @@ from shapely.prepared import prep -def buffer_neg_pos(geometry, buffer_value,mitre_limit=5): +def buffer_neg_pos(geometry, buffer_value, mitre_limit=5): """ Computes two buffers accordingly: one with a negative buffer value and another with a positive buffer value. This function can be used the check where relevant areas @@ -56,18 +56,18 @@ def buffer_neg_pos(geometry, buffer_value,mitre_limit=5): buffer( geometry, -buffer_value, - #quad_segs=QUAD_SEGMENTS, + # quad_segs=QUAD_SEGMENTS, join_style="mitre", mitre_limit=mitre_limit, ), buffer_value, - #quad_segs=QUAD_SEGMENTS, + # quad_segs=QUAD_SEGMENTS, join_style="mitre", mitre_limit=mitre_limit, ) -def buffer_neg(geometry, buffer_value,mitre_limit=5): +def buffer_neg(geometry, buffer_value, mitre_limit=5): """ Computes the negative buffer of a given geometric object. @@ -94,13 +94,13 @@ def buffer_neg(geometry, buffer_value,mitre_limit=5): return buffer( geometry, -buffer_value, - #quad_segs=QUAD_SEGMENTS, + # quad_segs=QUAD_SEGMENTS, join_style="mitre", mitre_limit=mitre_limit, ) -def buffer_pos(geometry, buffer_value,mitre_limit=5): +def buffer_pos(geometry, buffer_value, mitre_limit=5): """ Computes the positive buffer of a given geometric object. @@ -127,7 +127,7 @@ def buffer_pos(geometry, buffer_value,mitre_limit=5): return buffer( geometry, buffer_value, - #quad_segs=QUAD_SEGMENTS, + # quad_segs=QUAD_SEGMENTS, join_style="mitre", mitre_limit=mitre_limit, ) @@ -506,9 +506,11 @@ def fill_and_remove_gaps(input_geometry, buffer_value): ix_part = ix_part + 1 return cleaned_geometry + def safe_unary_union(geometries): return make_valid(unary_union(geometries)) + def get_bbox(geometry): """ Get the BBOX (string) of a shapely geometry diff --git a/brdr/grb.py b/brdr/grb.py index c85fe59..56a34c1 100644 --- a/brdr/grb.py +++ b/brdr/grb.py @@ -14,7 +14,8 @@ LAST_VERSION_DATE, DATE_FORMAT, VERSION_DATE, - FORMULA_FIELD_NAME, BASE_FORMULA_FIELD_NAME, + FORMULA_FIELD_NAME, + BASE_FORMULA_FIELD_NAME, ) from brdr.constants import DOWNLOAD_LIMIT from brdr.constants import GRB_BUILDING_ID @@ -434,7 +435,9 @@ def update_to_actual_grb( actual_aligner.relevant_distances = ( np.arange(0, max_distance_for_actualisation * 100, 10, dtype=int) / 100 ) - dict_evaluated, prop_dictionary = actual_aligner.evaluate(ids_to_evaluate=affected,base_formula_field=BASE_FORMULA_FIELD_NAME) + dict_evaluated, prop_dictionary = actual_aligner.evaluate( + ids_to_evaluate=affected, base_formula_field=BASE_FORMULA_FIELD_NAME + ) return actual_aligner.get_results_as_geojson( resulttype=AlignerResultType.EVALUATED_PREDICTIONS, diff --git a/brdr/loader.py b/brdr/loader.py index 29a78a5..dc00c22 100644 --- a/brdr/loader.py +++ b/brdr/loader.py @@ -36,7 +36,9 @@ def load_data(self): ], DATE_FORMAT, ) - self.data_dict_properties[key][VERSION_DATE] = datetime.strftime(date,DATE_FORMAT) + self.data_dict_properties[key][VERSION_DATE] = datetime.strftime( + date, DATE_FORMAT + ) return self.data_dict, self.data_dict_properties, self.data_dict_source diff --git a/examples/example_evaluate.py b/examples/example_evaluate.py index 28f2cde..520f711 100644 --- a/examples/example_evaluate.py +++ b/examples/example_evaluate.py @@ -16,61 +16,77 @@ """ EXAMPLE of the 'evaluate()-function of 'brdr': This function evaluates thematic objects with a former brdr_formula and compares them with an actual formula; and adds evaluation-properties to the result """ - #initiate a base Aligner, to align thematic objects on an older version of the parcels (year 2022) + # initiate a base Aligner, to align thematic objects on an older version of the parcels (year 2022) base_aligner = Aligner() - #Load thematic data + # Load thematic data loader = GeoJsonFileLoader("themelayer.geojson", "theme_identifier") base_aligner.load_thematic_data(loader) base_year = "2022" name_formula = "base_formula" - #Load reference data + # Load reference data base_aligner.load_reference_data( GRBFiscalParcelLoader(year=base_year, aligner=base_aligner) ) relevant_distance = 2 - #Align the thematic object on the parcelborders of 2022, to simulate a base-situation + # Align the thematic object on the parcelborders of 2022, to simulate a base-situation base_process_result = base_aligner.process(relevant_distance=2) - #Collect the base-situation (base-geometries and the brdr_formula from that moment + # Collect the base-situation (base-geometries and the brdr_formula from that moment thematic_dict_formula = {} thematic_dict_result = {} for key in base_process_result: - thematic_dict_result[key] = base_process_result[key][relevant_distance]["result"] + thematic_dict_result[key] = base_process_result[key][relevant_distance][ + "result" + ] thematic_dict_formula[key] = { - name_formula: json.dumps(base_aligner.get_brdr_formula(thematic_dict_result[key])) + name_formula: json.dumps( + base_aligner.get_brdr_formula(thematic_dict_result[key]) + ) } print(key + ": " + thematic_dict_result[key].wkt) print(key + ": " + str(thematic_dict_formula[key])) - #(OPTIONAL) Check for changes in the period 2022-now of the reference-parcels (GRB/Flanders-specific function) + # (OPTIONAL) Check for changes in the period 2022-now of the reference-parcels (GRB/Flanders-specific function) affected, unaffected = get_affected_by_grb_change( - dict_thematic = thematic_dict_result, + dict_thematic=thematic_dict_result, grb_type=GRBType.ADP, date_start=date(2022, 1, 1), date_end=date.today(), one_by_one=False, ) - if len(affected)==0: + if len(affected) == 0: print("No affected dicts") exit() print("Affected_IDs: " + str(affected)) - #Start an aligner to align thematic objects on the actual parcels + # Start an aligner to align thematic objects on the actual parcels actual_aligner = Aligner(relevant_distances=np.arange(0, 200, 10, dtype=int) / 100) - #Load the thematic objects (aligned on 2022) and also give the brdr_formula from 2022 as property + # Load the thematic objects (aligned on 2022) and also give the brdr_formula from 2022 as property actual_aligner.load_thematic_data( - DictLoader(data_dict=thematic_dict_result, data_dict_properties=thematic_dict_formula) + DictLoader( + data_dict=thematic_dict_result, data_dict_properties=thematic_dict_formula + ) ) - #Load reference data; the actual parcels + # Load reference data; the actual parcels actual_aligner.load_reference_data( GRBActualLoader(grb_type=GRBType.ADP, partition=1000, aligner=actual_aligner) ) - #Use the EVALUATE-function - dict_evaluated, prop_dictionary = actual_aligner.evaluate(ids_to_evaluate=affected,base_formula_field=name_formula) + # Use the EVALUATE-function + dict_evaluated, prop_dictionary = actual_aligner.evaluate( + ids_to_evaluate=affected, base_formula_field=name_formula + ) # SHOW the EVALUATED results - fc = actual_aligner.get_results_as_geojson(resulttype=AlignerResultType.EVALUATED_PREDICTIONS,formula=True, attributes=True) + fc = actual_aligner.get_results_as_geojson( + resulttype=AlignerResultType.EVALUATED_PREDICTIONS, + formula=True, + attributes=True, + ) print(fc["result"]) for feature in fc["result"]["features"]: - print(feature["properties"][actual_aligner.name_thematic_id] + ": " + feature["properties"][EVALUATION_FIELD_NAME]) + print( + feature["properties"][actual_aligner.name_thematic_id] + + ": " + + feature["properties"][EVALUATION_FIELD_NAME] + ) diff --git a/examples/example_geojsonloader.py b/examples/example_geojsonloader.py index 3f61590..4ae7adf 100644 --- a/examples/example_geojsonloader.py +++ b/examples/example_geojsonloader.py @@ -9,7 +9,6 @@ #EXAMPLE of a Geojson, aligned by 'brdr' """ - # Initiate brdr aligner = Aligner() # Load thematic data @@ -56,7 +55,7 @@ # Example how to use the Aligner dict_results = aligner.process(relevant_distance=6) - #show results + # show results aligner.save_results("output/") show_map(dict_results, aligner.dict_thematic, aligner.dict_reference) print_brdr_formula(dict_results, aligner) diff --git a/examples/example_grbspecificloader.py b/examples/example_grbspecificloader.py index 4cf151e..1fb7cbb 100644 --- a/examples/example_grbspecificloader.py +++ b/examples/example_grbspecificloader.py @@ -15,8 +15,8 @@ "Polygon ((172283.76869662097305991 174272.85233648214489222, 172276.89871930953813717 174278.68436246179044247, 172274.71383684969623573 174280.57171753142029047, 172274.63047763772192411 174280.64478165470063686, 172272.45265833073062822 174282.52660570573061705, 172269.33533191855531186 174285.22093996312469244, 172265.55258252174826339 174288.49089696351438761, 172258.77032718938426115 174294.22654021997004747, 172258.63259260458289646 174294.342757155187428, 172254.93673790179309435 174288.79932878911495209, 172248.71360730109154247 174279.61860501393675804, 172248.96566232520854101 174279.43056782521307468, 172255.25363882273086347 174274.73737183399498463, 172257.08298882702365518 174273.37133203260600567, 172259.32325354730710387 174271.69890458136796951, 172261.65807284769834951 174269.9690355472266674, 172266.35596220899606124 174266.4871726930141449, 172273.34350050613284111 174261.30863015633076429, 172289.60360219911672175 174249.35944479051977396, 172293.30328181147342548 174246.59864199347794056, 172297.34760522318538278 174253.10583685990422964, 172289.53060952731175348 174259.6846851697191596, 172292.86485871637705714 174265.19099397677928209, 172283.76869662097305991 174272.85233648214489222))" ) } - #EXAMPLE to use a GRBSpecificLoader, that retrieves the parcels for a specific data, based on the 2 fiscal parcel-situations of the year before and after - #Based on the date, the referencelayer will be different + # EXAMPLE to use a GRBSpecificLoader, that retrieves the parcels for a specific data, based on the 2 fiscal parcel-situations of the year before and after + # Based on the date, the referencelayer will be different date = "2023-05-03" date = "2023-08-03" loader = DictLoader(thematic_dict) @@ -31,4 +31,3 @@ inputtype=AlignerInputType.REFERENCE, ) write_geojson(os.path.join("output/", "grb_adp_" + date + ".geojson"), fc) - diff --git a/examples/example_onroerenderfgoed.py b/examples/example_onroerenderfgoed.py index 9ddd800..c862786 100644 --- a/examples/example_onroerenderfgoed.py +++ b/examples/example_onroerenderfgoed.py @@ -11,7 +11,7 @@ # Initiate brdr aligner = Aligner() # Load thematic data from Onroerend Erfgoed - loader = OnroerendErfgoedLoader( objectids = [131635] , oetype=OEType.AO) + loader = OnroerendErfgoedLoader(objectids=[131635], oetype=OEType.AO) aligner.load_thematic_data(loader) # Load reference data: The actual GRB-parcels loader = GRBActualLoader(grb_type=GRBType.ADP, partition=1000, aligner=aligner) diff --git a/examples/example_parcel_change_detector.py b/examples/example_parcel_change_detector.py index b1d9b8c..375d915 100644 --- a/examples/example_parcel_change_detector.py +++ b/examples/example_parcel_change_detector.py @@ -2,7 +2,11 @@ from datetime import datetime from brdr.aligner import Aligner -from brdr.constants import EVALUATION_FIELD_NAME, RELEVANT_DISTANCE_FIELD_NAME, FORMULA_FIELD_NAME +from brdr.constants import ( + EVALUATION_FIELD_NAME, + RELEVANT_DISTANCE_FIELD_NAME, + FORMULA_FIELD_NAME, +) from brdr.grb import GRBFiscalParcelLoader from brdr.grb import update_to_actual_grb from brdr.oe import OnroerendErfgoedLoader @@ -49,7 +53,7 @@ + str(len(base_aligner.dict_thematic)) ) base_aligner.load_reference_data( - GRBFiscalParcelLoader(year=base_year, aligner=base_aligner,partition=1000) + GRBFiscalParcelLoader(year=base_year, aligner=base_aligner, partition=1000) ) print("Reference-data loaded") # Exclude objects bigger than specified area @@ -59,9 +63,7 @@ if base_aligner.dict_thematic[key].area > excluded_area: keys_to_exclude.append(key) counter_excluded = counter_excluded + 1 - print( - "geometrie excluded; bigger than " + str(excluded_area) + ": " + key - ) + print("geometrie excluded; bigger than " + str(excluded_area) + ": " + key) for x in keys_to_exclude: del base_aligner.dict_thematic[x] @@ -85,15 +87,17 @@ max_distance_for_actualisation=max_distance_for_actualisation, ) -write_geojson(os.path.join("output/", "parcel_change_detector_with.geojson"), fcs["result"]) +write_geojson( + os.path.join("output/", "parcel_change_detector_with.geojson"), fcs["result"] +) counter_equality = 0 counter_equality_by_alignment = 0 counter_difference = 0 counter_no_change = 0 -#TODO: counter_difference collects al the 'TO_CHECK's' but these are multiple proposals, so clean up the stats -#TODO: Move this as general output from the updater? +# TODO: counter_difference collects al the 'TO_CHECK's' but these are multiple proposals, so clean up the stats +# TODO: Move this as general output from the updater? for feature in fcs["result"]["features"]: if EVALUATION_FIELD_NAME in feature["properties"].keys(): ev = feature["properties"][EVALUATION_FIELD_NAME] @@ -104,7 +108,7 @@ elif ev.startswith("equal") and rd > 0: counter_equality_by_alignment = counter_equality_by_alignment + 1 elif ev.startswith("no_change"): - counter_no_change= counter_no_change + 1 + counter_no_change = counter_no_change + 1 else: counter_difference = counter_difference + 1 diff --git a/examples/example_parcel_vs_building.py b/examples/example_parcel_vs_building.py index 2003b75..ffc07c7 100644 --- a/examples/example_parcel_vs_building.py +++ b/examples/example_parcel_vs_building.py @@ -37,9 +37,13 @@ # Example how to use a series (for histogram) series = np.arange(0, 300, 10, dtype=int) / 100 - x_dict_series = aligner_x.process(relevant_distances=series, od_strategy=4, threshold_overlap_percentage=50) + x_dict_series = aligner_x.process( + relevant_distances=series, od_strategy=4, threshold_overlap_percentage=50 + ) x_resulting_areas = diffs_from_dict_series(x_dict_series, aligner_x.dict_thematic) - y_dict_series = aligner_y.process(relevant_distances=series, od_strategy=4, threshold_overlap_percentage=50) + y_dict_series = aligner_y.process( + relevant_distances=series, od_strategy=4, threshold_overlap_percentage=50 + ) y_resulting_areas = diffs_from_dict_series(y_dict_series, aligner_y.dict_thematic) # plot_diffs(series,x_resulting_areas) # plot_diffs(series,y_resulting_areas) diff --git a/examples/example_predictor.py b/examples/example_predictor.py index 29127c4..276cc04 100644 --- a/examples/example_predictor.py +++ b/examples/example_predictor.py @@ -24,22 +24,24 @@ loader = GRBActualLoader(grb_type=GRBType.ADP, partition=1000, aligner=aligner) aligner.load_reference_data(loader) - #PREDICT the 'stable' relevant distances, for a series of relevant distances + # PREDICT the 'stable' relevant distances, for a series of relevant distances series = np.arange(0, 300, 10, dtype=int) / 100 # predict which relevant distances are interesting to propose as resulting geometry dict_series, dict_predictions, diffs = aligner.predictor( - relevant_distances=series, od_strategy=OpenbaarDomeinStrategy.SNAP_FULL_AREA_ALL_SIDE, threshold_overlap_percentage=50 + relevant_distances=series, + od_strategy=OpenbaarDomeinStrategy.SNAP_FULL_AREA_ALL_SIDE, + threshold_overlap_percentage=50, ) - #SHOW results of the predictions + # SHOW results of the predictions fcs = aligner.get_results_as_geojson( resulttype=AlignerResultType.PREDICTIONS, formula=False ) print(fcs["result"]) for key in dict_predictions: - plot_series(series, {key:diffs[key]}) + plot_series(series, {key: diffs[key]}) show_map( - {key:dict_predictions[key]}, + {key: dict_predictions[key]}, {key: aligner.dict_thematic[key]}, aligner.dict_reference, ) diff --git a/pyproject.toml b/pyproject.toml index 057bcc2..11cbb85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "brdr" -version = "0.3.0" +version = "0.4.0" 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" } diff --git a/tests/test_aligner.py b/tests/test_aligner.py index 7a48fa4..82e212b 100644 --- a/tests/test_aligner.py +++ b/tests/test_aligner.py @@ -272,7 +272,7 @@ def test_process_interior_ring(self): def test_process_circle(self): geometry = Point(0, 0).buffer(3) - #geometry = MultiPolygon([geometry]) + # geometry = MultiPolygon([geometry]) thematic_dict = {"key": geometry} self.sample_aligner.load_thematic_data(DictLoader(thematic_dict)) # LOAD REFERENCE DICTIONARY @@ -346,14 +346,12 @@ def test_fully_aligned_input(self): self.sample_aligner.load_reference_data(DictLoader({"ref_id_1": aligned_shape})) relevant_distance = 1 result = self.sample_aligner.process(relevant_distance=relevant_distance) - assert equals(result["theme_id_1"][relevant_distance].get("result"),aligned_shape) - assert result["theme_id_1"][relevant_distance].get("result_diff").is_empty - assert ( - result["theme_id_1"][relevant_distance].get("result_diff_min").is_empty - ) - assert ( - result["theme_id_1"][relevant_distance].get("result_diff_plus").is_empty + assert equals( + result["theme_id_1"][relevant_distance].get("result"), aligned_shape ) + assert result["theme_id_1"][relevant_distance].get("result_diff").is_empty + assert result["theme_id_1"][relevant_distance].get("result_diff_min").is_empty + assert result["theme_id_1"][relevant_distance].get("result_diff_plus").is_empty def test_evaluate(self): thematic_dict = { @@ -380,8 +378,8 @@ def test_evaluate(self): "result" ] thematic_dict_formula[key] = { - FORMULA_FIELD_NAME: json.dumps(base_aligner.get_brdr_formula( - thematic_dict_result[key]) + FORMULA_FIELD_NAME: json.dumps( + base_aligner.get_brdr_formula(thematic_dict_result[key]) ) } print(key + ": " + thematic_dict_result[key].wkt) @@ -413,7 +411,7 @@ def test_evaluate(self): ) actual_aligner.relevant_distances = np.arange(0, 200, 10, dtype=int) / 100 dict_evaluated, prop_dictionary = actual_aligner.evaluate( - ids_to_evaluate=affected,base_formula_field=FORMULA_FIELD_NAME + ids_to_evaluate=affected, base_formula_field=FORMULA_FIELD_NAME ) fc = get_series_geojson_dict( @@ -427,15 +425,16 @@ def test_evaluate(self): def test_remark_for_poly_multipoly(self): shape = from_wkt( - "MultiPolygon(((48893.03662109375 214362.93756103515625, 48890.8258056640625 214368.482666015625, 48890.7159423828125 214368.44110107421875, 48887.6488037109375 214367.2845458984375, 48886.3800048828125 214368.68017578125, 48885.1068115234375 214370.08062744140625, 48884.3330078125 214369.782470703125, 48882.563720703125 214369.10064697265625, 48882.1116943359375 214370.1346435546875, 48878.5626220703125 214368.70196533203125, 48877.839111328125 214368.40997314453125, 48877.2352294921875 214369.79376220703125, 48876.7911376953125 214369.60687255859375, 48875.0850830078125 214373.62353515625, 48875.478759765625 214373.8182373046875, 48881.5286865234375 214376.81109619140625, 48885.10546875 214372.36151123046875, 48887.0050048828125 214370.08538818359375, 48888.4698486328125 214368.330078125, 48890.366943359375 214369.2685546875, 48901.0638427734375 214374.56024169921875, 48905.0159912109375 214369.61175537109375, 48904.472900390625 214367.53851318359375, 48893.03662109375 214362.93756103515625)))") - self.sample_aligner.load_thematic_data( - DictLoader({"theme_id_1": shape}) + "MultiPolygon(((48893.03662109375 214362.93756103515625, 48890.8258056640625 214368.482666015625, 48890.7159423828125 214368.44110107421875, 48887.6488037109375 214367.2845458984375, 48886.3800048828125 214368.68017578125, 48885.1068115234375 214370.08062744140625, 48884.3330078125 214369.782470703125, 48882.563720703125 214369.10064697265625, 48882.1116943359375 214370.1346435546875, 48878.5626220703125 214368.70196533203125, 48877.839111328125 214368.40997314453125, 48877.2352294921875 214369.79376220703125, 48876.7911376953125 214369.60687255859375, 48875.0850830078125 214373.62353515625, 48875.478759765625 214373.8182373046875, 48881.5286865234375 214376.81109619140625, 48885.10546875 214372.36151123046875, 48887.0050048828125 214370.08538818359375, 48888.4698486328125 214368.330078125, 48890.366943359375 214369.2685546875, 48901.0638427734375 214374.56024169921875, 48905.0159912109375 214369.61175537109375, 48904.472900390625 214367.53851318359375, 48893.03662109375 214362.93756103515625)))" + ) + self.sample_aligner.load_thematic_data(DictLoader({"theme_id_1": shape})) + self.sample_aligner.load_reference_data( + GRBActualLoader( + grb_type=GRBType.ADP, partition=1000, aligner=self.sample_aligner + ) ) - self.sample_aligner.load_reference_data(GRBActualLoader( grb_type=GRBType.ADP, partition=1000, aligner=self.sample_aligner - )) self.sample_aligner.process(relevant_distances=[2]) - assert self.sample_aligner.dict_processresults["theme_id_1"][2]["remark"]!="" - + assert self.sample_aligner.dict_processresults["theme_id_1"][2]["remark"] != "" def test_fully_aligned_geojson_output(self): aligned_shape = from_wkt( diff --git a/tests/test_grb.py b/tests/test_grb.py index 0998d48..98e911d 100644 --- a/tests/test_grb.py +++ b/tests/test_grb.py @@ -101,7 +101,7 @@ def test_get_geoms_affected_by_grb_change(self): } aligner = Aligner() aligner.load_thematic_data(DictLoader(thematic_dict)) - affected,unaffected = get_affected_by_grb_change( + affected, unaffected = get_affected_by_grb_change( dict_thematic=thematic_dict, grb_type=GRBType.ADP, date_start=date.today() - timedelta(days=1), @@ -110,7 +110,7 @@ def test_get_geoms_affected_by_grb_change(self): ) assert len(affected) == 0 - affected,unaffected = get_affected_by_grb_change( + affected, unaffected = get_affected_by_grb_change( dict_thematic=thematic_dict, grb_type=GRBType.ADP, date_start=date.today() - timedelta(days=1000), @@ -130,7 +130,7 @@ def test_get_geoms_affected_by_grb_change(self): } aligner2 = Aligner() aligner2.load_thematic_data(DictLoader(thematic_dict2)) - affected,unaffected = get_affected_by_grb_change( + affected, unaffected = get_affected_by_grb_change( dict_thematic=thematic_dict2, grb_type=GRBType.ADP, date_start=date.today() - timedelta(days=1000), @@ -152,7 +152,7 @@ def test_get_geoms_affected_by_grb_change_bulk(self): } aligner = Aligner() aligner.load_thematic_data(DictLoader(thematic_dict)) - affected,unaffected = get_affected_by_grb_change( + affected, unaffected = get_affected_by_grb_change( dict_thematic=thematic_dict, grb_type=GRBType.ADP, date_start=date.today() - timedelta(days=1), @@ -161,7 +161,7 @@ def test_get_geoms_affected_by_grb_change_bulk(self): ) assert len(affected) == 0 - affected,unaffected = get_affected_by_grb_change( + affected, unaffected = get_affected_by_grb_change( dict_thematic=thematic_dict, grb_type=GRBType.ADP, date_start=date.today() - timedelta(days=1000), @@ -233,7 +233,9 @@ def test_update_to_actual_grb(self): # Update Featurecollection to actual version featurecollection = update_to_actual_grb( - featurecollection_base_result, name_thematic_id,base_formula_field="brdr_base_formula" + featurecollection_base_result, + name_thematic_id, + base_formula_field="brdr_base_formula", ) # Print results for feature in featurecollection["result"]["features"]: diff --git a/tests/test_integration.py b/tests/test_integration.py index 1da1a90..c5489c0 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -55,7 +55,11 @@ def test_webservice_brdr(self): series = np.arange(0, 61, 1, dtype=float) / 10 - dict_series = aligner.process(relevant_distances=series, od_strategy=openbaardomein_strategy, threshold_overlap_percentage=50) + dict_series = aligner.process( + relevant_distances=series, + od_strategy=openbaardomein_strategy, + threshold_overlap_percentage=50, + ) dict_diffs = diffs_from_dict_series( dict_series, aligner.dict_thematic, DiffMetric.CHANGES_AREA ) diff --git a/tests/test_utils.py b/tests/test_utils.py index bc185cc..0e7e175 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -8,6 +8,7 @@ from brdr.oe import get_oe_dict_by_ids from brdr.typings import ProcessResult from brdr.utils import diffs_from_dict_series + # from brdr.utils import filter_dict_by_key from brdr.utils import get_breakpoints_zerostreak from brdr.utils import get_collection @@ -41,26 +42,26 @@ def test_get_breakpoints_zerostreak_no_zerostreaks(self): def test_multipolygons_to_singles_empty_dict(self): data = {} - result,dict_multi_as_single = multipolygons_to_singles(data) + result, dict_multi_as_single = multipolygons_to_singles(data) self.assertEqual(result, {}) def test_multipolygons_to_singles_with_point(self): geometry1 = shapely.geometry.Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]) geometry2 = shapely.geometry.Point(0, 0) data = {"test_id1": geometry1, "test_id2": geometry2} - result,dict_multi_as_single = multipolygons_to_singles(data) + result, dict_multi_as_single = multipolygons_to_singles(data) self.assertEqual(result, {"test_id1": geometry1}) def test_multipolygons_to_singles_single_polygon(self): geometry = shapely.geometry.Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]) data = {"test_id": geometry} - result,dict_multi_as_single = multipolygons_to_singles(data) + result, dict_multi_as_single = multipolygons_to_singles(data) self.assertEqual(result, data) def test_multipolygons_to_singles_multipolygon_single_poly(self): geometry = shapely.geometry.Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]) data = {"test_id": shapely.geometry.MultiPolygon([geometry])} - result,dict_multi_as_single = multipolygons_to_singles(data) + result, dict_multi_as_single = multipolygons_to_singles(data) self.assertEqual(result, {"test_id": geometry}) def test_polygonize_reference_data_no_overlap(self): @@ -168,7 +169,7 @@ def test_merge_process_results(self): key_1 = "key" + MULTI_SINGLE_ID_SEPARATOR + "1" key_2 = "key" + MULTI_SINGLE_ID_SEPARATOR + "2" key_3 = "key_3" - dict_multi_as_single = {key_1:"key",key_2:"key"} + dict_multi_as_single = {key_1: "key", key_2: "key"} process_result_1 = ProcessResult() process_result_1["result"] = Polygon([(0, 0), (10, 0), (10, 10), (0, 10)]) process_result_2 = ProcessResult() @@ -180,5 +181,7 @@ def test_merge_process_results(self): key_2: {0: process_result_2}, key_3: {0: process_result_3}, } - merged_testdict = merge_process_results(result_dict=testdict,dict_multi_as_single = dict_multi_as_single) + merged_testdict = merge_process_results( + result_dict=testdict, dict_multi_as_single=dict_multi_as_single + ) assert len(merged_testdict.keys()) == 2