当前位置: 首页>>代码示例>>Python>>正文


Python utilities.compareWkt函数代码示例

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


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

示例1: testInsertVertex

    def testInsertVertex(self):
        linestring = QgsGeometry.fromWkt( "LINESTRING(1 0,2 0)" )

        if TestQgsGeometry.wkbPtr:
          # CHANGE old implementation fails to insert vertex
          assert linestring.insertVertex( 0, 0, 0 ), "Insert vertex 0 0 at 0 failed"
          expwkt = "LINESTRING(0 0, 1 0, 2 0)"
          wkt = linestring.exportToWkt()
          assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        assert linestring.insertVertex( 1.5, 0, 2 if TestQgsGeometry.wkbPtr else 1 ), "Insert vertex 1.5 0 at 2 failed"
        expwkt = "LINESTRING(0 0, 1 0, 1.5 0, 2 0)" if TestQgsGeometry.wkbPtr else "LINESTRING(1 0, 1.5 0, 2 0)"
        wkt = linestring.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        assert not linestring.insertVertex( 3, 0, 5 ), "Insert vertex 3 0 at 5 should have failed"

        polygon = QgsGeometry.fromWkt( "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,5 2,3 2,3 1,4 1,4 0)))" )
        assert polygon.insertVertex( 0, 0, 8 ), "Insert vertex 0 0 at 8 failed"
        expwkt = "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,0 0,5 0,5 2,3 2,3 1,4 1,4 0)))"
        wkt = polygon.exportToWkt()

        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )
        polygon = QgsGeometry.fromWkt( "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,5 2,3 2,3 1,4 1,4 0)))" )
        assert polygon.insertVertex( 0, 0, 7 ), "Insert vertex 0 0 at 7 failed"
        expwkt = "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((0 0,4 0,5 0,5 2,3 2,3 1,4 1,0 0)))"
        wkt = polygon.exportToWkt()

        if TestQgsGeometry.wkbPtr:
          # CHANGE old implementation produces: MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),())
          assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )
开发者ID:idesign3000,项目名称:QGIS,代码行数:31,代码来源:test_qgsgeometry.py

示例2: testAsWktCoordinates

 def testAsWktCoordinates(self):
     """Test that we can get a proper wkt representation fo the rect"""
     rect1 = QgsRectangle(0.0, 0.0, 5.0, 5.0)
     myExpectedWkt = "0 0, " "5 5"
     myWkt = rect1.asWktCoordinates()
     myMessage = "Expected: %s\nGot: %s\n" % (myExpectedWkt, myWkt)
     assert compareWkt(myWkt, myExpectedWkt), myMessage
开发者ID:dwadler,项目名称:QGIS,代码行数:7,代码来源:test_qgsrectangle.py

