def translate(self, params):
        if params is None:
            return
        params['callback'] = self.translate_callback

        dlg = QProgressDialog(self)
        dlg.setWindowTitle(plugin_name())
        dlg.setLabelText('Operation in progress')
        dlg.setMinimum(0)
        dlg.setMaximum(100)
        dlg.setWindowModality(Qt.WindowModal)
        self.progress_dlg = dlg

        self.setCursor(Qt.WaitCursor)
        try:
            log("gdal.VectorTranslate({})".format(str(params)))
            gdal.PushErrorHandler(gdal_error_handler)
            with qgis_proxy_settings():
                res = gdal.VectorTranslate(**params)
            gdal.PopErrorHandler()
            log(str(res))
        finally:
            self.unsetCursor()
            self.progress_dlg.reset()
            self.progress_dlg = None
    def translate(self, params):
        if params is None:
            return
        params["callback"] = self.translate_callback

        dlg = QProgressDialog(self)
        dlg.setWindowTitle(plugin_name())
        dlg.setLabelText("Operation in progress")
        dlg.setMinimum(0)
        dlg.setMaximum(100)
        dlg.setWindowModality(Qt.WindowModal)
        self.progress_dlg = dlg

        self.setCursor(Qt.WaitCursor)
        try:
            log("gdal.VectorTranslate({})".format(str(params)))
            gdal.PushErrorHandler(gdal_error_handler)
            with qgis_proxy_settings():
                res = gdal.VectorTranslate(**params)
            gdal.PopErrorHandler()
            log(str(res))
        finally:
            self.unsetCursor()
            self.progress_dlg.reset()
            self.progress_dlg = None
    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_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)
Пример #5
0
    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 download(self):
        wfs = self.wfs()

        typenames = self.selected_typenames()
        if len(typenames) == 0:
            return

        params = {
            'typename': ','.join(typenames),
            'maxfeatures': self.featureLimitBox.value(),
        }

        if self.bboxGroupBox.isChecked():
            if self.bboxWidget.value() == '':
                QMessageBox.warning(self, self.windowTitle(),
                                    "Extent is empty")
                return
            if not self.bboxWidget.isValid():
                QMessageBox.warning(self, self.windowTitle(),
                                    "Extent is invalid")
                return
            params['bbox'] = self._get_bbox(wfs)

        try:
            with qgis_proxy_settings():
                response = wfs.getfeature(**params)
        except owslib.util.ServiceException as e:
            QMessageBox.critical(self, 'ServiceException', str(e))
            return
        xml = response.read()

        doc = QDomDocument()
        if not doc.setContent(xml):
            return
        root = doc.documentElement()
        exception = root.firstChildElement('ows:Exception')
        if not exception.isNull():
            QMessageBox.critical(self, 'ows:Exception', exception.text())
            return

        path = self.outputPathLineEdit.text()
        if path == '':
            with NamedTemporaryFile(mode="w+t", suffix='.gml',
                                    delete=False) as out:
                out.write(xml)
                path = out.name
        else:
            with open(path, 'w') as out:
                out.write(xml)

        return path
Пример #7
0
    def wfs(self):
        conn = QgsOwsConnection("wfs", self.connectionCombo.currentText())
        uri = conn.uri().param('url')
        version = conn.uri().param('version')
        if version == "auto":
            # detect version
            u = QUrlQuery(uri)
            u.addQueryItem("request", "GetCapabilities")
            u.addQueryItem("acceptversions", "2.0.0,1.1.0,1.0.0")

            xml, ns_map = xml_parse(remote_open_from_qgis(u.query()))
            root = xml.getroot()
            versions = [
                v.text for v in root.findall(
                    "./ows:ServiceIdentification/ows:ServiceTypeVersion",
                    ns_map)
            ]
            # take the greatest version, if more than one
            version = sorted(versions)[-1]

        with qgis_proxy_settings():
            return WebFeatureService(url=uri, version=version)
 def wfs(self):
     uri = self.uriComboBox.currentText()
     with qgis_proxy_settings():
         return WebFeatureService(url=uri)