Ejemplo n.º 1
0
    def init_analysis(self):
        """Setup analysis to make it ready to work.

        .. note:: Copied or adapted from the dock
        """
        self.analysis = Analysis()

        # Impact Function
        impact_function = self.impact_function_manager.get(
            self.parent.selected_function()['id'])
        impact_function.parameters = self.parent.if_params
        self.analysis.impact_function = impact_function

        # Layers
        self.analysis.hazard = self.parent.hazard_layer
        self.analysis.exposure = self.parent.exposure_layer
        self.analysis.aggregation = self.parent.aggregation_layer
        # TODO test if the implement aggregation layer works!

        # Variables
        self.analysis.clip_hard = self.clip_hard
        self.analysis.show_intermediate_layers = self.show_intermediate_layers
        viewport = viewport_geo_array(self.iface.mapCanvas())
        self.analysis.viewport_extent = viewport

        # Extent
        if self.analysis.user_extent:
            self.analysis.user_extent = self.extent.user_extent
            self.analysis.user_extent_crs = self.extent.user_extent_crs
Ejemplo n.º 2
0
    def setup_analysis(self):
        """Setup analysis to make it ready to work.

        .. note:: Copied or adapted from the dock
        """
        # Impact Function
        self.impact_function = self.impact_function_manager.get(
            self.parent.step_fc_function.selected_function()['id'])
        self.impact_function.parameters = self.parent.step_fc_summary.if_params

        # Layers
        self.impact_function.hazard = self.parent.hazard_layer
        self.impact_function.exposure = self.parent.exposure_layer
        self.impact_function.aggregation = self.parent.aggregation_layer
        # TODO test if the implement aggregation layer works!

        # Variables
        self.impact_function.clip_hard = self.clip_hard
        self.impact_function.show_intermediate_layers = \
            self.show_intermediate_layers
        viewport = viewport_geo_array(self.iface.mapCanvas())
        self.impact_function.viewport_extent = viewport

        # Extent
        if self.impact_function.requested_extent:
            extent = self.extent
            self.impact_function.requested_extent = extent.user_extent
            self.impact_function.requested_extent_crs = extent.user_extent_crs
Ejemplo n.º 3
0
    def setup_analysis(self):
        """Setup analysis to make it ready to work.

        .. note:: Copied or adapted from the dock
        """
        # Impact Function
        self.impact_function = self.impact_function_manager.get(
            self.parent.step_fc_function.selected_function()['id'])
        self.impact_function.parameters = self.parent.step_fc_summary.if_params

        # Layers
        self.impact_function.hazard = self.parent.hazard_layer
        self.impact_function.exposure = self.parent.exposure_layer
        self.impact_function.aggregation = self.parent.aggregation_layer
        # TODO test if the implement aggregation layer works!

        # Variables
        self.impact_function.clip_hard = self.clip_hard
        self.impact_function.show_intermediate_layers = \
            self.show_intermediate_layers
        viewport = viewport_geo_array(self.iface.mapCanvas())
        self.impact_function.viewport_extent = viewport

        # Extent
        if self.impact_function.requested_extent:
            extent = self.extent
            self.impact_function.requested_extent = extent.user_extent
            self.impact_function.requested_extent_crs = extent.user_extent_crs
Ejemplo n.º 4
0
    def init_analysis(self):
        """Setup analysis to make it ready to work.

        .. note:: Copied or adapted from the dock
        """
        self.analysis = Analysis()

        # Impact Function
        impact_function = self.impact_function_manager.get(
            self.parent.selected_function()['id'])
        impact_function.parameters = self.parent.if_params
        self.analysis.impact_function = impact_function

        # Layers
        self.analysis.hazard = self.parent.hazard_layer
        self.analysis.exposure = self.parent.exposure_layer
        self.analysis.aggregation = self.parent.aggregation_layer
        # TODO test if the implement aggregation layer works!

        # Variables
        self.analysis.clip_hard = self.clip_hard
        self.analysis.show_intermediate_layers = self.show_intermediate_layers
        viewport = viewport_geo_array(self.iface.mapCanvas())
        self.analysis.viewport_extent = viewport

        # Extent
        if self.analysis.user_extent:
            self.analysis.user_extent = self.extent.user_extent
            self.analysis.user_extent_crs = self.extent.user_extent_crs
