def read_settings(self): """Restore settings from QSettings. Do this on init and after changing options in the options dialog. """ settings = QSettings() flag = bool(settings.value('inasafe/showRubberBands', False, type=bool)) self.extent.show_rubber_bands = flag try: extent = settings.value('inasafe/analysis_extent', '', type=str) crs = settings.value('inasafe/analysis_extent_crs', '', type=str) except TypeError: # Any bogus stuff in settings and we just clear them extent = '' crs = '' if extent != '' and crs != '': extent = extent_string_to_array(extent) try: self.extent.user_extent = QgsRectangle(*extent) self.extent.user_extent_crs = QgsCoordinateReferenceSystem(crs) self.extent.show_user_analysis_extent() except TypeError: self.extent.user_extent = None self.extent.user_extent_crs = None flag = settings.value('inasafe/useThreadingFlag', False, type=bool) self.run_in_thread_flag = flag flag = settings.value('inasafe/setZoomToImpactFlag', True, type=bool) self.zoom_to_impact_flag = flag # whether exposure layer should be hidden after model completes flag = settings.value('inasafe/setHideExposureFlag', False, type=bool) self.hide_exposure_flag = flag # whether to 'hard clip' layers (e.g. cut buildings in half if they # lie partially in the AOI self.clip_hard = settings.value('inasafe/clip_hard', False, type=bool) # whether to show or not postprocessing generated layers self.show_intermediate_layers = settings.value( 'inasafe/show_intermediate_layers', False, type=bool) # whether to show or not dev only options # noinspection PyAttributeOutsideInit self.developer_mode = settings.value('inasafe/developer_mode', False, type=bool) # whether to show or not a custom Logo # noinspection PyAttributeOutsideInit self.organisation_logo_path = settings.value( 'inasafe/organisation_logo_path', supporters_logo_path(), type=str)
def read_settings(self): """Restore settings from QSettings. Do this on init and after changing options in the options dialog. """ settings = QSettings() flag = bool(settings.value( 'inasafe/showRubberBands', False, type=bool)) self.extent.show_rubber_bands = flag try: extent = settings.value('inasafe/analysis_extent', '', type=str) crs = settings.value('inasafe/analysis_extent_crs', '', type=str) except TypeError: # Any bogus stuff in settings and we just clear them extent = '' crs = '' if extent != '' and crs != '': extent = extent_string_to_array(extent) try: self.extent.user_extent = QgsRectangle(*extent) self.extent.user_extent_crs = QgsCoordinateReferenceSystem(crs) self.extent.show_user_analysis_extent() except TypeError: self.extent.user_extent = None self.extent.user_extent_crs = None flag = settings.value( 'inasafe/useThreadingFlag', False, type=bool) self.run_in_thread_flag = flag flag = settings.value( 'inasafe/setZoomToImpactFlag', True, type=bool) self.zoom_to_impact_flag = flag # whether exposure layer should be hidden after model completes flag = settings.value( 'inasafe/setHideExposureFlag', False, type=bool) self.hide_exposure_flag = flag # whether to 'hard clip' layers (e.g. cut buildings in half if they # lie partially in the AOI self.clip_hard = settings.value('inasafe/clip_hard', False, type=bool) # whether to show or not postprocessing generated layers self.show_intermediate_layers = settings.value( 'inasafe/show_intermediate_layers', False, type=bool) # whether to show or not dev only options self.developer_mode = settings.value( 'inasafe/developer_mode', False, type=bool) # whether to show or not a custom Logo self.organisation_logo_path = settings.value( 'inasafe/organisation_logo_path', default_organisation_logo_path(), type=str) flag = bool(settings.value( 'inasafe/showOrganisationLogoInDockFlag', True, type=bool))
def run_scenario(self, items): """Run a simple scenario. :param items: A dictionary containing the scenario configuration as table items. :type items: dict :returns: True if success, otherwise return False. :rtype: bool """ LOGGER.info('Run simple task' + str(items)) scenario_directory = str(self.source_directory.text()) paths = [] if 'hazard' in items: paths.append(items['hazard']) if 'exposure' in items: paths.append(items['exposure']) if 'aggregation' in items: paths.append(items['aggregation']) # always run in new project self.iface.newProject() try: scenario_runner.add_layers(scenario_directory, paths, self.iface) except FileNotFoundError: # set status to 'fail' LOGGER.exception('Loading layers failed: \nRoot: %s\n%s' % ( scenario_directory, paths)) return False # See if we have a preferred impact function if 'function' in items: function_id = items['function'] result = scenario_runner.set_function_id( function_id, dock=self.dock) if not result: return False if 'aggregation' in items: aggregation_path = scenario_runner.extract_path( scenario_directory, items['aggregation'])[0] result = scenario_runner.set_aggregation_layer( aggregation_path, self.dock) if not result: return False # Set extent CRS if it exists if 'extent_crs' in items: crs = QgsCoordinateReferenceSystem(items['extent_crs']) else: # assume crs is Geo/WGS84 crs = QgsCoordinateReferenceSystem('EPSG:4326') # set extent if exist if 'extent' in items: # split extent string coordinates = items['extent'] coordinates = extent_string_to_array(coordinates) # set the extent according the value self.iface.mapCanvas().mapRenderer().setProjectionsEnabled(True) extent = QgsRectangle(*coordinates) self.dock.define_user_analysis_extent(extent, crs) message = 'set layer extent to %s ' % extent.asWktCoordinates() LOGGER.info(message) self.iface.mapCanvas().setExtent(extent) result = scenario_runner.run_scenario(self.dock) return result
def run_scenario(self, items): """Run a simple scenario. :param items: A dictionary containing the scenario configuration as table items. :type items: dict :returns: True if success, otherwise return False. :rtype: bool """ # LOGGER.info('Run simple task' + str(items)) scenario_directory = str(self.source_directory.text()) paths = [] if 'hazard' in items: paths.append(items['hazard']) if 'exposure' in items: paths.append(items['exposure']) if 'aggregation' in items: paths.append(items['aggregation']) # always run in new project self.iface.newProject() try: scenario_runner.add_layers(scenario_directory, paths, self.iface) except FileNotFoundError: # set status to 'fail' LOGGER.exception('Loading layers failed: \nRoot: %s\n%s' % ( scenario_directory, paths)) return False # See if we have a preferred impact function if 'function' in items: function_id = items['function'] result = scenario_runner.set_function_id( function_id, dock=self.dock) if not result: return False if 'aggregation' in items: aggregation_path = scenario_runner.extract_path( scenario_directory, items['aggregation'])[0] result = scenario_runner.set_aggregation_layer( aggregation_path, self.dock) if not result: return False # Set extent CRS if it exists if 'extent_crs' in items: crs = QgsCoordinateReferenceSystem(items['extent_crs']) else: # assume crs is Geo/WGS84 crs = QgsCoordinateReferenceSystem('EPSG:4326') # set extent if exist if 'extent' in items: # split extent string coordinates = items['extent'] coordinates = extent_string_to_array(coordinates) # set the extent according the value self.iface.mapCanvas().mapRenderer().setProjectionsEnabled(True) extent = QgsRectangle(*coordinates) self.dock.define_user_analysis_extent(extent, crs) message = 'set layer extent to %s ' % extent.asWktCoordinates() # LOGGER.info(message) self.iface.mapCanvas().setExtent(extent) result = scenario_runner.run_scenario(self.dock) return result
def prepare_task(self, items): """Prepare scenario for impact function variable. :param items: Dictionary containing settings for impact function. :type items: Python dictionary. :return: A tuple containing True and dictionary containing parameters if post processor success. Or False and an error message if something went wrong. """ status = True message = '' # get hazard if 'hazard' in items: hazard_path = items['hazard'] hazard = self.define_layer(hazard_path) if not hazard: status = False message = self.tr( 'Unable to find {hazard_path}').format( hazard_path=hazard_path) else: hazard = None LOGGER.warning('Scenario does not contain hazard path') # get exposure if 'exposure' in items: exposure_path = items['exposure'] exposure = self.define_layer(exposure_path) if not exposure: status = False if message: message += '\n' message += self.tr( 'Unable to find {exposure_path}').format( exposure_path=exposure_path) else: exposure = None LOGGER.warning('Scenario does not contain hazard path') # get aggregation if 'aggregation' in items: aggregation_path = items['aggregation'] aggregation = self.define_layer(aggregation_path) else: aggregation = None LOGGER.info('Scenario does not contain aggregation path') # get extent if 'extent' in items: LOGGER.info('Extent coordinate is found') coordinates = items['extent'] array_coord = extent_string_to_array(coordinates) extent = QgsRectangle(*array_coord) else: extent = None LOGGER.info('Scenario does not contain extent coordinates') # get extent crs id if 'extent_crs' in items: LOGGER.info('Extent CRS is found') crs = items['extent_crs'] extent_crs = QgsCoordinateReferenceSystem(crs) else: LOGGER.info('Extent crs is not found, assuming crs to EPSG:4326') extent_crs = QgsCoordinateReferenceSystem('EPSG:4326') # make sure at least hazard and exposure data are available in # scenario. Aggregation and extent checking will be done when # assigning layer to impact_function if status: parameters = { layer_purpose_hazard['key']: hazard, layer_purpose_exposure['key']: exposure, layer_purpose_aggregation['key']: aggregation, 'extent': extent, 'crs': extent_crs } return True, parameters else: LOGGER.warning(message) display_critical_message_box( title=self.tr('Error while preparing scenario'), message=message) return False, None