示例3: testWriteShapefileWithMultiConversion

    def testWriteShapefileWithMultiConversion(self):
        """Check writing geometries to an ESRI shapefile with conversion to multi."""
        ml = QgsVectorLayer(("Point?crs=epsg:4326&field=id:int"), "test", "memory")

        self.assertIsNotNone(ml, "Provider not initialized")
        self.assertTrue(ml.isValid(), "Source layer not valid")
        provider = ml.dataProvider()
        self.assertIsNotNone(provider)

        ft = QgsFeature()
        ft.setGeometry(QgsGeometry.fromWkt("Point (1 2)"))
        ft.setAttributes([1])
        res, features = provider.addFeatures([ft])
        self.assertTrue(res)
        self.assertTrue(features)

        dest_file_name = os.path.join(str(QDir.tempPath()), "to_multi.shp")
        crs = QgsCoordinateReferenceSystem()
        crs.createFromId(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
        write_result = QgsVectorFileWriter.writeAsVectorFormat(
            ml, dest_file_name, "utf-8", crs, "ESRI Shapefile", forceMulti=True
        )
        self.assertEqual(write_result, QgsVectorFileWriter.NoError)

        # Open result and check
        created_layer = QgsVectorLayer("{}|layerid=0".format(dest_file_name), "test", "ogr")
        f = next(created_layer.getFeatures(QgsFeatureRequest()))
        g = f.geometry()
        wkt = g.exportToWkt()
        expWkt = "MultiPoint ((1 2))"
        self.assertTrue(
            compareWkt(expWkt, wkt),
            "saving geometry with multi conversion failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt),
        )
开发者ID:liminlu0314,项目名称:QGIS,代码行数:34,代码来源:test_qgsvectorfilewriter.py

示例4: testAsWktPolygon

 def testAsWktPolygon(self):
     """Test that we can get a proper rect wkt polygon representation for rect"""
     rect1 = QgsRectangle(0.0, 0.0, 5.0, 5.0)
     myExpectedWkt = "POLYGON((0 0, " "5 0, " "5 5, " "0 5, " "0 0))"
     myWkt = rect1.asWktPolygon()
     myMessage = "Expected: %s\nGot: %s\n" % (myExpectedWkt, myWkt)
     assert compareWkt(myWkt, myExpectedWkt), myMessage
开发者ID:dwadler,项目名称:QGIS,代码行数:7,代码来源:test_qgsrectangle.py

示例5: testGeometry

    def testGeometry(self):
        """ Test calculation of aggregates on geometry expressions """

        layer = QgsVectorLayer("Point?", "layer", "memory")
        pr = layer.dataProvider()

        # must be same length:
        geometry_values = [
            QgsGeometry.fromWkt("Point ( 0 0 )"),
            QgsGeometry.fromWkt("Point ( 1 1 )"),
            QgsGeometry.fromWkt("Point ( 2 2 )"),
        ]

        features = []
        for i in range(len(geometry_values)):
            f = QgsFeature()
            f.setGeometry(geometry_values[i])
            features.append(f)
        self.assertTrue(pr.addFeatures(features))

        agg = QgsAggregateCalculator(layer)

        val, ok = agg.calculate(QgsAggregateCalculator.GeometryCollect, "$geometry")
        self.assertTrue(ok)
        expwkt = "MultiPoint ((0 0), (1 1), (2 2))"
        wkt = val.exportToWkt()
        self.assertTrue(compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt))
开发者ID:medspx,项目名称:QGIS,代码行数:27,代码来源:test_qgsaggregatecalculator.py

示例6: testMoveVertex

    def testMoveVertex(self):
        multipoint = QgsGeometry.fromWkt( "MULTIPOINT(5 0,0 0,0 4,5 4,5 1,1 1,1 3,4 3,4 2,2 2)" )
        for i in range(0,10):
          assert multipoint.moveVertex( i+1, -1-i, i ), "move vertex %d failed" % i
        expwkt = "MULTIPOINT(1 -1, 2 -2, 3 -3, 4 -4, 5 -5, 6 -6, 7 -7, 8 -8, 9 -9, 10 -10)"
        wkt = multipoint.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        # 2-+-+-+-+-3
        # |         |
        # + 6-+-+-7 +
        # | |     | |
        # + + 9-+-8 +
        # | |       |
        # ! 5-+-+-+-4 !
        # |
        # 1-+-+-+-+-0 !
        polyline = QgsGeometry.fromWkt( "LINESTRING(5 0,0 0,0 4,5 4,5 1,1 1,1 3,4 3,4 2,2 2)" )
        assert polyline.moveVertex( 5.5, 4.5, 3 ), "move vertex failed"
        expwkt = "LINESTRING(5 0, 0 0, 0 4, 5.5 4.5, 5 1, 1 1, 1 3, 4 3, 4 2, 2 2)"
        wkt = polyline.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        # 5-+-4 0-+-9
        # |   | |   |
        # 6 2-3 1-2!+
        # | |     | |
        # 0-1     7-8
        polygon = QgsGeometry.fromWkt( "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,5 2,3 2,3 1,4 1,4 0)))" )
        assert polygon.moveVertex( 6, 2, 9 ), "move vertex failed"
        expwkt = "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,6 2,3 2,3 1,4 1,4 0)))"
        wkt = polygon.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        assert polygon.moveVertex( 1, 2, 0 ), "move vertex failed"
        expwkt = "MULTIPOLYGON(((1 2,1 0,1 1,2 1,2 2,0 2,1 2)),((4 0,5 0,6 2,3 2,3 1,4 1,4 0)))"
        wkt = polygon.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        assert polygon.moveVertex( 2, 1, 7 ), "move vertex failed"
        expwkt = "MULTIPOLYGON(((1 2,1 0,1 1,2 1,2 2,0 2,1 2)),((2 1,5 0,6 2,3 2,3 1,4 1,2 1)))"
        wkt = polygon.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )
