• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python QtXml.QDomDocument类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中qgis.PyQt.QtXml.QDomDocument的典型用法代码示例。如果您正苦于以下问题:Python QDomDocument类的具体用法?Python QDomDocument怎么用?Python QDomDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了QDomDocument类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testQgsSvgMarkerSymbolLayer

    def testQgsSvgMarkerSymbolLayer(self):
        """
        Create a new style from a .sld file and match test
        """
        mTestName = 'QgsSvgMarkerSymbolLayer'
        mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))

        mDoc = QDomDocument(mTestName)
        mFile = QFile(mFilePath)
        mFile.open(QIODevice.ReadOnly)
        mDoc.setContent(mFile, True)
        mFile.close()
        mSymbolLayer = QgsSvgMarkerSymbolLayer.createFromSld(mDoc.elementsByTagName('PointSymbolizer').item(0).toElement())

        mExpectedValue = type(QgsSvgMarkerSymbolLayer(""))
        mValue = type(mSymbolLayer)
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 'skull.svg'
        mValue = os.path.basename(mSymbolLayer.path())
        print(("VALUE", mSymbolLayer.path()))
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 12
        mValue = mSymbolLayer.size()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 45
        mValue = mSymbolLayer.angle()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage
开发者ID:mj10777,项目名称:QGIS,代码行数:34,代码来源:test_qgssymbollayer.py


示例2: testReadWriteXml

    def testReadWriteXml(self):
        p = QgsProject()
        l = QgsLayout(p)
        l.initializeDefaults()
        guides = l.guides()

        # add some guides
        g1 = QgsLayoutGuide(Qt.Horizontal, QgsLayoutMeasurement(5, QgsUnitTypes.LayoutCentimeters), l.pageCollection().page(0))
        guides.addGuide(g1)
        g2 = QgsLayoutGuide(Qt.Vertical, QgsLayoutMeasurement(6, QgsUnitTypes.LayoutInches), l.pageCollection().page(0))
        guides.addGuide(g2)

        guides.setVisible(False)

        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        self.assertTrue(guides.writeXml(elem, doc, QgsReadWriteContext()))

        l2 = QgsLayout(p)
        l2.initializeDefaults()
        guides2 = l2.guides()

        self.assertTrue(guides2.readXml(elem.firstChildElement(), doc, QgsReadWriteContext()))
        guide_list = guides2.guidesOnPage(0)
        self.assertEqual(len(guide_list), 2)

        self.assertEqual(guide_list[0].orientation(), Qt.Horizontal)
        self.assertEqual(guide_list[0].position().length(), 5.0)
        self.assertEqual(guide_list[0].position().units(), QgsUnitTypes.LayoutCentimeters)
        self.assertEqual(guide_list[1].orientation(), Qt.Vertical)
        self.assertEqual(guide_list[1].position().length(), 6.0)
        self.assertEqual(guide_list[1].position().units(), QgsUnitTypes.LayoutInches)
开发者ID:pblottiere,项目名称:QGIS,代码行数:32,代码来源:test_qgslayoutguides.py


示例3: copy_layer_settings

    def copy_layer_settings(self, source_layer, target_layer):
        # copy filter

        if target_layer.type() == QgsVectorLayer:
            target_layer.setSubsetString(source_layer.subsetString())

        # copy symbology
        error = ""
        doc = QDomDocument()
        node = doc.createElement("symbology")
        doc.appendChild(node)
        source_layer.writeSymbology(node, doc, error,  QgsReadWriteContext())

        if not error:
            target_layer.readSymbology(node, error,  QgsReadWriteContext())
        if error:
            QMessageBox.warning(None, "Could not copy symbology", error)

        # copy scale based visibility
        try:
            target_layer.setScaleBasedVisibility(source_layer.hasScaleBasedVisibility())
        except:
            # Fall back to the deprecated function
            target_layer.toggleScaleBasedVisibility(source_layer.hasScaleBasedVisibility())
        target_layer.setMinimumScale(source_layer.minimumScale())
        target_layer.setMaximumScale(source_layer.maximumScale())

        #copy CRS
        target_layer.setCrs(source_layer.crs(), False)
