예제 #1
0
    def generateProcessInputsGUI(self):
        """Generate the GUI for all Inputs defined in the process description XML file"""
        for input in self.process.inputs:
            inputType = type(input)
            inputIdentifier = input.identifier
            title = input.title
            minOccurs = input.minOccurs
            if inputType == VectorInput or inputType == MultipleVectorInput:
                complexDataFormat = input.dataFormat
                self.inputDataTypeList[inputIdentifier] = complexDataFormat
                layerNamesList = self.tools.getLayerNameList(0)
                if inputType == VectorInput:
                    self.complexInputComboBoxList.append(self.tools.addComplexInputComboBox(title, inputIdentifier, str(complexDataFormat), layerNamesList, minOccurs,  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout))
                else:
                    self.complexInputListWidgetList.append(self.tools.addComplexInputListWidget(title, inputIdentifier, str(complexDataFormat), layerNamesList, minOccurs,  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout))
            elif inputType == StringInput:
                dValue =  input.defaultValue
                self.literalInputLineEditList.append(self.tools.addLiteralLineEdit(title, inputIdentifier, minOccurs,  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout, dValue))
            elif inputType == TextInput:
                complexDataFormat = input.dataFormat
                if isMimeTypePlaylist(complexDataFormat["MimeType"]) != None:
                    self.inputDataTypeList[inputIdentifier] = complexDataFormat
                    # Playlist (text) inputs
                    self.complexInputTextBoxList.append(self.tools.addComplexInputTextBox(title, inputIdentifier, minOccurs,  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout, str(complexDataFormat)))
                else:
                    self.complexInputTextBoxList.append(self.tools.addComplexInputTextBox(title, inputIdentifier, minOccurs,  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout))
            elif inputType == RasterInput or inputType == MultipleRasterInput:
                complexDataFormat = input.dataFormat
                self.inputDataTypeList[inputIdentifier] = complexDataFormat
                layerNamesList = self.tools.getLayerNameList(1)
                if inputType == RasterInput:
                    self.complexInputComboBoxList.append(self.tools.addComplexInputComboBox(title, inputIdentifier, str(complexDataFormat), layerNamesList, minOccurs,  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout))
                else:
                    self.complexInputListWidgetList.append(self.tools.addComplexInputListWidget(title, inputIdentifier, str(complexDataFormat), layerNamesList, minOccurs,  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout))
            elif inputType == SelectionInput:
                valList = input.valList
                self.literalInputComboBoxList.append(self.tools.addLiteralComboBox(title, inputIdentifier, valList, minOccurs,  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout))
            elif inputType == ExtentInput:
                myExtent = pystring(self.iface.mapCanvas().extent()).replace(':',',')
                self.bboxInputLineEditList.append(self.tools.addLiteralLineEdit(title+"(minx,miny,maxx,maxy)", inputIdentifier, minOccurs,  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout, myExtent))
            elif inputType == CrsInput:
                crsListe = input.crsList
#                self.literalInputComboBoxList.append(self.tools.addLiteralComboBox("Supported CRS", inputIdentifier, crsListe, minOccurs,  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout))

        self.tools.addCheckBox(QCoreApplication.translate("QgsWps","Process selected objects only"), QCoreApplication.translate("QgsWps","Selected"),  self.dlgProcessScrollAreaWidget,  self.dlgProcessScrollAreaWidgetLayout)
예제 #2
0
    def defineProcess(self):
        """Create the execute request"""
        self.dlgProcess.close()
        self.dlg.close()
        doc = QtXml.QDomDocument()
        doc.setContent(self.process.processXML)

        QApplication.setOverrideCursor(Qt.WaitCursor)

        checkBoxes = self.dlgProcess.findChildren(QCheckBox)
        if len(checkBoxes) > 0:
            useSelected = checkBoxes[0].isChecked()

        request = ExecutionRequest(self.process)
        request.addExecuteRequestHeader()

        request.addDataInputsStart()
        if len(self.process.inputs) > 0:
            # text/plain inputs ########################################################
            for textBox in self.complexInputTextBoxList:
                # Do not add undefined inputs
                if textBox == None or str(
                        textBox.document().toPlainText()) == "":
                    continue

                # TODO: Check for more types (e.g. KML, Shapefile, JSON)
                self.mimeType = self.inputDataTypeList[
                    textBox.objectName()]["MimeType"]

                if isMimeTypePlaylist(self.mimeType) != None:
                    schema = self.inputDataTypeList[
                        textBox.objectName()]["Schema"]
                    encoding = self.inputDataTypeList[
                        textBox.objectName()]["Encoding"]

                    # Handle 'as reference' playlist
                    request.addReferenceInput(textBox.objectName(),
                                              self.mimeType, schema, encoding,
                                              textBox.document().toPlainText())

                else:  # It's not a playlist
                    request.addPlainTextInput(textBox.objectName(),
                                              textBox.document().toPlainText())

            # Single raster and vector inputs ##########################################
            for comboBox in self.complexInputComboBoxList:
                # Do not add undefined inputs

                if comboBox == None or comboBox.currentText() == "<None>":
                    continue

                # TODO: Check for more types (e.g. KML, Shapefile, JSON)