开发者ID:idesign3000,项目名称:QGIS,代码行数:43,代码来源:test_qgsgeometry.py

示例7: testAddPart

    def testAddPart(self):
        #   2-3 6-+-7
        #   | | |   |
        # 0-1 4 5   8-9
        points = [
            [ QgsPoint(0,0), QgsPoint(1,0), QgsPoint(1,1), QgsPoint(2,1), QgsPoint(2,0), ],
            [ QgsPoint(3,0), QgsPoint(3,1), QgsPoint(5,1), QgsPoint(5,0), QgsPoint(6,0), ]
          ]

        polyline = QgsGeometry.fromPolyline( points[0] )
        assert polyline.addPart( points[1][0:1] ) == 2, "addPart with one point line unexpectedly succeeded."
        assert polyline.addPart( points[1][0:2] ) == 0, "addPart with two point line failed."
        expwkt = "MULTILINESTRING((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1))"
        wkt = polyline.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        polyline = QgsGeometry.fromPolyline( points[0] )
        assert polyline.addPart( points[1] ) == 0, "addPart with %d point line failed." % len(points[1])
        expwkt = "MULTILINESTRING((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1, 5 1, 5 0, 6 0))"

        # 5-+-4 0-+-9
        # |   | |   |
        # | 2-3 1-2 |
        # | |     | |
        # 0-1     7-8
        points = [
            [ [ QgsPoint(0,0), QgsPoint(1,0), QgsPoint(1,1), QgsPoint(2,1), QgsPoint(2,2), QgsPoint(0,2), QgsPoint(0,0), ] ],
            [ [ QgsPoint(4,0), QgsPoint(5,0), QgsPoint(5,2), QgsPoint(3,2), QgsPoint(3,1), QgsPoint(4,1), QgsPoint(4,0), ] ]
          ]

        polygon = QgsGeometry.fromPolygon( points[0] )

        assert polygon.addPart( points[1][0][0:1] ) == 2, "addPart with one point ring unexpectedly succeeded."
        assert polygon.addPart( points[1][0][0:2] ) == 2, "addPart with two point ring unexpectedly succeeded."
        assert polygon.addPart( points[1][0][0:3] ) == 2, "addPart with unclosed three point ring unexpectedly succeeded."
        assert polygon.addPart( [ QgsPoint(4,0), QgsPoint(5,0), QgsPoint(4,0) ] ) == 2, "addPart with 'closed' three point ring unexpectedly succeeded."

        assert polygon.addPart( points[1][0] ) == 0, "addPart failed"
        expwkt = "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,5 2,3 2,3 1,4 1,4 0)))"
        wkt = polygon.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )
开发者ID:idesign3000,项目名称:QGIS,代码行数:41,代码来源:test_qgsgeometry.py

示例8: testAsWktPolygon

 def testAsWktPolygon(self):
     """Test that we can get a proper rect wkt polygon representation for rect"""
     rect1 = QgsRectangle(0.0, 0.0, 5.0, 5.0)
     myExpectedWkt = ('POLYGON((0 0, '
                      '5 0, '
                      '5 5, '
                      '0 5, '
                      '0 0))')
     myWkt = rect1.asWktPolygon()
     myMessage = ('Expected: %s\nGot: %s\n' %
                  (myExpectedWkt, myWkt))
     assert compareWkt(myWkt, myExpectedWkt), myMessage
开发者ID:phborba,项目名称:QGIS,代码行数:12,代码来源:test_qgsrectangle.py

示例9: testAddFeatures

    def testAddFeatures(self):
        layer = QgsVectorLayer("Point", "test", "pythonprovider")
        provider = layer.dataProvider()

        res = provider.addAttributes([QgsField("name", QVariant.String),
                                      QgsField("age", QVariant.Int),
                                      QgsField("size", QVariant.Double)])
        assert res, "Failed to add attributes"

        myMessage = ('Expected: %s\nGot: %s\n' %
                     (3, len(provider.fields())))

        assert len(provider.fields()) == 3, myMessage

        ft = QgsFeature()
        ft.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(10, 10)))
        ft.setAttributes(["Johny",
                          20,
                          0.3])
        res, t = provider.addFeatures([ft])

        assert res, "Failed to add feature"

        myMessage = ('Expected: %s\nGot: %s\n' %
                     (1, provider.featureCount()))
        assert provider.featureCount() == 1, myMessage

        for f in provider.getFeatures(QgsFeatureRequest()):
            myMessage = ('Expected: %s\nGot: %s\n' %
                         ("Johny", f[0]))

            assert f[0] == "Johny", myMessage

            myMessage = ('Expected: %s\nGot: %s\n' %
                         (20, f[1]))

            assert f[1] == 20, myMessage

            myMessage = ('Expected: %s\nGot: %s\n' %
                         (0.3, f[2]))

            assert (f[2] - 0.3) < 0.0000001, myMessage

            geom = f.geometry()

            myMessage = ('Expected: %s\nGot: %s\n' %
                         ("Point (10 10)", str(geom.asWkt())))

            assert compareWkt(str(geom.asWkt()), "Point (10 10)"), myMessage