Ejemplo n.º 5
0
 def update_extent(self):
     """ Update extent value in GUI based from value in map."""
     # Get the extent as [xmin, ymin, xmax, ymax]
     extent = viewport_geo_array(self.iface.mapCanvas())
     self.min_longitude.setText(str(extent[0]))
     self.min_latitude.setText(str(extent[1]))
     self.max_longitude.setText(str(extent[2]))
     self.max_latitude.setText(str(extent[3]))
    def update_extent_from_map_canvas(self):
        """Update extent value in GUI based from value in map.

        .. note:: Delegates to update_extent()
        """

        self.groupBox.setTitle(self.tr('Bounding box from the map canvas'))
        # Get the extent as [xmin, ymin, xmax, ymax]
        extent = viewport_geo_array(self.iface.mapCanvas())
        self.update_extent(extent)
Ejemplo n.º 7
0
    def update_extent_from_map_canvas(self):
        """Update extent value in GUI based from value in map.

        .. note:: Delegates to update_extent()
        """

        self.groupBox.setTitle(self.tr('Bounding box from the map canvas'))
        # Get the extent as [xmin, ymin, xmax, ymax]
        extent = viewport_geo_array(self.iface.mapCanvas())
        self.update_extent(extent)
Ejemplo n.º 8
0
    def save_scenario(self, scenario_file_path=None):
        """Save current scenario to a text file.

        You can use the saved scenario with the batch runner.

        :param scenario_file_path: A path to the scenario file.
        :type scenario_file_path: str
        """
        # Validate Input
        warning_title = tr('InaSAFE Save Scenario Warning')
        is_valid, warning_message = self.validate_input()
        if not is_valid:
            # noinspection PyCallByClass,PyTypeChecker,PyArgumentList
            QtGui.QMessageBox.warning(self, warning_title, warning_message)
            return

        # Make extent to look like:
        # 109.829170982, -8.13333290561, 111.005344795, -7.49226294379

        # Added in 2.2 to support user defined analysis extents
        if self.dock.extent.user_extent is not None \
                and self.dock.extent.crs is not None:
            # In V4.0, user_extent is QgsGeometry.
            user_extent = self.dock.extent.user_extent.boundingBox()
            extent = extent_to_array(user_extent, self.dock.extent.crs)
        else:
            extent = viewport_geo_array(self.iface.mapCanvas())
        extent_string = ', '.join(('%f' % x) for x in extent)

        exposure_path = self.exposure_layer.publicSource()
        hazard_path = self.hazard_layer.publicSource()
        title = self.keyword_io.read_keywords(self.hazard_layer, 'title')
        title = tr(title)
        default_filename = title.replace(' ',
                                         '_').replace('(',
                                                      '').replace(')', '')

        # Popup a dialog to request the filename if scenario_file_path = None
        dialog_title = tr('Save Scenario')
        if scenario_file_path is None:
            # noinspection PyCallByClass,PyTypeChecker
            scenario_file_path = QFileDialog.getSaveFileName(
                self, dialog_title,
                os.path.join(self.output_directory, default_filename + '.txt'),
                "Text files (*.txt)")
        if scenario_file_path is None or scenario_file_path == '':
            return
        self.output_directory = os.path.dirname(scenario_file_path)

        #  Write to file
        parser = ConfigParser()
        parser.add_section(title)
        # Relative path is not recognized by the batch runner, so we use
        # absolute path.
        parser.set(title, 'exposure', exposure_path)
        parser.set(title, 'hazard', hazard_path)

        parser.set(title, 'extent', extent_string)
        if self.dock.extent.crs is None:
            parser.set(title, 'extent_crs', 'EPSG:4326')
        else:
            parser.set(title, 'extent_crs', self.dock.extent.crs.authid())
        if self.aggregation_layer is not None:
            aggregation_path = self.aggregation_layer.publicSource()
            relative_aggregation_path = self.relative_path(
                scenario_file_path, aggregation_path)
            parser.set(title, 'aggregation', relative_aggregation_path)

        # noinspection PyBroadException
        try:
            parser.write(open(scenario_file_path, 'a'))
        except Exception as e:
            # noinspection PyTypeChecker,PyCallByClass,PyArgumentList
            QtGui.QMessageBox.warning(
                self, 'InaSAFE',
                tr('Failed to save scenario to {path}, exception '
                   '{exception}').format(path=scenario_file_path,
                                         exception=str(e)))

        # Save State
        self.save_state()