#              QMessageBox.information(None, '',  str(self.inputDataTypeList[comboBox.objectName()]["MimeType"]))
#              QMessageBox.information(None, '',  pystring(comboBox.objectName()))

                self.mimeType = self.inputDataTypeList[pystring(
                    comboBox.objectName())]["MimeType"]
                schema = self.inputDataTypeList[pystring(
                    comboBox.objectName())]["Schema"]
                encoding = self.inputDataTypeList[pystring(
                    comboBox.objectName())]["Encoding"]
                self.myLayer = self.tools.getVLayer(comboBox.currentText())

                #              try:
                if isMimeTypeVector(
                        self.mimeType) != None and encoding != "base64":
                    gmldata = createTmpGML(
                        self.tools.getVLayer(comboBox.currentText()),
                        useSelected,
                        self.process.getSupportedGMLVersion(
                            comboBox.objectName()))
                    request.addGeometryInput(comboBox.objectName(),
                                             self.mimeType, schema, encoding,
                                             gmldata, useSelected)
                elif isMimeTypeVector(
                        self.mimeType) != None or isMimeTypeRaster(
                            self.mimeType) != None:
                    request.addGeometryBase64Input(
                        comboBox.objectName(), self.mimeType,
                        self.tools.getVLayer(comboBox.currentText()))
#              except:
#                  QApplication.restoreOverrideCursor()
#                  QMessageBox.warning(self.iface.mainWindow(),
#                      QApplication.translate("QgsWps","Error"),
#                      QApplication.translate("QgsWps","Please load or select a vector layer!"))
#                  return

# Multiple raster and vector inputs ########################################
            for listWidgets in self.complexInputListWidgetList:
                # Do not add undefined inputs
                if listWidgets == None:
                    continue

                self.mimeType = self.inputDataTypeList[
                    listWidgets.objectName()]["MimeType"]
                schema = self.inputDataTypeList[
                    listWidgets.objectName()]["Schema"]
                encoding = self.inputDataTypeList[
                    listWidgets.objectName()]["Encoding"]

                # Iterate over each seletced item
                for i in range(listWidgets.count()):
                    listWidget = listWidgets.item(i)
                    if listWidget == None or listWidget.isSelected(
                    ) == False or str(listWidget.text()) == "<None>":
                        continue

                    # TODO: Check for more types
                    if isMimeTypeVector(
                            self.mimeType
                    ) != None and self.mimeType == "text/xml":
                        gmldata = createTmpGML(
                            self.tools.getVLayer(listWidget.text()),
                            useSelected,
                            self.process.getSupportedGMLVersion(
                                listWidgets.objectName()))
                        request.addMultipleGeometryInput(
                            listWidgets.objectName(), self.mimeType, schema,
                            encoding, gmldata, useSelected)
                    elif isMimeTypeVector(
                            self.mimeType) != None or isMimeTypeRaster(
                                self.mimeType) != None:
                        request.addMultipleGeometryBase64Input(
                            listWidgets.objectName(), self.mimeType,
                            self.tools.getVLayer(listWidget.text()))

            # Literal data as combo box choice #########################################
            for comboBox in self.literalInputComboBoxList:
                if comboBox == None or comboBox.currentText() == "":
                    continue

                request.addLiteralDataInput(comboBox.objectName(),
                                            comboBox.currentText())

        # Literal data as combo box choice #########################################
            for lineEdit in self.literalInputLineEditList:
                if lineEdit == None or lineEdit.text() == "":
                    continue

                request.addLiteralDataInput(lineEdit.objectName(),
                                            lineEdit.text())

        # BBOX data as lineEdit #########################################
            for bbox in self.bboxInputLineEditList:
                if bbox == None or bbox.text() == "":
                    continue

                bboxArray = bbox.text().split(',')

                request.addBoundingBoxInput(bbox.objectName(), bboxArray)

        request.addDataInputsEnd()

        # Attach only defined outputs
        dataOutputs = doc.elementsByTagName("Output")
        if dataOutputs.size() > 0 or len(self.complexOutputComboBoxList) > 0:
            request.addResponseFormStart()

            # Attach ALL literal outputs #############################################
            for i in range(dataOutputs.size()):
                f_element = dataOutputs.at(i).toElement()
                outputIdentifier = pystring(
                    f_element.elementsByTagName("ows:Identifier").at(
                        0).toElement().text()).strip()
                literalOutputType = f_element.elementsByTagName(
                    "LiteralOutput")

                # Complex data is always requested as reference
                if literalOutputType.size() != 0:
                    request.addLiteralDataOutput(outputIdentifier)

            # Attach selected complex outputs ########################################
            for comboBox in self.complexOutputComboBoxList:
                # Do not add undefined outputs
                if comboBox == None or str(comboBox.currentText()) == "<None>":
                    continue
                outputIdentifier = comboBox.objectName()

                self.mimeType = self.outputDataTypeList[pystring(
                    outputIdentifier)]["MimeType"]
                schema = self.outputDataTypeList[pystring(
                    outputIdentifier)]["Schema"]
                encoding = self.outputDataTypeList[pystring(
                    outputIdentifier)]["Encoding"]

                request.addReferenceOutput(outputIdentifier, self.mimeType,
                                           schema, encoding)

            request.addResponseFormEnd()

        request.addExecuteRequestEnd()
        postString = request.request

        # This is for debug purpose only
        if DEBUG == True:
            #            self.tools.popUpMessageBox("Execute request", postString)
            # Write the request into a file
            outFile = open('/tmp/qwps_execute_request.xml', 'w')
            outFile.write(postString)
            outFile.close()

        QApplication.restoreOverrideCursor()
        self.setStatus("processing")
        self.wps = ExecutionResult(self.getLiteralResult, self.getResultFile,
                                   self.successResult, self.errorResult,
                                   self.streamingHandler, self.progressBar)
        self.wps.executeProcess(self.process.processUrl, postString)
        if len(self.process.inputs) > 0:
            self.wps.thePostReply.uploadProgress.connect(
                lambda done, total: self.setStatus("upload", done, total))
        self.wps.fetchingResult.connect(self.fetchingResult)