开发者ID:qgiscloud,项目名称:qgis-cloud-plugin,代码行数:29,代码来源:data_upload.py


示例4: testQgsSVGFillSymbolLayer

    def testQgsSVGFillSymbolLayer(self):
        """
        Create a new style from a .sld file and match test
        """
        mTestName = 'QgsSVGFillSymbolLayer'
        mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))

        mDoc = QDomDocument(mTestName)
        mFile = QFile(mFilePath)
        mFile.open(QIODevice.ReadOnly)
        mDoc.setContent(mFile, True)
        mFile.close()
        mSymbolLayer = QgsSVGFillSymbolLayer.createFromSld(
            mDoc.elementsByTagName('PolygonSymbolizer').item(0).toElement())

        mExpectedValue = type(QgsSVGFillSymbolLayer(""))
        mValue = type(mSymbolLayer)
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 'accommodation_camping.svg'
        mValue = os.path.basename(mSymbolLayer.svgFilePath())
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 6
        mValue = mSymbolLayer.patternWidth()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage
开发者ID:mj10777,项目名称:QGIS,代码行数:29,代码来源:test_qgssymbollayer.py


示例5: testWriteReadXmlProj6

    def testWriteReadXmlProj6(self):
        # setup a context
        context = QgsCoordinateTransformContext()

        proj_1 = '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=intl +step +proj=helmert +x=-18.944 +y=-379.364 +z=-24.063 +rx=-0.04 +ry=0.764 +rz=-6.431 +s=3.657 +convention=coordinate_frame +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        proj_2 = '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=intl +step +proj=helmert +x=-150 +y=-250 +z=-1 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'

        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(4204),
                                                       QgsCoordinateReferenceSystem(4326), proj_1))
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(4205),
                                                       QgsCoordinateReferenceSystem(4326), proj_2))

        self.assertEqual(context.coordinateOperations(),
                         {('EPSG:4204', 'EPSG:4326'): proj_1,
                          ('EPSG:4205', 'EPSG:4326'): proj_2})

        # save to xml
        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        context.writeXml(elem, QgsReadWriteContext())

        # restore from xml
        context2 = QgsCoordinateTransformContext()
        context2.readXml(elem, QgsReadWriteContext())

        # check result
        self.assertEqual(context2.coordinateOperations(),
                         {('EPSG:4204', 'EPSG:4326'): proj_1,
                          ('EPSG:4205', 'EPSG:4326'): proj_2})
开发者ID:digitalsatori,项目名称:QGIS,代码行数:29,代码来源:test_qgscoordinatetransformcontext.py


示例6: layerToSld

 def layerToSld(self, layer, properties={}):
     dom = QDomDocument()
     root = dom.createElement("FakeRoot")
     dom.appendChild(root)
     errorMessage = ''
     layer.writeSld(root, dom, errorMessage, properties)
     return dom, root, errorMessage
开发者ID:m-kuhn,项目名称:QGIS,代码行数:7,代码来源:test_qgsrasterlayer.py


示例7: testReadWriteXml

    def testReadWriteXml(self):
        """
        Test reading and writing layout manager state to XML
        """
        project = QgsProject()
        manager = QgsLayoutManager(project)

        # add a bunch of layouts
        layout = QgsPrintLayout(project)
        layout.setName('test layout')
        layout2 = QgsPrintLayout(project)
        layout2.setName('test layout2')
        layout3 = QgsPrintLayout(project)
        layout3.setName('test layout3')

        manager.addLayout(layout)
        manager.addLayout(layout2)
        manager.addLayout(layout3)

        # save to xml
        doc = QDomDocument("testdoc")
        elem = manager.writeXml(doc)
        doc.appendChild(elem)

        # restore from xml
        project2 = QgsProject()
        manager2 = QgsLayoutManager(project2)
        self.assertTrue(manager2.readXml(elem, doc))

        self.assertEqual(len(manager2.layouts()), 3)
        names = [c.name() for c in manager2.layouts()]
        self.assertCountEqual(names, ['test layout', 'test layout2', 'test layout3'])