Ejemplo n.º 9
0
    def save_scenario(self, scenario_file_path=None):
        """Save current scenario to a text file.

        You can use the saved scenario with the batch runner.

        :param scenario_file_path: A path to the scenario file.
        :type scenario_file_path: str
        """
        # Validate Input
        warning_title = self.tr('InaSAFE Save Scenario Warning')
        is_valid, warning_message = self.validate_input()
        if not is_valid:
            # noinspection PyCallByClass,PyTypeChecker,PyArgumentList
            QtGui.QMessageBox.warning(self, warning_title, warning_message)
            return

        # Make extent to look like:
        # 109.829170982, -8.13333290561, 111.005344795, -7.49226294379

        # Added in 2.2 to support user defined analysis extents
        if self.dock.extent.user_extent is not None \
                and self.dock.extent.user_extent_crs is not None:
            extent = extent_to_array(
                self.dock.extent.user_extent,
                self.dock.extent.user_extent_crs)
        else:
            extent = viewport_geo_array(self.iface.mapCanvas())
        extent_string = ', '.join(('%f' % x) for x in extent)

        exposure_path = self.exposure_layer.publicSource()
        hazard_path = self.hazard_layer.publicSource()
        title = self.keyword_io.read_keywords(self.hazard_layer, 'title')
        title = self.tr(title)
        default_filename = title.replace(
            ' ', '_').replace('(', '').replace(')', '')

        # Popup a dialog to request the filename if scenario_file_path = None
        dialog_title = self.tr('Save Scenario')
        if scenario_file_path is None:
            # noinspection PyCallByClass,PyTypeChecker
            scenario_file_path = QFileDialog.getSaveFileName(
                self,
                dialog_title,
                os.path.join(self.output_directory, default_filename + '.txt'),
                "Text files (*.txt)")
        if scenario_file_path is None or scenario_file_path == '':
            return
        self.output_directory = os.path.dirname(scenario_file_path)

        # Get relative path for each layer
        relative_exposure_path = self.relative_path(
            scenario_file_path, exposure_path)
        relative_hazard_path = self.relative_path(
            scenario_file_path, hazard_path)

        #  Write to file
        parser = ConfigParser()
        parser.add_section(title)
        parser.set(title, 'exposure', relative_exposure_path)
        parser.set(title, 'hazard', relative_hazard_path)
        parser.set(title, 'function', self.function_id)
        parser.set(title, 'extent', extent_string)
        if self.dock.extent.user_extent_crs is None:
            parser.set(title, 'extent_crs',
                       'EPSG:4326')
        else:
            parser.set(
                title,
                'extent_crs',
                self.dock.extent.user_extent_crs.authid())
        if self.aggregation_layer is not None:
            aggregation_path = self.aggregation_layer.publicSource()
            relative_aggregation_path = self.relative_path(
                scenario_file_path, aggregation_path)
            parser.set(title, 'aggregation', relative_aggregation_path)

        try:
            parser.write(open(scenario_file_path, 'a'))
        except IOError:
            # noinspection PyTypeChecker,PyCallByClass,PyArgumentList
            QtGui.QMessageBox.warning(
                self,
                self.tr('InaSAFE'),
                self.tr('Failed to save scenario to ' + scenario_file_path))

        # Save State
        self.save_state()