开发者ID:yoichigmf,项目名称:QGIS,代码行数:49,代码来源:test_provider_python.py

示例10: testGetFeatures

    def testGetFeatures(self):
        """ Test that expected results are returned when fetching all features """

        # IMPORTANT - we do not use `for f in provider.getFeatures()` as we are also
        # testing that existing attributes & geometry in f are overwritten correctly
        # (for f in ... uses a new QgsFeature for every iteration)

        it = self.provider.getFeatures()
        f = QgsFeature()
        attributes = {}
        geometries = {}
        while it.nextFeature(f):
            # expect feature to be valid
            self.assertTrue(f.isValid())
            # split off the first 5 attributes only - some provider test datasets will include
            # additional attributes which we ignore
            attrs = f.attributes()[0:5]
            # force the num_char attribute to be text - some providers (eg delimited text) will
            # automatically detect that this attribute contains numbers and set it as a numeric
            # field
            attrs[4] = str(attrs[4])
            attributes[f["pk"]] = attrs
            geometries[f["pk"]] = f.hasGeometry() and f.geometry().exportToWkt()

        expected_attributes = {
            5: [5, -200, NULL, "NuLl", "5"],
            3: [3, 300, "Pear", "PEaR", "3"],
            1: [1, 100, "Orange", "oranGe", "1"],
            2: [2, 200, "Apple", "Apple", "2"],
            4: [4, 400, "Honey", "Honey", "4"],
        }
        self.assertEqual(attributes, expected_attributes, "Expected {}, got {}".format(expected_attributes, attributes))

        expected_geometries = {
            1: "Point (-70.332 66.33)",
            2: "Point (-68.2 70.8)",
            3: None,
            4: "Point(-65.32 78.3)",
            5: "Point(-71.123 78.23)",
        }
        for pk, geom in list(expected_geometries.items()):
            if geom:
                assert compareWkt(geom, geometries[pk]), "Geometry {} mismatch Expected:\n{}\nGot:\n{}\n".format(
                    pk, geom, geometries[pk].exportToWkt()
                )
            else:
                self.assertFalse(geometries[pk], "Expected null geometry for {}".format(pk))
开发者ID:mbernasocchi,项目名称:QGIS,代码行数:47,代码来源:providertestbase.py

示例11: recordDifference

 def recordDifference(self, record1, record2):
     # Compare a record defined as a dictionary
     for k in list(record1.keys()):
         if k not in record2:
             return "Field {0} is missing".format(k)
         r1k = record1[k]
         r2k = record2[k]
         if k == geomkey:
             if not compareWkt(r1k, r2k):
                 return "Geometry differs: {0:.50} versus {1:.50}".format(r1k, r2k)
         else:
             if record1[k] != record2[k]:
                 return "Field {0} differs: {1:.50} versus {2:.50}".format(k, repr(r1k), repr(r2k))
     for k in list(record2.keys()):
         if k not in record1:
             return "Output contains extra field {0}".format(k)
     return ''
开发者ID:alexbruy,项目名称:QGIS,代码行数:17,代码来源:test_qgsdelimitedtextprovider.py