开发者ID:mhugo,项目名称:QGIS,代码行数:32,代码来源:test_qgslayoutmanager.py


示例8: testQgsCentroidFillSymbolLayerV2

    def testQgsCentroidFillSymbolLayerV2(self):
        """
        Create a new style from a .sld file and match test
        """
        mTestName = 'QgsCentroidFillSymbolLayerV2'
        mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))

        mDoc = QDomDocument(mTestName)
        mFile = QFile(mFilePath)
        mFile.open(QIODevice.ReadOnly)
        mDoc.setContent(mFile, True)
        mFile.close()
        mSymbolLayer = QgsCentroidFillSymbolLayerV2.createFromSld(
            mDoc.elementsByTagName('PointSymbolizer').item(0).toElement())

        mExpectedValue = type(QgsCentroidFillSymbolLayerV2())
        mValue = type(mSymbolLayer)
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = u'regular_star'
        mValue = mSymbolLayer.subSymbol().symbolLayer(0).name()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = u'#55aaff'
        mValue = mSymbolLayer.subSymbol().symbolLayer(0).color().name()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = u'#00ff00'
        mValue = mSymbolLayer.subSymbol().symbolLayer(0).borderColor().name()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage
开发者ID:PeterTFS,项目名称:QGIS,代码行数:34,代码来源:test_qgssymbollayerv2.py


示例9: on_btnLoad_clicked

    def on_btnLoad_clicked(self):
        fileName, _ = QFileDialog.getOpenFileName(None,
                                                  self.tr('Import Colors and elevations from XML'),
                                                  QDir.homePath(),
                                                  self.tr('XML files (*.xml *.XML)'))
        if fileName == '':
            return

        doc = QDomDocument()
        with codecs.open(fileName, 'r', encoding='utf-8') as f:
            content = f.read()

        if not doc.setContent(content):
            QMessageBox.critical(None,
                                 self.tr('Error parsing XML'),
                                 self.tr('The XML file could not be loaded'))
            return

        self.reliefClassTree.clear()
        reliefColorList = doc.elementsByTagName('ReliefColor')
        for i in range(reliefColorList.length()):
            elem = reliefColorList.at(i).toElement()
            item = QTreeWidgetItem()
            item.setText(0, elem.attribute('MinElevation'))
            item.setText(1, elem.attribute('MaxElevation'))
            item.setBackground(2, QBrush(QColor(int(elem.attribute('red')),
                                                int(elem.attribute('green')),
                                                int(elem.attribute('blue')))))
            self.reliefClassTree.addTopLevelItem(item)
开发者ID:cayetanobv,项目名称:QGIS,代码行数:29,代码来源:ReliefColorsWidget.py


示例10: layerToSld

 def layerToSld(self, mapLayer):
     dom = QDomDocument()
     root = dom.createElement("FakeRoot")
     dom.appendChild(root)
     error = None
     mapLayer.writeSld(root, dom, error, {})
     return dom, root
开发者ID:rskelly,项目名称:QGIS,代码行数:7,代码来源:test_qgssymbollayer_createsld.py


示例11: testMissingTransformsProj6

    def testMissingTransformsProj6(self):
        return # TODO -- this seems impossible to determine with existing PROJ6 api
        # fudge context xml with a missing transform
        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        contextElem = doc.createElement("transformContext")
        transformElem = doc.createElement("srcDest")
        transformElem.setAttribute("source", 'EPSG:4204')
        transformElem.setAttribute("dest", 'EPSG:4326')

        # fake a proj string with a grid which will NEVER exist
        fake_proj = '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +inv +proj=hgridshift +grids=this_is_not_a_real_grid.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        transformElem.setAttribute("coordinateOp", fake_proj)
        contextElem.appendChild(transformElem)

        elem2 = doc.createElement("test2")
        elem2.appendChild(contextElem)

        # restore from xml
        context2 = QgsCoordinateTransformContext()
        ok, errors = context2.readXml(elem2, QgsReadWriteContext())
        self.assertFalse(ok)

        # check result
        self.assertEqual(errors, ['not valid'])
