def reproject_params(self, temp_datasource_path): params = { "destNameOrDestDS": temp_datasource_path, "srcDS": self.src_datasource(), "format": "SQLite", "datasetCreationOptions": ["SPATIALITE=YES"], "dstSRS": self.dest_srs(), "reproject": True, "options": ["-skipfailures"], } if self.bboxGroupBox.isChecked(): if self.bboxWidget.value() == "": raise InputError("Extent is empty") if not self.bboxWidget.isValid(): raise InputError("Extent is invalid") bbox = self.bboxWidget.rectangle() params["spatFilter"] = ( bbox.xMinimum(), bbox.yMinimum(), bbox.xMaximum(), bbox.yMaximum(), ) srs = osr.SpatialReference() srs.ImportFromWkt(self.bboxWidget.crs().toWkt()) assert srs.Validate() == 0 params["spatSRS"] = srs return params
def reproject_params(self, temp_datasource_path): params = { 'destNameOrDestDS': temp_datasource_path, 'srcDS': self.src_datasource(), 'format': 'SQLite', 'datasetCreationOptions': ['SPATIALITE=YES'], 'dstSRS': self.dest_srs(), 'reproject': True, 'options': ['-skipfailures'] } if self.bboxGroupBox.isChecked(): if self.bboxWidget.value() == '': raise InputError("Extent is empty") if not self.bboxWidget.isValid(): raise InputError("Extent is invalid") bbox = self.bboxWidget.rectangle() params['spatFilter'] = (bbox.xMinimum(), bbox.yMinimum(), bbox.xMaximum(), bbox.yMaximum()) srs = osr.SpatialReference() srs.ImportFromWkt(self.bboxWidget.crs().toWkt()) assert srs.Validate() == 0 params['spatSRS'] = srs return params
def datasource_name(self): if self.sqliteRadioButton.isChecked(): path = self.sqlitePathLineEdit.text() if path == '': raise InputError("You must select a SQLite file") return path if self.pgsqlRadioButton.isChecked(): if self._pgsql_db is None: raise InputError("You must select a PostgreSQL connection") return 'PG:{}'.format(self._pgsql_db.uri.connectionInfo(True))
def import_params(self, dest): params = { "destNameOrDestDS": dest, "srcDS": self.gmlas_datasource(), "format": self.databaseWidget.format(), "accessMode": self.access_mode(), "datasetCreationOptions": self.dataset_creation_options(), "layerCreationOptions": self.layer_creation_options(), "options": self.translate_options(), } if self.reprojectCheck.isChecked(): params["reproject"] = True params["dstSRS"] = self.dest_srs() else: params["reproject"] = False if self.sourceSrsCheck.isChecked(): params["srcSRS"] = self.src_srs() if self.convertToLinearCheckbox.isChecked(): params["geometryType"] = "CONVERT_TO_LINEAR" layers = self.selected_layers() if len(layers) > 0: params["layers"] = self.selected_layers() if self.ogrExposeMetadataLayersCheckbox.isChecked(): params["layers"] = params["layers"] + [ "_ogr_fields_metadata", "_ogr_layer_relationships", "_ogr_layers_metadata", "_ogr_other_metadata", ] if self.gmlas_bbox_group.isChecked(): if self.bboxWidget.value() == "": raise InputError("Extent is empty") if not self.bboxWidget.isValid(): raise InputError("Extent is invalid") bbox = self.bboxWidget.rectangle() params["spatFilter"] = ( bbox.xMinimum(), bbox.yMinimum(), bbox.xMaximum(), bbox.yMaximum(), ) srs = osr.SpatialReference() srs.ImportFromWkt(self.bboxWidget.crs().toWkt()) assert srs.Validate() == 0 params["spatSRS"] = srs return params
def gmlas_datasource(self): gmlasconf = self.gmlas_config() datasourceFile = self.gmlPathLineEdit.text() if datasourceFile == '': raise InputError(self.tr("You must select a input file or URL")) isXsd = datasourceFile.endswith(".xsd") isUrl = datasourceFile.startswith("http") swapCoordinates = self.swapCoordinatesCombo.currentText() driverConnection = "" openOptions = [ 'EXPOSE_METADATA_LAYERS=YES', 'CONFIG_FILE={}'.format(gmlasconf) ] openOptions.append('SWAP_COORDINATES={}'.format(swapCoordinates)) if isXsd: driverConnection = "GMLAS:" openOptions.append('XSD={}'.format(datasourceFile)) elif isUrl: driverConnection = "GMLAS:/vsicurl_streaming/{}".format( datasourceFile) else: driverConnection = "GMLAS:{}".format(datasourceFile) with qgis_proxy_settings(): return gdal.OpenEx(driverConnection, open_options=openOptions)
def gmlas_config(self): path = self.gmlasConfigLineEdit.text() if path == '': raise InputError(self.tr("You must select a GMLAS config file")) xmlConfig = etree.parse(self.gmlasConfigLineEdit.text()) # Set parameters c = xmlConfig.getroot() for l in c.iter('ExposeMetadataLayers'): l.text = str(self.ogrExposeMetadataLayersCheckbox.isChecked()).lower() for l in c.iter('LayerBuildingRules'): for n in l.iter('RemoveUnusedLayers'): n.text = str(self.ogrRemoveUnusedLayersCheckbox.isChecked()).lower() for n in l.iter('RemoveUnusedFields'): n.text = str(self.ogrRemoveUnusedFieldsCheckbox.isChecked()).lower() for l in c.findall("XLinkResolution/URLSpecificResolution/HTTPHeader"): name = l.find('Name').text if name == 'Accept-Language': l.find('Value').text = self.acceptLanguageHeaderInput.text() textConfig = BytesIO() xmlConfig.write(textConfig, encoding='utf-8', xml_declaration=False) # Write config in temp file tf = tempfile.NamedTemporaryFile(prefix='gmlasconf_', suffix='.xml', delete=False) tf.write(textConfig.getvalue()) tf.close() log("Temporary configuration file created '{}' for conversion.".format(str(tf.name))) return tf.name
def gmlas_datasource(self): gmlasconf = self.gmlas_config() datasourceFile = self.gml_path() if datasourceFile == "": raise InputError(self.tr("You must select a input file or URL")) isXsd = datasourceFile.endswith(".xsd") isUrl = datasourceFile.startswith("http") swapCoordinates = self.swapCoordinatesCombo.currentText() driverConnection = "" openOptions = [ "EXPOSE_METADATA_LAYERS=YES", "CONFIG_FILE={}".format(gmlasconf) ] openOptions.append("SWAP_COORDINATES={}".format(swapCoordinates)) if isXsd: driverConnection = "GMLAS:" openOptions.append("XSD={}".format(datasourceFile)) elif isUrl: driverConnection = "GMLAS:/vsicurl_streaming/{}".format( datasourceFile) else: driverConnection = "GMLAS:{}".format(datasourceFile) gdal.SetConfigOption("GDAL_HTTP_UNSAFESSL", "YES") gdal.SetConfigOption("GDAL_HTTP_USERAGENT", settings.value("http_user_agent", plugin_name())) with qgis_proxy_settings(): return gdal.OpenEx(driverConnection, open_options=openOptions)
def import_params(self, dest): params = { 'destNameOrDestDS': dest, 'srcDS': self.gmlas_datasource(), 'format': self.databaseWidget.format(), 'accessMode': self.access_mode(), 'datasetCreationOptions': self.dataset_creation_options(), 'layerCreationOptions': self.layer_creation_options(), 'options': self.translate_options() } if self.reprojectCheck.isChecked(): params['reproject'] = True params['dstSRS'] = self.dest_srs() else: params['reproject'] = False if self.sourceSrsCheck.isChecked(): params['srcSRS'] = self.src_srs() if self.convertToLinearCheckbox.isChecked(): params['geometryType'] = 'CONVERT_TO_LINEAR' layers = self.selected_layers() if len(layers) > 0: params['layers'] = self.selected_layers() if self.ogrExposeMetadataLayersCheckbox.isChecked(): params['layers'] = params['layers'] + [ '_ogr_fields_metadata', '_ogr_layer_relationships', '_ogr_layers_metadata', '_ogr_other_metadata'] if self.bboxGroupBox.isChecked(): if self.bboxWidget.value() == '': raise InputError("Extent is empty") if not self.bboxWidget.isValid(): raise InputError("Extent is invalid") bbox = self.bboxWidget.rectangle() params['spatFilter'] = (bbox.xMinimum(), bbox.yMinimum(), bbox.xMaximum(), bbox.yMaximum()) srs = osr.SpatialReference() srs.ImportFromWkt(self.bboxWidget.crs().toWkt()) assert srs.Validate() == 0 params['spatSRS'] = srs return params
def dataset_creation_options(self): config_file = self.gmlasConfigLineEdit.text() if config_file == "": raise InputError("You must select a GMLAS config file") options = {"CONFIG_FILE": config_file} xsd_path = self.xsdPathLineEdit.text() if xsd_path != "": options["INPUT_XSD"] = xsd_path return options
def schema(self, create=False): schema = self.pgsqlSchemaBox.currentText() if not create: return schema #if self.pgsqlSchemaBox.currentIndex() == -1: schemas = [schema[1] for schema in self._pgsql_db.list_schemas()] if not schema in schemas: res = QMessageBox.question( self, plugin_name(), self.tr('Create schema "{}" ?').format(schema)) if res != QMessageBox.Yes: raise InputError() self._pgsql_db.create_schema(schema) return schema
def dst_datasource_name(self): gml_path = self.gmlPathLineEdit.text() if gml_path == "": raise InputError("You must select a GML output file") return "GMLAS:{}".format(gml_path)