示例12: testMultipoint

    def testMultipoint(self):
        # CHANGE previous implementation didn't support multipoint too much
        if not TestQgsGeometry.wkbPtr:
          return

        # #9423
        points = [ QgsPoint(10, 30), QgsPoint(40, 20), QgsPoint(30,10), QgsPoint(20,10) ]
        wkt = "MULTIPOINT (10 30, 40 20, 30 10, 20 10)"
        multipoint = QgsGeometry.fromWkt(wkt)
        assert multipoint.isMultipart(), "Expected MULTIPOINT to be multipart"
        assert multipoint.wkbType() == QGis.WKBMultiPoint, "Expected wkbType to be WKBMultipoint"
        i = 0
        for p in multipoint.asMultiPoint():
                assert p == points[i], "Expected %s at %d, got %s" % (points[i].toString(), i, p.toString())
                i+=1

        multipoint = QgsGeometry.fromWkt( "MULTIPOINT(5 5)" )
        assert multipoint.vertexAt( 0 ) == QgsPoint(5,5), "MULTIPOINT fromWkt failed"

        assert multipoint.insertVertex(4, 4, 0), "MULTIPOINT insert 4,4 at 0 failed"
        expwkt = "MULTIPOINT(4 4, 5 5)"
        wkt = multipoint.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        assert multipoint.insertVertex(7, 7, 2), "MULTIPOINT append 7,7 at 2 failed"
        expwkt = "MULTIPOINT(4 4, 5 5, 7 7)"
        wkt = multipoint.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        assert multipoint.insertVertex(6, 6, 2), "MULTIPOINT append 6,6 at 2 failed"
        expwkt = "MULTIPOINT(4 4, 5 5, 6 6, 7 7)"
        wkt = multipoint.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        assert not multipoint.deleteVertex(4), "MULTIPOINT delete at 4 unexpectedly succeeded"
        assert not multipoint.deleteVertex(-1), "MULTIPOINT delete at -1 unexpectedly succeeded"

        assert multipoint.deleteVertex(1), "MULTIPOINT delete at 1 failed"
        expwkt = "MULTIPOINT(4 4, 6 6, 7 7)"
        wkt = multipoint.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        assert multipoint.deleteVertex(2), "MULTIPOINT delete at 2 failed"
        expwkt = "MULTIPOINT(4 4, 6 6)"
        wkt = multipoint.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        assert multipoint.deleteVertex(0), "MULTIPOINT delete at 2 failed"
        expwkt = "MULTIPOINT(6 6)"
        wkt = multipoint.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )
开发者ID:idesign3000,项目名称:QGIS,代码行数:51,代码来源:test_qgsgeometry.py

示例13: testTranslate

    def testTranslate(self):
        point = QgsGeometry.fromWkt( "POINT(1 1)" )
        assert point.translate( 1, 1 )==0, "Translate failed"
        expwkt = "POINT(2 2)"
        wkt = point.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        point = QgsGeometry.fromWkt( "MULTIPOINT(1 1,2 2,3 3)" )
        assert point.translate( 1, 1 )==0, "Translate failed"
        expwkt = "MULTIPOINT(2 2, 3 3, 4 4)"
        wkt = point.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        linestring = QgsGeometry.fromWkt( "LINESTRING(1 0,2 0)" )

        assert linestring.translate( 1, 1 )==0, "Translate failed"
        expwkt = "LINESTRING(2 1, 3 1)"
        wkt = linestring.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        polygon = QgsGeometry.fromWkt( "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,5 2,3 2,3 1,4 1,4 0)))" )
        assert polygon.translate( 1, 1 )==0, "Translate failed"
        expwkt = "MULTIPOLYGON(((1 1,2 1,2 2,3 2,3 3,1 3,1 1)),((5 1,6 1,6 1,4 3,4 2,5 2,5 1)))"
        wkt = polygon.exportToWkt()

        ct = QgsCoordinateTransform()

        point = QgsGeometry.fromWkt( "POINT(1 1)" )
        assert point.transform( ct )==0, "Translate failed"
        expwkt = "POINT(1 1)"
        wkt = point.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        point = QgsGeometry.fromWkt( "MULTIPOINT(1 1,2 2,3 3)" )
        assert point.transform( ct )==0, "Translate failed"
        expwkt = "MULTIPOINT(1 1, 2 2, 3 3)"
        wkt = point.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        linestring = QgsGeometry.fromWkt( "LINESTRING(1 0,2 0)" )
        assert linestring.transform( ct )==0, "Translate failed"
        expwkt = "LINESTRING(1 0, 2 0)"
        wkt = linestring.exportToWkt()
        assert compareWkt( expwkt, wkt ), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt )

        polygon = QgsGeometry.fromWkt( "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,5 2,3 2,3 1,4 1,4 0)))" )
        assert polygon.transform( ct )==0, "Translate failed"
        expwkt = "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,5 2,3 2,3 1,4 1,4 0)))"
        wkt = polygon.exportToWkt()