开发者ID:digitalsatori,项目名称:QGIS,代码行数:25,代码来源:test_qgscoordinatetransformcontext.py


示例12: testSubstitutionMap

    def testSubstitutionMap(self):
        """Test that we can use degree symbols in substitutions.
        """
        # Create a point and convert it to text containing a degree symbol.
        myPoint = QgsPoint(12.3, -33.33)
        myCoordinates = myPoint.toDegreesMinutesSeconds(2)
        myTokens = myCoordinates.split(',')
        myLongitude = myTokens[0]
        myLatitude = myTokens[1]
        myText = 'Latitude: %s, Longitude: %s' % (myLatitude, myLongitude)

        # Load the composition with the substitutions
        myComposition = QgsComposition(self.iface.mapCanvas().mapSettings())
        mySubstitutionMap = {'replace-me': myText}
        myFile = os.path.join(TEST_DATA_DIR, 'template-for-substitution.qpt')
        with open(myFile) as f:
            myTemplateContent = f.read()
        myDocument = QDomDocument()
        myDocument.setContent(myTemplateContent)
        myComposition.loadFromTemplate(myDocument, mySubstitutionMap)

        # We should be able to get map0
        myMap = myComposition.getComposerMapById(0)
        myMessage = ('Map 0 could not be found in template %s', myFile)
        assert myMap is not None, myMessage
开发者ID:spono,项目名称:QGIS,代码行数:25,代码来源:test_qgscomposition.py


示例13: testReadExtentOnTable

    def testReadExtentOnTable(self):
        # vector layer based on a standard table
        vl0 = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'pk\' srid=4326 type=POLYGON table="qgis_test"."some_poly_data" (geom) sql=', 'test', 'postgres')
        self.assertTrue(vl0.isValid())
        self.assertTrue(vl0.dataProvider().hasMetadata())

        # set a custom extent
        originalExtent = vl0.extent()

        customExtent = QgsRectangle(-80, 80, -70, 90)
        vl0.setExtent(customExtent)

        # write xml
        doc = QDomDocument("testdoc")
        elem = doc.createElement("maplayer")
        self.assertTrue(vl0.writeLayerXml(elem, doc, QgsReadWriteContext()))

        # read xml with the custom extent. It should not be used by default
        vl1 = QgsVectorLayer()
        vl1.readLayerXml(elem, QgsReadWriteContext())
        self.assertTrue(vl1.isValid())

        self.assertEqual(vl1.extent(), originalExtent)

        # read xml with custom extent with readExtent option. Extent read from
        # xml document should NOT be used because we don't have a view or a
        # materialized view
        vl2 = QgsVectorLayer()
        vl2.setReadExtentFromXml(True)
        vl2.readLayerXml(elem, QgsReadWriteContext())
        self.assertTrue(vl2.isValid())

        self.assertEqual(vl2.extent(), originalExtent)
开发者ID:giohappy,项目名称:QGIS,代码行数:33,代码来源:test_provider_postgres.py


示例14: testWriteReadXmlSingleVariant

    def testWriteReadXmlSingleVariant(self):
        # setup a context
        context = QgsCoordinateTransformContext()
        self.assertTrue(context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1))
        self.assertTrue(context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'), 2))
        self.assertTrue(context.addDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3113'), 11))
        self.assertTrue(context.addDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28355'), 12))
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                                                   QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2))
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                                   QgsCoordinateReferenceSystem(4283), 3, 4))

        self.assertEqual(context.sourceDatumTransforms(), {'EPSG:3111': 1, 'EPSG:28356': 2})
        self.assertEqual(context.destinationDatumTransforms(), {'EPSG:3113': 11, 'EPSG:28355': 12})
        self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
                                                                      ('EPSG:28356', 'EPSG:4283'): (3, 4)})

        # save to xml
        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        context.writeXml(elem, QgsReadWriteContext())

        # restore from xml
        context2 = QgsCoordinateTransformContext()
        context2.readXml(elem, QgsReadWriteContext())

        # check result
        self.assertEqual(context2.sourceDatumTransforms(), {'EPSG:3111': 1, 'EPSG:28356': 2})
        self.assertEqual(context2.destinationDatumTransforms(), {'EPSG:3113': 11, 'EPSG:28355': 12})
        self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
                                                                       ('EPSG:28356', 'EPSG:4283'): (3, 4)})
