def open_zonal_layer_dialog(self): """ Open a file dialog to select the zonal layer to be loaded :returns: the zonal layer """ text = self.tr('Select zonal layer to import') filters = self.tr('Vector shapefiles (*.shp);;SQLite (*.sqlite);;' 'All files (*.*)') default_dir = QSettings().value('irmt/select_layer_dir', QDir.homePath()) file_name, file_type = QFileDialog.getOpenFileNameAndFilter( self, text, default_dir, filters) if not file_name: return None selected_dir = QFileInfo(file_name).dir().path() QSettings().setValue('irmt/select_layer_dir', selected_dir) zonal_layer_plus_stats = self.load_zonal_layer(file_name) return zonal_layer_plus_stats
def open_file_dialog(self, dialog_type): """ Open a file dialog to select the data file to be loaded :param string dialog_type: 'loss_layer' or 'zonal_layer' :returns: a layer """ if dialog_type == 'loss_layer': text = self.tr('Select loss map to import') # FIXME: What should be the format of the raster maps? filters = self.tr('Loss curves from the OpenQuake-engine (*.csv);;' 'Shapefile vector loss curves (*.shp);;' 'Geojson vector loss curves (*.geojson);;' 'Raster loss curves (*.*)') elif dialog_type == 'zonal_layer': text = self.tr('Select zonal layer to import') filters = self.tr('Vector shapefiles (*.shp);;SQLite (*.sqlite);;' 'All files (*.*)') else: raise RuntimeError('Invalid dialog_type: {}'.format(dialog_type)) default_dir = QSettings().value('irmt/select_layer_dir', QDir.homePath()) file_name, file_type = QFileDialog.getOpenFileNameAndFilter( self, text, default_dir, filters) if dialog_type == 'zonal_layer': if not file_name: return None selected_dir = QFileInfo(file_name).dir().path() QSettings().setValue('irmt/select_layer_dir', selected_dir) layer = self.load_zonal_layer(file_name) elif dialog_type == 'loss_layer': if not file_name: return None selected_dir = QFileInfo(file_name).dir().path() QSettings().setValue('irmt/select_layer_dir', selected_dir) if file_type == 'Raster loss curves (*.*)': self.loss_layer_is_vector = False if file_type == 'Loss curves from the OpenQuake-engine (*.csv)': layer = self.import_loss_layer_from_csv(file_name) else: layer = self.load_loss_layer(file_name) else: raise RuntimeError return layer