开发者ID:SinSiXX,项目名称:QGIS,代码行数:49,代码来源:test_qgsgeometry.py

示例14: testWriteShapefileWithMultiConversion

    def testWriteShapefileWithMultiConversion(self):
        """Check writing geometries to an ESRI shapefile with conversion to multi."""
        ml = QgsVectorLayer(
            ('Point?crs=epsg:4326&field=id:int'),
            'test',
            'memory')

        self.assertIsNotNone(ml, 'Provider not initialized')
        self.assertTrue(ml.isValid(), 'Source layer not valid')
        provider = ml.dataProvider()
        self.assertIsNotNone(provider)

        ft = QgsFeature()
        ft.setGeometry(QgsGeometry.fromWkt('Point (1 2)'))
        ft.setAttributes([1])
        res, features = provider.addFeatures([ft])
        self.assertTrue(res)
        self.assertTrue(features)

        dest_file_name = os.path.join(str(QDir.tempPath()), 'to_multi.shp')
        crs = QgsCoordinateReferenceSystem()
        crs.createFromId(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
        write_result, error_message = QgsVectorFileWriter.writeAsVectorFormat(
            ml,
            dest_file_name,
            'utf-8',
            crs,
            'ESRI Shapefile',
            forceMulti=True)
        self.assertEqual(write_result, QgsVectorFileWriter.NoError, error_message)

        # Open result and check
        created_layer = QgsVectorLayer('{}|layerid=0'.format(dest_file_name), 'test', 'ogr')
        f = next(created_layer.getFeatures(QgsFeatureRequest()))
        g = f.geometry()
        wkt = g.asWkt()
        expWkt = 'MultiPoint ((1 2))'
        self.assertTrue(compareWkt(expWkt, wkt),
                        "saving geometry with multi conversion failed: mismatch Expected:\n%s\nGot:\n%s\n" % (
                        expWkt, wkt))
开发者ID:boundlessgeo,项目名称:QGIS,代码行数:40,代码来源:test_qgsvectorfilewriter.py

示例15: testGetFeatures

    def testGetFeatures(self):
        """ Test that expected results are returned when fetching all features """

        # IMPORTANT - we do not use `for f in provider.getFeatures()` as we are also
        # testing that existing attributes & geometry in f are overwritten correctly
        # (for f in ... uses a new QgsFeature for every iteration)

        it = self.provider.getFeatures()
        f = QgsFeature()
        attributes = {}
        geometries = {}
        while it.nextFeature(f):
            # split off the first 5 attributes only - some provider test datasets will include
            # additional attributes which we ignore
            attrs = f.attributes()[0:5]
            # force the num_char attribute to be text - some providers (eg delimited text) will
            # automatically detect that this attribute contains numbers and set it as a numeric
            # field
            attrs[4] = str(attrs[4])
            attributes[f['pk']] = attrs
            geometries[f['pk']] = f.constGeometry() and f.constGeometry().exportToWkt()

        expected_attributes = {5: [5, -200, NULL, 'NuLl', '5'],
                               3: [3, 300, 'Pear', 'PEaR', '3'],
                               1: [1, 100, 'Orange', 'oranGe', '1'],
                               2: [2, 200, 'Apple', 'Apple', '2'],
                               4: [4, 400, 'Honey', 'Honey', '4']}
        self.assertEqual(attributes, expected_attributes, 'Expected {}, got {}'.format(expected_attributes, attributes))

        expected_geometries = {1: 'Point (-70.332 66.33)',
                               2: 'Point (-68.2 70.8)',
                               3: None,
                               4: 'Point(-65.32 78.3)',
                               5: 'Point(-71.123 78.23)'}
        for pk, geom in expected_geometries.iteritems():
            if geom:
                assert compareWkt(geom, geometries[pk]), "Geometry {} mismatch Expected:\n{}\nGot:\n{}\n".format(pk, geom, geometries[pk].exportToWkt())
            else:
                self.assertFalse(geometries[pk], 'Expected null geometry for {}'.format(pk))
开发者ID:MrBenjaminLeb,项目名称:QGIS,代码行数:39,代码来源:providertestbase.py


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