|
44 | 44 | FileUtils, |
45 | 45 | CustomJsonEncoder, |
46 | 46 | todict, |
| 47 | + create_connectivity_raster, |
47 | 48 | ) |
48 | 49 |
|
49 | 50 |
|
@@ -2736,6 +2737,68 @@ def run_activities_cleaning(self, activities, extent=None, temporary_output=Fals |
2736 | 2737 |
|
2737 | 2738 | return True |
2738 | 2739 |
|
| 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 | + |
2739 | 2802 | def run_highest_position_analysis(self, temporary_output=False): |
2740 | 2803 | """Runs the highest position analysis which is last step |
2741 | 2804 | in scenario analysis. Uses the activities set by the current ongoing |
|
0 commit comments