开发者ID:alexbruy,项目名称:QGIS,代码行数:31,代码来源:test_qgscoordinatetransformcontext.py


示例15: testWriteReadXml

    def testWriteReadXml(self):
        # setup a context
        context = QgsCoordinateTransformContext()

        source_id_1 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4204),
                                                             QgsCoordinateReferenceSystem(4326))[0].sourceTransformId
        dest_id_1 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4204),
                                                           QgsCoordinateReferenceSystem(4326))[0].destinationTransformId

        source_id_2 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4205),
                                                             QgsCoordinateReferenceSystem(4326))[0].sourceTransformId
        dest_id_2 = QgsDatumTransform.datumTransformations(QgsCoordinateReferenceSystem(4205),
                                                           QgsCoordinateReferenceSystem(4326))[0].destinationTransformId

        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(4204),
                                                                   QgsCoordinateReferenceSystem(4326), source_id_1, dest_id_1))
        self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem(4205),
                                                                   QgsCoordinateReferenceSystem(4326), source_id_2, dest_id_2))

        self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:4204', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
                                                                      ('EPSG:4205', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_2, dest_id_2)})

        # save to xml
        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        context.writeXml(elem, QgsReadWriteContext())

        # restore from xml
        context2 = QgsCoordinateTransformContext()
        context2.readXml(elem, QgsReadWriteContext())

        # check result
        self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:4204', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_1, dest_id_1),
                                                                       ('EPSG:4205', 'EPSG:4326'): QgsDatumTransform.TransformPair(source_id_2, dest_id_2)})
开发者ID:alexbruy,项目名称:QGIS,代码行数:34,代码来源:test_qgscoordinatetransformcontext.py


示例16: testReadWriteXml

    def testReadWriteXml(self):
        """
        Test reading and writing layout manager state to XML
        """
        project = QgsProject()
        manager = QgsLayoutManager(project)

        # add a bunch of compositions
        composition = QgsComposition(project)
        composition.setName('test composition')
        composition2 = QgsComposition(project)
        composition2.setName('test composition2')
        composition3 = QgsComposition(project)
        composition3.setName('test composition3')

        manager.addComposition(composition)
        manager.addComposition(composition2)
        manager.addComposition(composition3)

        # save to xml
        doc = QDomDocument("testdoc")
        elem = manager.writeXml(doc)
        doc.appendChild(elem)

        # restore from xml
        project2 = QgsProject()
        manager2 = QgsLayoutManager(project2)
        self.assertTrue(manager2.readXml(elem, doc))

        self.assertEqual(len(manager2.compositions()), 3)
        names = [c.name() for c in manager2.compositions()]
        self.assertEqual(set(names), {'test composition', 'test composition2', 'test composition3'})
开发者ID:exlimit,项目名称:QGIS,代码行数:32,代码来源:test_qgslayoutmanager.py


示例17: _change_data_source

    def _change_data_source(self, layer, datasource, provider_key):
        """Due to the fact that a project r/w context is not available inside
        the map layers classes, the original style and subset string restore
        happens in app, this function replicates app behavior"""

        options = QgsDataProvider.ProviderOptions()

        subset_string = ''
        if not layer.isValid():
            try:
                subset_string = layer.dataProvider().subsetString()
            except:
                pass

        layer.setDataSource(datasource, layer.name(), provider_key, options)

        if subset_string:
            layer.setSubsetString(subset_string)

        self.assertTrue(layer.originalXmlProperties(), layer.name())
        context = QgsReadWriteContext()
        context.setPathResolver(QgsProject.instance().pathResolver())
        errorMsg = ''
        doc = QDomDocument()
        self.assertTrue(doc.setContent(layer.originalXmlProperties()))
        layer_node = QDomNode(doc.firstChild())
        self.assertTrue(layer.readSymbology(layer_node, errorMsg, context))
开发者ID:mbernasocchi,项目名称:QGIS,代码行数:27,代码来源:test_qgsprojectbadlayers.py


