Skip to content

Commit 2e3e292

Browse files
authored
Creating Pixel connectivity layer
Create Pixel connectivity layer
2 parents 9bf128d + fe1a625 commit 2e3e292

File tree

4 files changed

+429
-1
lines changed

4 files changed

+429
-1
lines changed

src/cplus_plugin/tasks.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
FileUtils,
4545
CustomJsonEncoder,
4646
todict,
47+
create_connectivity_raster,
4748
)
4849

4950

@@ -2736,6 +2737,68 @@ def run_activities_cleaning(self, activities, extent=None, temporary_output=Fals
27362737

27372738
return True
27382739

2740+
def create_activity_connectivity_layer(self, activity: Activity) -> str | None:
2741+
"""Create an activity connectivity layer for investability analysis
2742+
2743+
:param activity: Activity
2744+
:type activity: Activity
2745+
2746+
:returns: The path to the connectivity layer or None if the process failed
2747+
:rtype: str | None
2748+
"""
2749+
if not activity.path:
2750+
self.log_message(
2751+
f"Problem when creating the connectivity layer, "
2752+
f"there is no map layer for the activity {activity.name}"
2753+
)
2754+
return None
2755+
2756+
if not os.path.exists(activity.path):
2757+
self.log_message(
2758+
f"Problem when creating the connectivity layer, "
2759+
f"the map layer for the activity {activity.name} does not exist"
2760+
)
2761+
return None
2762+
2763+
self.set_status_message(
2764+
tr(f"Creating connectivity layer for the activity: {activity.name}")
2765+
)
2766+
2767+
output_directory = os.path.join(
2768+
self.scenario_directory, "investable_activities"
2769+
)
2770+
FileUtils.create_new_dir(output_directory)
2771+
2772+
output_path = os.path.join(
2773+
f"{output_directory}",
2774+
f"{Path(activity.path).stem}_connectivity_{str(uuid.uuid4())[:4]}.tif",
2775+
)
2776+
2777+
try:
2778+
if self.processing_cancelled:
2779+
return None
2780+
2781+
ok, logs = create_connectivity_raster(activity.path, output_path)
2782+
2783+
if ok and os.path.exists(output_path):
2784+
return output_path
2785+
2786+
self.log_message(
2787+
f" Error creating the connectivity layer for activity {activity.name}, "
2788+
)
2789+
for log in logs:
2790+
self.log_message(tr(log))
2791+
2792+
return None
2793+
2794+
except Exception as e:
2795+
self.log_message(
2796+
f"Problem creating connectivity layer for activity, {e} \n"
2797+
)
2798+
self.log_message(traceback.format_exc())
2799+
self.cancel_task(e)
2800+
return None
2801+
27392802
def run_highest_position_analysis(self, temporary_output=False):
27402803
"""Runs the highest position analysis which is last step
27412804
in scenario analysis. Uses the activities set by the current ongoing

0 commit comments

Comments
 (0)