Skip to content

Commit

Permalink
#102 only checking border of objects on changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dieuska committed Nov 28, 2024
1 parent 074c329 commit 8e95c52
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions brdr/geometry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ def geom_to_wkt(shapely_geometry):


def create_donut(geometry, distance):
if distance ==0:
return geometry
inner_geometry = buffer_neg(geometry, distance)
return safe_difference(geometry, inner_geometry)

Expand Down
19 changes: 13 additions & 6 deletions brdr/grb.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,10 @@ def get_affected_by_grb_change(

affected = []
unaffected = []
if border_distance > 0:
for key in dict_thematic.keys():
dict_thematic[key] = create_donut(dict_thematic[key], border_distance)
if one_by_one:
for key in dict_thematic:
geom = dict_thematic[key]
if is_grb_changed(geom, grb_type, date_start, date_end):
if is_grb_changed(geom, grb_type, date_start, date_end, border_distance=border_distance):
affected.append(key)
else:
unaffected.append(key)
Expand All @@ -136,11 +133,21 @@ def get_affected_by_grb_change(
dict_changed_grb, dict_changed_grb_properties = geojson_to_dicts(
coll_changed_grb, name_reference_id
)
if border_distance>0:
geom_to_check = create_donut(geometry_thematic_union,border_distance)
grb_intersections = features_by_geometric_operation(
list(dict_changed_grb.values()),
list(dict_changed_grb.keys()),
[geom_to_check],
predicate="intersects",
)
dict_changed_grb = {key: dict_changed_grb[key] for key in grb_intersections}


if len(dict_changed_grb) == 0:
logging.info("No detected changes")
logging.info(f"No detected changes for thematic geometry in timespan (border distance: {str(border_distance)})")
return affected, list(dict_thematic.keys()) # empty affected dict
logging.info("Changed parcels in timespan: " + str(len(dict_changed_grb)))
logging.info(f"Changed parcels in timespan with border_distance {str(border_distance)}: {str(len(dict_changed_grb))}")
thematic_intersections = features_by_geometric_operation(
list(dict_thematic.values()),
list(dict_thematic.keys()),
Expand Down
2 changes: 1 addition & 1 deletion brdr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def get_collection_by_partition(
dict: A collection of geographic data, potentially partitioned by the input geometry.
"""
collection = {}
if geometry is None:
if geometry is None or geometry.is_empty:
collection = get_collection(
_add_bbox_to_url(url=url, crs=crs, bbox=None), limit
)
Expand Down
1 change: 1 addition & 0 deletions examples/example_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
date_start=date(2022, 1, 1),
date_end=date.today(),
one_by_one=False,
border_distance=0
)
if len(affected) == 0:
print("No affected dicts")
Expand Down

0 comments on commit 8e95c52

Please sign in to comment.