示例18: testSaveCanvasVariablesToProject

    def testSaveCanvasVariablesToProject(self):
        """
        Ensure that temporary canvas atlas variables are not written to project
        """
        c1 = QgsMapCanvas()
        c1.setObjectName('c1')
        c1.expressionContextScope().setVariable('atlas_featurenumber', 1111)
        c1.expressionContextScope().setVariable('atlas_pagename', 'bb')
        c1.expressionContextScope().setVariable('atlas_feature', QgsFeature(1))
        c1.expressionContextScope().setVariable('atlas_featureid', 22)
        c1.expressionContextScope().setVariable('atlas_geometry', QgsGeometry.fromWkt('Point( 1 2 )'))
        c1.expressionContextScope().setVariable('vara', 1111)
        c1.expressionContextScope().setVariable('varb', 'bb')

        doc = QDomDocument("testdoc")
        elem = doc.createElement("qgis")
        doc.appendChild(elem)
        c1.writeProject(doc)

        c2 = QgsMapCanvas()
        c2.setObjectName('c1')
        c2.readProject(doc)

        self.assertCountEqual(c2.expressionContextScope().variableNames(), ['vara', 'varb'])
        self.assertEqual(c2.expressionContextScope().variable('vara'), 1111)
        self.assertEqual(c2.expressionContextScope().variable('varb'), 'bb')
开发者ID:boundlessgeo,项目名称:QGIS,代码行数:26,代码来源:test_qgsmapcanvas.py


示例19: testReadWriteXml

    def testReadWriteXml(self):
        pr = QgsProject()
        l = QgsLayout(pr)

        p = QPolygonF()
        p.append(QPointF(0.0, 0.0))
        p.append(QPointF(100.0, 0.0))
        p.append(QPointF(200.0, 100.0))
        shape = QgsLayoutItemPolyline(p, l)

        props = {}
        props["color"] = "255,0,0,255"
        props["width"] = "10.0"
        props["capstyle"] = "square"

        style = QgsLineSymbol.createSimple(props)
        shape.setSymbol(style)

        #save original item to xml
        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        self.assertTrue(shape.writeXml(elem, doc, QgsReadWriteContext()))

        shape2 = QgsLayoutItemPolyline(l)
        self.assertTrue(shape2.readXml(elem.firstChildElement(), doc, QgsReadWriteContext()))

        self.assertEqual(shape2.nodes(), shape.nodes())
        self.assertEqual(shape2.symbol().symbolLayer(0).color().name(), '#ff0000')
开发者ID:dmarteau,项目名称:QGIS,代码行数:28,代码来源:test_qgslayoutpolyline.py


示例20: testSaveMultipleCanvasesToProject

    def testSaveMultipleCanvasesToProject(self):
        # test saving/restoring canvas state to project with multiple canvases
        c1 = QgsMapCanvas()
        c1.setObjectName('c1')
        c1.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3111'))
        c1.setRotation(45)
        c2 = QgsMapCanvas()
        c2.setObjectName('c2')
        c2.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
        c2.setRotation(65)

        doc = QDomDocument("testdoc")
        elem = doc.createElement("qgis")
        doc.appendChild(elem)
        c1.writeProject(doc)
        c2.writeProject(doc)

        c3 = QgsMapCanvas()
        c3.setObjectName('c1')
        c4 = QgsMapCanvas()
        c4.setObjectName('c2')
        c3.readProject(doc)
        c4.readProject(doc)

        self.assertEqual(c3.mapSettings().destinationCrs().authid(), 'EPSG:3111')
        self.assertEqual(c3.rotation(), 45)
        self.assertEqual(c4.mapSettings().destinationCrs().authid(), 'EPSG:4326')
        self.assertEqual(c4.rotation(), 65)
开发者ID:timlinux,项目名称:QGIS,代码行数:28,代码来源:test_qgsmapcanvas.py



注:本文中的qgis.PyQt.QtXml.QDomDocument类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sip.isdeleted函数代码示例发布时间:2022-05-26
下一篇:
Python QtWidgets.QWidget类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap