def __init__(self): super(MainWindow, self).__init__(None) uic.loadUi("./mainwindow.ui", self) doc = QDomDocument() # 添加处理指令即XML说明 instruction = QDomProcessingInstruction() instruction = doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"") doc.appendChild(instruction) # 添加根元素 root = doc.createElement(QString("书库")) doc.appendChild(root) # 添加根元素 # 添加第一个图书元素及其子元素 book = doc.createElement(QString("图书")) id = doc.createAttribute(QString("编号")) title = doc.createElement(QString("书名")) author = doc.createElement(QString("作者")) text = QDomText() id.setValue(QString("1")) book.setAttributeNode(id) text = doc.createTextNode(QString("Qt")) title.appendChild(text) text = doc.createTextNode(QString("shiming")) author.appendChild(text) book.appendChild(title) # 图书元素 添加 书名元素 book.appendChild(author) # 图书元素 添加 作者元素 root.appendChild(book) # 根元素 添加 图书元素 # 添加第二个图书元素及其子元素 book = doc.createElement(QString("图书")) id = doc.createAttribute(QString("编号")) title = doc.createElement(QString("书名")) author = doc.createElement(QString("作者")) id.setValue(QString("2")) book.setAttributeNode(id) text = doc.createTextNode(QString("Linux")) title.appendChild(text) text = doc.createTextNode(QString("yafei")) author.appendChild(text) book.appendChild(title) book.appendChild(author) root.appendChild(book) file = QFile("my.xml") if (not file.open(QIODevice.WriteOnly | QIODevice.Truncate)): raise Exception("open my.xml Err") out = QTextStream(file) doc.save(out, 4) # 将文档保存到文件,4为子元素缩进字符数 file.close()
def method_30(self): filePath = define.appPath + "/Resource/settingData/phxtemplates.xml" fileInfo = QFileInfo(filePath) if fileInfo.exists(): QFile.remove(filePath) doc = QDomDocument() rootElem = doc.createElement("Templates") xmlDeclaration = doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"utf-8\"") doc.appendChild(xmlDeclaration) for i in range(self.parametersPanel.gridModel.rowCount()): elem = doc.createElement( "Templates" + self.parametersPanel.gridModel.item(i, 0).text()) valueElem = doc.createElement("title") valueElem.appendChild( doc.createTextNode( self.parametersPanel.gridModel.item(i, 0).text())) elem.appendChild(valueElem) valueElem = doc.createElement("space") valueElem.appendChild( doc.createTextNode( self.parametersPanel.gridModel.item(i, 1).text())) elem.appendChild(valueElem) valueElem = doc.createElement("value") valueElem.appendChild( doc.createTextNode( self.parametersPanel.gridModel.item(i, 2).text())) elem.appendChild(valueElem) rootElem.appendChild(elem) doc.appendChild(rootElem) qFile = QFile(filePath) if qFile.open(QFile.WriteOnly): textStream = QTextStream(qFile) doc.save(textStream, 4) qFile.close() # ###CRC file is created. contents = None with open(filePath, 'rb', 0) as tempFile: contents = tempFile.read() tempFile.flush() tempFile.close() bytes = FasDataBlockFile.CRC_Calculation(contents) string_0 = QString(filePath) path = string_0.left(string_0.length() - 3) + "crc" fileStream = open(path, 'wb') fileStream.write(bytes) fileStream.close()
def btnEvaluate_Click(self): #### --------------- Export -------------------### if ProcedureExportDlg.dataBase == None: return filePathDir = QFileDialog.getSaveFileName(self, "Save Data",QCoreApplication.applicationDirPath (),"XML Files (*.xml)") if filePathDir == "": return effectiveDate = ProcedureExportDlg.dataBase.EffectiveDate; resultDlg, effectiveDate = DlgAixmEffectiveDate.smethod_0(effectiveDate) if (not resultDlg): return; xmlDocument = QDomDocument() xmlDeclaration = xmlDocument.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"" ) xmlDocument.appendChild(xmlDeclaration) xmlElement = xmlDocument.createElement("AIXM-update") # xmlAttribute = xmlDocument.createAttribute("xsi") # xmlAttribute.setValue("http://www.w3.org/2001/XMLSchema-instance") xmlElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); xmlElement.setAttribute("xsi:noNamespaceSchemaLocation", "AIXM+Update.xsd"); # xmlAttribute.Value = "AIXM+Update.xsd"; xmlElement.setAttribute("version", "4.5"); xmlElement.setAttribute("origin", "ASAP s.r.o."); strS = QDateTime.currentDateTime().toString("yyyy-MM-dd"); now = QDateTime.currentDateTime(); xmlElement.setAttribute("created", String.Concat([strS, "T", now.toString("hh:mm:ss")])); xmlElement.setAttribute("effective", String.Concat([effectiveDate.toString("yyyy-MM-dd"), "T00:00:00"])); # xmlElement.Attributes.Append(xmlAttribute); xmlDocument.appendChild(xmlElement) xmlElement1 = xmlDocument.createElement("Group"); xmlElement1.setAttribute("Name", "Group 1 of 1"); ProcedureExportDlg.dataBase.ProcedureData.method_61(xmlElement1, self.newProcedurePointsInUse); ProcedureExportDlg.dataBase.ProcedureData.method_62(xmlElement1, ProcedureExportDlg.dataBase.SIDs.Select({"deleted":"True", "new":"False"}), DataBaseProcedureExportDlgType.Deleted); ProcedureExportDlg.dataBase.ProcedureData.method_62(xmlElement1, ProcedureExportDlg.dataBase.SIDs.Select({"deleted":"False", "changed":"True", "new":"False"}), DataBaseProcedureExportDlgType.Updated); ProcedureExportDlg.dataBase.ProcedureData.method_62(xmlElement1, ProcedureExportDlg.dataBase.SIDs.Select({"deleted":"False", "new":"True"}), DataBaseProcedureExportDlgType.Created); ProcedureExportDlg.dataBase.ProcedureData.method_63(xmlElement1, ProcedureExportDlg.dataBase.STARs.Select({"deleted":"True", "new":"False"}), DataBaseProcedureExportDlgType.Deleted); ProcedureExportDlg.dataBase.ProcedureData.method_63(xmlElement1, ProcedureExportDlg.dataBase.STARs.Select({"deleted":"False", "changed":"True", "new":"False"}), DataBaseProcedureExportDlgType.Updated); ProcedureExportDlg.dataBase.ProcedureData.method_63(xmlElement1, ProcedureExportDlg.dataBase.STARs.Select({"deleted":"False", "new":"True"}), DataBaseProcedureExportDlgType.Created); ProcedureExportDlg.dataBase.ProcedureData.method_64(xmlElement1, ProcedureExportDlg.dataBase.IAPs.Select({"deleted":"True", "new":"False"}), DataBaseProcedureExportDlgType.Deleted); ProcedureExportDlg.dataBase.ProcedureData.method_64(xmlElement1, ProcedureExportDlg.dataBase.IAPs.Select({"deleted":"False", "changed":"True", "new":"False"}), DataBaseProcedureExportDlgType.Updated); ProcedureExportDlg.dataBase.ProcedureData.method_64(xmlElement1, ProcedureExportDlg.dataBase.IAPs.Select({"deleted":"False", "new":"True"}), DataBaseProcedureExportDlgType.Created); ProcedureExportDlg.dataBase.ProcedureData.method_65(xmlElement1, ProcedureExportDlg.dataBase.Holdings.Select({"deleted":"True", "new":"False"}), DataBaseProcedureExportDlgType.Deleted); ProcedureExportDlg.dataBase.ProcedureData.method_65(xmlElement1, ProcedureExportDlg.dataBase.Holdings.Select({"deleted":"False", "changed":"True", "new":"False"}), DataBaseProcedureExportDlgType.Updated); ProcedureExportDlg.dataBase.ProcedureData.method_65(xmlElement1, ProcedureExportDlg.dataBase.Holdings.Select({"deleted":"False", "new":"True"}), DataBaseProcedureExportDlgType.Created); xmlElement.appendChild(xmlElement1); # xmlDocument.Save(self.sfd.FileName); # base.method_20(string.Format(Messages.X_SUCCESSFULLY_CREATED, self.pnlFile.Value)); qFile = QFile(filePathDir) if qFile.open(QFile.WriteOnly): textStream = QTextStream(qFile) xmlDocument.save(textStream, 4) qFile.close() else: raise UserWarning, "can not open file:" + filePathDir
def exportToXml(self, fn): from PyQt4.QtXml import QDomDocument doc = QDomDocument(self.XML_TRANSF_DOC) instr = doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\" ") doc.appendChild(instr) root = doc.createElement(self.XML_TRANSF_LIST_TAG) doc.appendChild(root) for t in Transformation.getAll(): root.appendChild(t._toNode(doc)) f = QFile(fn) if not f.open(QIODevice.WriteOnly): return False xmlStream = QTextStream(f) xmlStream.setCodec(QTextCodec.codecForName("UTF-8")) xmlStream << doc.toString() return True
def WriteProjectInfoXml(self): doc = QDomDocument() rootElem = doc.createElement("ProjectListClass") xmlDeclaration = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"") doc.appendChild(xmlDeclaration) elem = doc.createElement("ProjectCount") elem.appendChild(doc.createTextNode(str(len(self.ProjectsList)))) rootElem.appendChild(elem) for i in range(len(self.ProjectsList)): elem = doc.createElement("ProjectInfo") objNameElem = doc.createElement("Name") objNameElem.appendChild(doc.createTextNode(self.ProjectsList[i].Name)) elem.appendChild(objNameElem) objNameElem = doc.createElement("Path") objNameElem.appendChild(doc.createTextNode(self.ProjectsList[i].Path)) elem.appendChild(objNameElem) objNameElem = doc.createElement("Created") objNameElem.appendChild(doc.createTextNode(self.ProjectsList[i].Created)) elem.appendChild(objNameElem) objNameElem = doc.createElement("ProcedureName") objNameElem.appendChild(doc.createTextNode(self.ProjectsList[i].ProcedureName)) elem.appendChild(objNameElem) objNameElem = doc.createElement("ProjName") objNameElem.appendChild(doc.createTextNode(self.ProjectsList[i].ProjName)) elem.appendChild(objNameElem) objNameElem = doc.createElement("Pt") objNameElem.appendChild(doc.createTextNode(self.ProjectsList[i].Pt)) elem.appendChild(objNameElem) objNameElem = doc.createElement("SubProjName") objNameElem.appendChild(doc.createTextNode(self.ProjectsList[i].SubProjName)) elem.appendChild(objNameElem) objNameElem = doc.createElement("UserName") objNameElem.appendChild(doc.createTextNode(self.ProjectsList[i].UserName)) elem.appendChild(objNameElem) objNameElem = doc.createElement("WorkspaceName") objNameElem.appendChild(doc.createTextNode(self.ProjectsList[i].WorkspaceName)) elem.appendChild(objNameElem) objNameElem = doc.createElement("FullName") objNameElem.appendChild(doc.createTextNode(self.ProjectsList[i].FullName)) elem.appendChild(objNameElem) rootElem.appendChild(elem) doc.appendChild(rootElem) qFile = QFile(self.m_strProjectInfoFullName) if qFile.open(QFile.WriteOnly): textStream = QTextStream(qFile) doc.save(textStream, 4) qFile.close() # ###CRC file is created. with open(self.m_strProjectInfoFullName, 'rb', 0) as tempFile: contents = tempFile.read() tempFile.flush() tempFile.close() bytes = FasDataBlockFile.CRC_Calculation(contents) string_0 = QString(self.m_strProjectInfoFullName) path = string_0.left(string_0.length() - 3) + "crc" fileStream = open(path, 'wb') fileStream.write(bytes) fileStream.close() else: raise UserWarning, "can not open file:" + self.m_strProjectInfoFullName
def getObservations (self, offering="", properties=[], features=[], procedures=[], filters=None, resultModel = ""): """ :param offering: Offering name :type offering: str :param properties: Selected properties names :type properties: str list :param features: Selected features of interest names :type features: str list :param procedures: Selected procedures names :type procedures: str list :param filters: Configured filters :type filters: FilterRequest :param resultModel: Selected result model :type resultModel: str :return: xml data """ doc = QDomDocument() doc.appendChild(doc.createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"')) root = doc.createElement('GetObservation') root.setAttribute('xmlns',"http://www.opengis.net/sos/1.0") root.setAttribute('xmlns:ows',"http://www.opengis.net/ows/1.1") root.setAttribute('xmlns:gml',"http://www.opengis.net/gml") root.setAttribute('xmlns:ogc',"http://www.opengis.net/ogc") root.setAttribute('xmlns:om',"http://www.opengis.net/om/1.0") root.setAttribute('xmlns:xsi',"http://www.w3.org/2001/XMLSchema-instance") root.setAttribute('xsi:schemaLocation',"http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd") root.setAttribute('service',"SOS") root.setAttribute('version',"1.0.0") root.setAttribute('srsName',self[offering].srsName) doc.appendChild(root) offer = doc.createElement("offering") offer.appendChild(doc.createTextNode(offering)) root.appendChild (offer) if filters.temporalFilter: timeEvent = doc.createElement("eventTime") operator = doc.createElement("ogc:%s" % filters.temporalOperator) prop = doc.createElement("ogc:PropertyName") prop.appendChild (doc.createTextNode ("om:samplingTime")) operand = doc.createElement(filters.temporalOperand) if filters.temporalOperand == "gml:TimeInstant": timePos = doc.createElement("gml:timePosition") timePos.appendChild(doc.createTextNode(str(filters.temporalValue))) operand.appendChild (timePos) elif filters.temporalOperand == "gml:TimePeriod": begin = doc.createElement("gml:beginPosition") begin.appendChild(doc.createTextNode(str(filters.temporalValue).split()[0])) end = doc.createElement("gml:endPosition") end.appendChild(doc.createTextNode(str(filters.temporalValue).split()[-1])) operand.appendChild(begin) operand.appendChild(end) root.appendChild(timeEvent) timeEvent.appendChild(operator) operator.appendChild (prop) operator.appendChild (operand) for proc in procedures: procElement = doc.createElement("procedure") procElement.appendChild (doc.createTextNode(proc)) root.appendChild (procElement) for prop in properties: propElement = doc.createElement("observedProperty") propElement.appendChild(doc.createTextNode(prop)) root.appendChild (propElement) foi = doc.createElement("featureOfInterest") if len (features) else None for foiName in features: foiElement = doc.createElement("ObjectID") foiElement.appendChild(doc.createTextNode(foiName)) foi.appendChild (foiElement) if filters.spatialFilter and not foi: foi = doc.createElement("featureOfInterest") operator = doc.createElement("ogc:%s" % filters.spatialOperator) prop = doc.createElement("ogc:PropertyName") prop.appendChild (doc.createTextNode ("urn:ogc:data:location")) operator.appendChild (prop) try: if filters.spatialOperand == "gml:Point": gmlNode = QgsOgcUtils.geometryToGML(QgsGeometry.fromPoint(filters._spatialValue), doc) elif filters.spatialOperand == "gml:Envelope": gmlNode = QgsOgcUtils.rectangleToGMLEnvelope(QgsGeometry.fromRect(filters._spatialValue).boundingBox(), doc) elif filters.spatialOperand == "gml:Polygon": gmlNode = QgsOgcUtils.geometryToGML(QgsGeometry.fromPolygon(filters._spatialValue), doc) elif filters.spatialOperand == "gml:LineString": gmlNode = QgsOgcUtils.geometryToGML(QgsGeometry.fromPolyline(filters._spatialValue), doc) gmlNode.setAttribute('srsName',self[offering].srsName) operator.appendChild (gmlNode) except: pass foi.appendChild(operator) #Lista de features o filtro espacial if foi: root.appendChild(foi) if filters.scalarFilter: result = doc.createElement("result") operator = doc.createElement("ogc:PropertyIs%s" % filters.scalarOperator) prop = doc.createElement("ogc:PropertyName") prop.appendChild (doc.createTextNode (filters.scalarOperand)) operator.appendChild (prop) if filters.scalarOperator in ["Between"]: try: lower = doc.createElement ("ogc:LowerBoundary") lowValue = doc.createElement ("ogc:Literal") lowValue.appendChild(doc.createTextNode(str(filters.scalarValue).split()[0])) lower.appendChild (lowValue) upper = doc.createElement ("ogc:UpperBoundary") upValue = doc.createElement ("ogc:Literal") upValue.appendChild(doc.createTextNode(str(filters.scalarValue).split()[-1])) upper.appendChild (upValue) operator.appendChild (lower) operator.appendChild (upper) except: pass else: value = doc.createElement ("ogc:Literal") value.appendChild(doc.createTextNode(str(filters.scalarValue))) operator.appendChild (value) root.appendChild(result) result.appendChild(operator) responseFormat = doc.createElement ("responseFormat") responseFormat.appendChild (doc.createTextNode('text/xml;subtype="om/1.0.0"')) root.appendChild (responseFormat) resultModelElement = doc.createElement ("resultModel") resultModelElement.appendChild (doc.createTextNode(resultModel)) root.appendChild (resultModelElement) responseMode = doc.createElement ("responseMode") responseMode.appendChild (doc.createTextNode("inline")) root.appendChild (responseMode) return doc.toString(4)
def createAndParseSld(qgisLayerItem): document = QDomDocument() header = document.createProcessingInstruction( 'xml', 'version=\'1.0\' encoding=\'UTF-8\'') document.appendChild(header) root = document.createElementNS('http://www.opengis.net/sld', 'StyledLayerDescriptor') root.setAttribute('version', '1.0.0') root.setAttribute('xmlns:ogc', 'http://www.opengis.net/ogc') root.setAttribute('xmlns:sld', 'http://www.opengis.net/sld') root.setAttribute('xmlns:gml', 'http://www.opengis.net/gml') document.appendChild(root) namedLayerNode = document.createElement('sld:NamedLayer') root.appendChild(namedLayerNode) qgisLayerItem.layer.writeSld(namedLayerNode, document, '') ## TODO: if could not be created... nameNode = namedLayerNode.firstChildElement('se:Name') oldNameText = nameNode.firstChild() newname = qgisLayerItem.parentShogunLayer.source['layerNames'] newNameText = document.createTextNode(newname) nameNode.appendChild(newNameText) nameNode.removeChild(oldNameText) userStyleNode = namedLayerNode.firstChildElement('UserStyle') userStyleNameNode = userStyleNode.firstChildElement('se:Name') userStyleNameText = userStyleNameNode.firstChild() userStyleNameNode.removeChild(userStyleNameText) userStyleNameNode.appendChild( document.createTextNode(qgisLayerItem.stylename)) titleNode = document.createElement('sld:Title') title = document.createTextNode('A QGIS-Style for ' + qgisLayerItem.layer.name()) titleNode.appendChild(title) userStyleNode.appendChild(titleNode) defaultNode = document.createElement('sld:IsDefault') defaultNode.appendChild(document.createTextNode('1')) userStyleNode.appendChild(defaultNode) featureTypeStyleNode = userStyleNode.firstChildElement( 'se:FeatureTypeStyle') featureTypeStyleNameNode = document.createElement('sld:Name') featureTypeStyleNameNode.appendChild(document.createTextNode('name')) featureTypeStyleNode.appendChild(featureTypeStyleNameNode) rules = featureTypeStyleNode.elementsByTagName('se:Rule') for x in range(rules.length()): rule = rules.at(x) rule.removeChild(rule.firstChildElement('se:Description')) # Check if custom icons are used in symbology and replace the text: # search if tag 'se:OnlineResource' is in the sld document listOfGraphics = rule.toElement().elementsByTagName('se:OnlineResource') if not listOfGraphics.isEmpty(): for x in range(listOfGraphics.length()): graphicNode = listOfGraphics.at(x) currentIcon = graphicNode.attributes().namedItem( 'xlink:href').nodeValue() iconUrl = qgisLayerItem.ressource.prepareIconForUpload(currentIcon) graphicNode.toElement().setAttribute('xlink:href', iconUrl) graphicNode.toElement().setAttribute( 'xmlns:xlink', 'http://www.w3.org/1999/xlink') sld = document.toString() if qgisLayerItem.layer.labelsEnabled(): labelSld = getLabelingAsSld(qgisLayerItem.layer) sld = sld.replace('</se:Rule>', labelSld + '</se:Rule>') sld = sld.replace('ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"', 'ogc:Filter') # the following fixes weird problems with the sld compability with the # shogun webapp sld = sld.replace('<ogc:And>', '') sld = sld.replace('</ogc:And>', '') sld = sld.replace('<se:Name> ', '<se:Name>') sld = sld.replace(' </se:Name>', '</se:Name>') sld = sld.replace('StyledLayerDescriptor', 'sld:StyledLayerDescriptor') sld = sld.replace('UserStyle', 'sld:UserStyle') sld = sld.replace('se:', 'sld:') sld = sld.replace('SvgParameter', 'CssParameter') sld = sld.replace('\n', '') sld = sld.replace('\t', '') return sld
def getObservations(self, offering="", properties=[], features=[], procedures=[], filters=None, resultModel=""): """ :param offering: Offering name :type offering: str :param properties: Selected properties names :type properties: str list :param features: Selected features of interest names :type features: str list :param procedures: Selected procedures names :type procedures: str list :param filters: Configured filters :type filters: FilterRequest :param resultModel: Selected result model :type resultModel: str :return: xml data """ doc = QDomDocument() doc.appendChild( doc.createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"')) root = doc.createElement('GetObservation') root.setAttribute('xmlns', "http://www.opengis.net/sos/1.0") root.setAttribute('xmlns:ows', "http://www.opengis.net/ows/1.1") root.setAttribute('xmlns:gml', "http://www.opengis.net/gml") root.setAttribute('xmlns:ogc', "http://www.opengis.net/ogc") root.setAttribute('xmlns:om', "http://www.opengis.net/om/1.0") root.setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance") root.setAttribute( 'xsi:schemaLocation', "http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd" ) root.setAttribute('service', "SOS") root.setAttribute('version', "2.0.0") root.setAttribute('srsName', self[offering].srsName) doc.appendChild(root) offer = doc.createElement("offering") offer.appendChild(doc.createTextNode(offering)) root.appendChild(offer) if filters.temporalFilter: timeEvent = doc.createElement("eventTime") operator = doc.createElement("ogc:%s" % filters.temporalOperator) prop = doc.createElement("ogc:PropertyName") prop.appendChild(doc.createTextNode("om:samplingTime")) operand = doc.createElement(filters.temporalOperand) if filters.temporalOperand == "gml:TimeInstant": timePos = doc.createElement("gml:timePosition") timePos.appendChild( doc.createTextNode(str(filters.temporalValue))) operand.appendChild(timePos) elif filters.temporalOperand == "gml:TimePeriod": begin = doc.createElement("gml:beginPosition") begin.appendChild( doc.createTextNode(str(filters.temporalValue).split()[0])) end = doc.createElement("gml:endPosition") end.appendChild( doc.createTextNode(str(filters.temporalValue).split()[-1])) operand.appendChild(begin) operand.appendChild(end) root.appendChild(timeEvent) timeEvent.appendChild(operator) operator.appendChild(prop) operator.appendChild(operand) for proc in procedures: procElement = doc.createElement("procedure") procElement.appendChild(doc.createTextNode(proc)) root.appendChild(procElement) for prop in properties: propElement = doc.createElement("observedProperty") propElement.appendChild(doc.createTextNode(prop)) root.appendChild(propElement) foi = doc.createElement("featureOfInterest") if len(features) else None for foiName in features: foiElement = doc.createElement("ObjectID") foiElement.appendChild(doc.createTextNode(foiName)) foi.appendChild(foiElement) if filters.spatialFilter and not foi: foi = doc.createElement("featureOfInterest") operator = doc.createElement("ogc:%s" % filters.spatialOperator) prop = doc.createElement("ogc:PropertyName") prop.appendChild(doc.createTextNode("urn:ogc:data:location")) operator.appendChild(prop) try: if filters.spatialOperand == "gml:Point": gmlNode = QgsOgcUtils.geometryToGML( QgsGeometry.fromPoint(filters._spatialValue), doc) elif filters.spatialOperand == "gml:Envelope": gmlNode = QgsOgcUtils.rectangleToGMLEnvelope( QgsGeometry.fromRect( filters._spatialValue).boundingBox(), doc) elif filters.spatialOperand == "gml:Polygon": gmlNode = QgsOgcUtils.geometryToGML( QgsGeometry.fromPolygon(filters._spatialValue), doc) elif filters.spatialOperand == "gml:LineString": gmlNode = QgsOgcUtils.geometryToGML( QgsGeometry.fromPolyline(filters._spatialValue), doc) gmlNode.setAttribute('srsName', self[offering].srsName) operator.appendChild(gmlNode) except: pass foi.appendChild(operator) #Lista de features o filtro espacial if foi: root.appendChild(foi) if filters.scalarFilter: result = doc.createElement("result") operator = doc.createElement("ogc:PropertyIs%s" % filters.scalarOperator) prop = doc.createElement("ogc:PropertyName") prop.appendChild(doc.createTextNode(filters.scalarOperand)) operator.appendChild(prop) if filters.scalarOperator in ["Between"]: try: lower = doc.createElement("ogc:LowerBoundary") lowValue = doc.createElement("ogc:Literal") lowValue.appendChild( doc.createTextNode( str(filters.scalarValue).split()[0])) lower.appendChild(lowValue) upper = doc.createElement("ogc:UpperBoundary") upValue = doc.createElement("ogc:Literal") upValue.appendChild( doc.createTextNode( str(filters.scalarValue).split()[-1])) upper.appendChild(upValue) operator.appendChild(lower) operator.appendChild(upper) except: pass else: value = doc.createElement("ogc:Literal") value.appendChild(doc.createTextNode(str(filters.scalarValue))) operator.appendChild(value) root.appendChild(result) result.appendChild(operator) responseFormat = doc.createElement("responseFormat") responseFormat.appendChild( doc.createTextNode('text/xml;subtype="om/2.0.0"')) root.appendChild(responseFormat) resultModelElement = doc.createElement("resultModel") resultModelElement.appendChild(doc.createTextNode(resultModel)) root.appendChild(resultModelElement) responseMode = doc.createElement("responseMode") responseMode.appendChild(doc.createTextNode("inline")) root.appendChild(responseMode) return doc.toString(4)