Ejemplo n.º 1
0
    def test_issue_32443(self):
        p = QgsPoint()
        assert p.wkbType() == QgsWkbTypes.Point and p.x() != p.x() and p.y() != p.y()

        # ctor from QgsPointXY should be available
        p = QgsPoint(QgsPointXY(1, 2))
        assert p.wkbType() == QgsWkbTypes.Point and p.x() == 1 and p.y() == 2

        # ctor from QPointF should be available
        p = QgsPoint(QPointF(1, 2))
        assert p.wkbType() == QgsWkbTypes.Point and p.x() == 1 and p.y() == 2

        p = QgsPoint(1, 2)
        assert p.wkbType() == QgsWkbTypes.Point and p.x() == 1 and p.y() == 2

        p = QgsPoint(1, 2, 3)
        assert p.wkbType() == QgsWkbTypes.PointZ and p.x() == 1 and p.y() == 2 and p.z() == 3

        p = QgsPoint(1, 2, z=3)
        assert p.wkbType() == QgsWkbTypes.PointZ and p.x() == 1 and p.y() == 2 and p.z() == 3

        p = QgsPoint(1, 2, m=3)
        assert p.wkbType() == QgsWkbTypes.PointM and p.x() == 1 and p.y() == 2 and p.m() == 3

        p = QgsPoint(1, 2, wkbType=QgsWkbTypes.PointM)
        assert p.wkbType() == QgsWkbTypes.PointM and p.x() == 1 and p.y() == 2 and p.m() != p.m()

        p = QgsPoint(1, 2, 3, 4)
        assert p.wkbType() == QgsWkbTypes.PointZM and p.x() == 1 and p.y() == 2 and p.z() == 3 and p.m() == 4

        p = QgsPoint(1, 2, m=4, z=3)
        assert p.wkbType() == QgsWkbTypes.PointZM and p.x() == 1 and p.y() == 2 and p.z() == 3 and p.m() == 4
Ejemplo n.º 2
0
from qgis.core import QgsGeometry, QgsPoint

g = QgsGeometry.fromWkt('POINT ZM (1 2 5 60)')  # your geometry

# if you don't need z and m, you could do this:

p = g.asPoint()  # you'll get a QgsPointXY object
x = p.x()
y = p.y()

# if you need z and m, and you don't want to use regex, you could do this:

p = QgsPoint()
p.fromWkt(g.asWkt())

x = p.x()
y = p.y()
z = p.z()
m = p.m()

# example to parse multilinestring if you don't need z and m

g2 = QgsGeometry.fromWkt(
    'MULTILINESTRING ((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10))')
for points in g2.asMultiPolyline(
):  # asMultiPolyline() returns a list of a list of QgsPointXY
    point_list = [(p.x(), p.y()) for p in points
                  ]  # converts QgsPointXY objects to a simple tuple
    print(point_list)