예제 #3
0
    def defineProcess(self):
        """Create the execute request"""
        self.dlgProcess.close()
        self.dlg.close()
        doc = QtXml.QDomDocument()
        doc.setContent(self.process.processXML)

        QApplication.setOverrideCursor(Qt.WaitCursor)

        checkBoxes = self.dlgProcess.findChildren(QCheckBox)
        if len(checkBoxes) > 0:
            useSelected = checkBoxes[0].isChecked()

        request = ExecutionRequest(self.process)
        request.addExecuteRequestHeader()

        request.addDataInputsStart()
        if len(self.process.inputs) > 0:
            # text/plain inputs ########################################################
            for textBox in self.complexInputTextBoxList:
                # Do not add undefined inputs
                if textBox == None or str(textBox.document().toPlainText()) == "":
                    continue

                # TODO: Check for more types (e.g. KML, Shapefile, JSON)
                self.mimeType = self.inputDataTypeList[textBox.objectName()]["MimeType"]

                if isMimeTypePlaylist(self.mimeType) != None:
                    schema = self.inputDataTypeList[textBox.objectName()]["Schema"]
                    encoding = self.inputDataTypeList[textBox.objectName()]["Encoding"]

                    # Handle 'as reference' playlist
                    request.addReferenceInput(
                        textBox.objectName(), self.mimeType, schema, encoding, textBox.document().toPlainText()
                    )

                else:  # It's not a playlist
                    request.addPlainTextInput(textBox.objectName(), textBox.document().toPlainText())

            # Single raster and vector inputs ##########################################
            for comboBox in self.complexInputComboBoxList:
                # Do not add undefined inputs

                if comboBox == None or comboBox.currentText() == "<None>":
                    continue

                # TODO: Check for more types (e.g. KML, Shapefile, JSON)
                #              QMessageBox.information(None, '',  str(self.inputDataTypeList[comboBox.objectName()]["MimeType"]))
                #              QMessageBox.information(None, '',  pystring(comboBox.objectName()))

                self.mimeType = self.inputDataTypeList[pystring(comboBox.objectName())]["MimeType"]
                schema = self.inputDataTypeList[pystring(comboBox.objectName())]["Schema"]
                encoding = self.inputDataTypeList[pystring(comboBox.objectName())]["Encoding"]
                self.myLayer = self.tools.getVLayer(comboBox.currentText())

                #              try:
                if isMimeTypeVector(self.mimeType) != None and encoding != "base64":
                    gmldata = createTmpGML(
                        self.tools.getVLayer(comboBox.currentText()),
                        useSelected,
                        self.process.getSupportedGMLVersion(comboBox.objectName()),
                    )
                    request.addGeometryInput(
                        comboBox.objectName(), self.mimeType, schema, encoding, gmldata, useSelected
                    )
                elif isMimeTypeVector(self.mimeType) != None or isMimeTypeRaster(self.mimeType) != None:
                    request.addGeometryBase64Input(
                        comboBox.objectName(), self.mimeType, self.tools.getVLayer(comboBox.currentText())
                    )
            #              except:
            #                  QApplication.restoreOverrideCursor()
            #                  QMessageBox.warning(self.iface.mainWindow(),
            #                      QApplication.translate("QgsWps","Error"),
            #                      QApplication.translate("QgsWps","Please load or select a vector layer!"))
            #                  return

            # Multiple raster and vector inputs ########################################
            for listWidgets in self.complexInputListWidgetList:
                # Do not add undefined inputs
                if listWidgets == None:
                    continue

                self.mimeType = self.inputDataTypeList[listWidgets.objectName()]["MimeType"]
                schema = self.inputDataTypeList[listWidgets.objectName()]["Schema"]
                encoding = self.inputDataTypeList[listWidgets.objectName()]["Encoding"]

                # Iterate over each seletced item
                for i in range(listWidgets.count()):
                    listWidget = listWidgets.item(i)
                    if listWidget == None or listWidget.isSelected() == False or str(listWidget.text()) == "<None>":
                        continue

                    # TODO: Check for more types
                    if isMimeTypeVector(self.mimeType) != None and self.mimeType == "text/xml":
                        gmldata = createTmpGML(
                            self.tools.getVLayer(listWidget.text()),
                            useSelected,
                            self.process.getSupportedGMLVersion(listWidgets.objectName()),
                        )
                        request.addMultipleGeometryInput(
                            listWidgets.objectName(), self.mimeType, schema, encoding, gmldata, useSelected
                        )
                    elif isMimeTypeVector(self.mimeType) != None or isMimeTypeRaster(self.mimeType) != None:
                        request.addMultipleGeometryBase64Input(
                            listWidgets.objectName(), self.mimeType, self.tools.getVLayer(listWidget.text())
                        )

            # Literal data as combo box choice #########################################
            for comboBox in self.literalInputComboBoxList:
                if comboBox == None or comboBox.currentText() == "":
                    continue

                request.addLiteralDataInput(comboBox.objectName(), comboBox.currentText())

            # Literal data as combo box choice #########################################
            for lineEdit in self.literalInputLineEditList:
                if lineEdit == None or lineEdit.text() == "":
                    continue

                request.addLiteralDataInput(lineEdit.objectName(), lineEdit.text())

            # BBOX data as lineEdit #########################################
            for bbox in self.bboxInputLineEditList:
                if bbox == None or bbox.text() == "":
                    continue

                bboxArray = bbox.text().split(",")

                request.addBoundingBoxInput(bbox.objectName(), bboxArray)

        request.addDataInputsEnd()

        # Attach only defined outputs
        dataOutputs = doc.elementsByTagName("Output")
        if dataOutputs.size() > 0 or len(self.complexOutputComboBoxList) > 0:
            request.addResponseFormStart()

            # Attach ALL literal outputs #############################################
            for i in range(dataOutputs.size()):
                f_element = dataOutputs.at(i).toElement()
                outputIdentifier = pystring(
                    f_element.elementsByTagName("ows:Identifier").at(0).toElement().text()
                ).strip()
                literalOutputType = f_element.elementsByTagName("LiteralOutput")

                # Complex data is always requested as reference
                if literalOutputType.size() != 0:
                    request.addLiteralDataOutput(outputIdentifier)

            # Attach selected complex outputs ########################################
            for comboBox in self.complexOutputComboBoxList:
                # Do not add undefined outputs
                if comboBox == None or str(comboBox.currentText()) == "<None>":
                    continue
                outputIdentifier = comboBox.objectName()

                self.mimeType = self.outputDataTypeList[pystring(outputIdentifier)]["MimeType"]
                schema = self.outputDataTypeList[pystring(outputIdentifier)]["Schema"]
                encoding = self.outputDataTypeList[pystring(outputIdentifier)]["Encoding"]

                request.addReferenceOutput(outputIdentifier, self.mimeType, schema, encoding)

            request.addResponseFormEnd()

        request.addExecuteRequestEnd()
        postString = request.request

        # This is for debug purpose only
        if True:
            #            self.tools.popUpMessageBox("Execute request", postString)
            # Write the request into a file
            outFile = open("/tmp/qwps_execute_request.xml", "w")
            outFile.write(postString)
            outFile.close()

        QApplication.restoreOverrideCursor()
        self.setStatus("processing")
        self.wps = ExecutionResult(
            self.getLiteralResult,
            self.getResultFile,
            self.successResult,
            self.errorResult,
            self.streamingHandler,
            self.progressBar,
        )
        self.wps.executeProcess(self.process.processUrl, postString)
        if len(self.process.inputs) > 0:
            self.wps.thePostReply.uploadProgress.connect(lambda done, total: self.setStatus("upload", done, total))
        self.wps.fetchingResult.connect(self.fetchingResult)