Skip to content

Commit ecaee1a

Browse files
committedJul 28, 2017
QgsGeometry::vertexAt now returns QgsPoint, not QgsPointXY
Since it's easy to convert from a QgsPoint to a QgsPointXY, but impossible to recover the Z/M values lost by only returning a QgsPointXY.
1 parent 620d4e0 commit ecaee1a

File tree

8 files changed

+31
-31
lines changed

8 files changed

+31
-31
lines changed
 

‎doc/api_break.dox

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,7 @@ empty geometry collection)
12421242
- avoidIntersections() got an extra argument: list of layers to include in the operation (previously read from active QgsProject)
12431243
- isGeosEmpty() was removed. Use isEmpty() instead.
12441244
- reshapeGeometry() expects QgsLineString as a parameter instead of a list of 2D points (so that it can support 3D geometries)
1245+
- vertexAt() now returns a QgsPoint (previously QgsPointV2) instead of a QgsPointXY (previously QgsPoint)
12451246

12461247

12471248
QgsGeometryAnalyzer {#qgis_api_break_3_0_QgsGeometryAnalyzer}

‎python/core/geometry/qgsgeometry.sip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,12 @@ Returns true if WKB of the geometry is of WKBMulti* type
326326
:rtype: bool
327327
%End
328328

329-
QgsPointXY vertexAt( int atVertex ) const;
329+
QgsPoint vertexAt( int atVertex ) const;
330330
%Docstring
331331
Returns coordinates of a vertex.
332332
\param atVertex index of the vertex
333-
:return: Coordinates of the vertex or QgsPointXY(0,0) on error
334-
:rtype: QgsPointXY
333+
:return: Coordinates of the vertex or QgsPoint(0,0) on error
334+
:rtype: QgsPoint
335335
%End
336336

337337
double sqrDistToVertexAt( QgsPointXY &point /In/, int atVertex ) const;

‎python/plugins/processing/algs/qgis/ExtractSpecificNodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def processAlgorithm(self, parameters, context, feedback):
120120
output_feature.setAttributes(attrs)
121121

122122
point = input_geometry.vertexAt(node_index)
123-
output_feature.setGeometry(QgsGeometry.fromPoint(point))
123+
output_feature.setGeometry(QgsGeometry(point))
124124

125125
writer.addFeature(output_feature, QgsFeatureSink.FastInsert)
126126

‎python/plugins/processing/tools/vector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
QgsCredentials,
5353
QgsFeatureRequest,
5454
QgsSettings,
55-
QgsProcessingContext,
55+
QgsPointXY,
5656
QgsProcessingUtils)
5757

5858
from processing.tools import dataobjects
@@ -251,7 +251,7 @@ def snapToPrecision(geom, precision):
251251
snapped.moveVertex(x, y, i)
252252
i = i + 1
253253
p = snapped.vertexAt(i)
254-
return snapped
254+
return QgsPointXY(snapped.x(), snapped.y())
255255

256256

257257
def ogrConnectionString(uri):

‎src/app/nodetool/qgsnodetool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ void QgsNodeTool::startDraggingEdge( const QgsPointLocator::Match &m, const QgsP
13131313
Q_FOREACH ( const Vertex &v, movingVertices )
13141314
{
13151315
mDraggingExtraVertices << v;
1316-
mDraggingExtraVerticesOffset << ( geom.vertexAt( v.vertexId ) - layerPoint );
1316+
mDraggingExtraVerticesOffset << ( geom.vertexAt( v.vertexId ) - QgsPoint( layerPoint ) );
13171317
}
13181318

13191319
mOverrideCadPoints.clear();
@@ -1639,10 +1639,10 @@ void QgsNodeTool::deleteVertex()
16391639
int vertexId = vertex.vertexId;
16401640

16411641
// if next vertex is not available, use the previous one
1642-
if ( geom.vertexAt( vertexId ) == QgsPointXY() )
1642+
if ( geom.vertexAt( vertexId ) == QgsPoint() )
16431643
vertexId -= 1;
16441644

1645-
if ( geom.vertexAt( vertexId ) != QgsPointXY() )
1645+
if ( geom.vertexAt( vertexId ) != QgsPoint() )
16461646
{
16471647
QList<Vertex> nodes_new;
16481648
nodes_new << Vertex( vertex.layer, vertex.fid, vertexId );

‎src/core/geometry/qgsgeometry.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,21 +546,20 @@ bool QgsGeometry::insertVertex( const QgsPoint &point, int beforeVertex )
546546
return d->geometry->insertVertex( id, point );
547547
}
548548

549-
QgsPointXY QgsGeometry::vertexAt( int atVertex ) const
549+
QgsPoint QgsGeometry::vertexAt( int atVertex ) const
550550
{
551551
if ( !d->geometry )
552552
{
553-
return QgsPointXY( 0, 0 );
553+
return QgsPoint();
554554
}
555555

556556
QgsVertexId vId;
557557
( void )vertexIdFromVertexNr( atVertex, vId );
558558
if ( vId.vertex < 0 )
559559
{
560-
return QgsPointXY( 0, 0 );
560+
return QgsPoint();
561561
}
562-
QgsPoint pt = d->geometry->vertexAt( vId );
563-
return QgsPointXY( pt.x(), pt.y() );
562+
return d->geometry->vertexAt( vId );
564563
}
565564

566565
double QgsGeometry::sqrDistToVertexAt( QgsPointXY &point, int atVertex ) const

‎src/core/geometry/qgsgeometry.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ class CORE_EXPORT QgsGeometry
343343
/**
344344
* Returns coordinates of a vertex.
345345
* \param atVertex index of the vertex
346-
* \returns Coordinates of the vertex or QgsPointXY(0,0) on error
346+
* \returns Coordinates of the vertex or QgsPoint(0,0) on error
347347
*/
348-
QgsPointXY vertexAt( int atVertex ) const;
348+
QgsPoint vertexAt( int atVertex ) const;
349349

350350
/**
351351
* Returns the squared Cartesian distance between the given point

‎tests/src/python/test_qgsgeometry.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def testVertexAt(self):
761761
polyline = QgsGeometry.fromPolyline(points)
762762

763763
for i in range(0, len(points)):
764-
self.assertEqual(points[i], polyline.vertexAt(i), "Mismatch at %d" % i)
764+
self.assertEqual(QgsPoint(points[i]), polyline.vertexAt(i), "Mismatch at %d" % i)
765765

766766
# 2-3 6-+-7
767767
# | | | |
@@ -773,15 +773,15 @@ def testVertexAt(self):
773773
polyline = QgsGeometry.fromMultiPolyline(points)
774774

775775
p = polyline.vertexAt(-100)
776-
self.assertEqual(p, QgsPointXY(0, 0), "Expected 0,0, Got %s" % p.toString())
776+
self.assertEqual(p, QgsPoint(0, 0), "Expected 0,0, Got {}.{}".format(p.x(), p.y()))
777777

778778
p = polyline.vertexAt(100)
779-
self.assertEqual(p, QgsPointXY(0, 0), "Expected 0,0, Got %s" % p.toString())
779+
self.assertEqual(p, QgsPoint(0, 0), "Expected 0,0, Got {}.{}".format(p.x(), p.y()))
780780

781781
i = 0
782782
for j in range(0, len(points)):
783783
for k in range(0, len(points[j])):
784-
self.assertEqual(points[j][k], polyline.vertexAt(i), "Mismatch at %d / %d,%d" % (i, j, k))
784+
self.assertEqual(QgsPoint(points[j][k]), polyline.vertexAt(i), "Mismatch at %d / %d,%d" % (i, j, k))
785785
i += 1
786786

787787
# 5---4
@@ -795,15 +795,15 @@ def testVertexAt(self):
795795
polygon = QgsGeometry.fromPolygon(points)
796796

797797
p = polygon.vertexAt(-100)
798-
self.assertEqual(p, QgsPointXY(0, 0), "Expected 0,0, Got %s" % p.toString())
798+
self.assertEqual(p, QgsPoint(0, 0), "Expected 0,0, Got {}.{}".format(p.x(), p.y()))
799799

800800
p = polygon.vertexAt(100)
801-
self.assertEqual(p, QgsPointXY(0, 0), "Expected 0,0, Got %s" % p.toString())
801+
self.assertEqual(p, QgsPoint(0, 0), "Expected 0,0, Got {}.{}".format(p.x(), p.y()))
802802

803803
i = 0
804804
for j in range(0, len(points)):
805805
for k in range(0, len(points[j])):
806-
self.assertEqual(points[j][k], polygon.vertexAt(i), "Mismatch at %d / %d,%d" % (i, j, k))
806+
self.assertEqual(QgsPoint(points[j][k]), polygon.vertexAt(i), "Mismatch at %d / %d,%d" % (i, j, k))
807807
i += 1
808808

809809
# 3-+-+-2
@@ -820,15 +820,15 @@ def testVertexAt(self):
820820
polygon = QgsGeometry.fromPolygon(points)
821821

822822
p = polygon.vertexAt(-100)
823-
self.assertEqual(p, QgsPointXY(0, 0), "Expected 0,0, Got %s" % p.toString())
823+
self.assertEqual(p, QgsPoint(0, 0), "Expected 0,0, Got {}.{}".format(p.x(), p.y()))
824824

825825
p = polygon.vertexAt(100)
826-
self.assertEqual(p, QgsPointXY(0, 0), "Expected 0,0, Got %s" % p.toString())
826+
self.assertEqual(p, QgsPoint(0, 0), "Expected 0,0, Got {}.{}".format(p.x(), p.y()))
827827

828828
i = 0
829829
for j in range(0, len(points)):
830830
for k in range(0, len(points[j])):
831-
self.assertEqual(points[j][k], polygon.vertexAt(i), "Mismatch at %d / %d,%d" % (i, j, k))
831+
self.assertEqual(QgsPoint(points[j][k]), polygon.vertexAt(i), "Mismatch at %d / %d,%d" % (i, j, k))
832832
i += 1
833833

834834
# 5-+-4 0-+-9
@@ -844,17 +844,17 @@ def testVertexAt(self):
844844
polygon = QgsGeometry.fromMultiPolygon(points)
845845

846846
p = polygon.vertexAt(-100)
847-
self.assertEqual(p, QgsPointXY(0, 0), "Expected 0,0, Got %s" % p.toString())
847+
self.assertEqual(p, QgsPoint(0, 0), "Expected 0,0, Got {}.{}".format(p.x(), p.y()))
848848

849849
p = polygon.vertexAt(100)
850-
self.assertEqual(p, QgsPointXY(0, 0), "Expected 0,0, Got %s" % p.toString())
850+
self.assertEqual(p, QgsPoint(0, 0), "Expected 0,0, Got {}.{}".format(p.x(), p.y()))
851851

852852
i = 0
853853
for j in range(0, len(points)):
854854
for k in range(0, len(points[j])):
855855
for l in range(0, len(points[j][k])):
856856
p = polygon.vertexAt(i)
857-
self.assertEqual(points[j][k][l], p, "Got %s, Expected %s at %d / %d,%d,%d" % (p.toString(), points[j][k][l].toString(), i, j, k, l))
857+
self.assertEqual(QgsPoint(points[j][k][l]), p, "Got {},{} Expected {} at {} / {},{},{}".format(p.x(), p.y(), points[j][k][l].toString(), i, j, k, l))
858858
i += 1
859859

860860
def testMultipoint(self):
@@ -870,7 +870,7 @@ def testMultipoint(self):
870870
i += 1
871871

872872
multipoint = QgsGeometry.fromWkt("MultiPoint ((5 5))")
873-
self.assertEqual(multipoint.vertexAt(0), QgsPointXY(5, 5), "MULTIPOINT fromWkt failed")
873+
self.assertEqual(multipoint.vertexAt(0), QgsPoint(5, 5), "MULTIPOINT fromWkt failed")
874874

875875
assert multipoint.insertVertex(4, 4, 0), "MULTIPOINT insert 4,4 at 0 failed"
876876
expwkt = "MultiPoint ((4 4),(5 5))"
@@ -906,7 +906,7 @@ def testMultipoint(self):
906906
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
907907

908908
multipoint = QgsGeometry.fromWkt("MultiPoint ((5 5))")
909-
self.assertEqual(multipoint.vertexAt(0), QgsPointXY(5, 5), "MultiPoint fromWkt failed")
909+
self.assertEqual(multipoint.vertexAt(0), QgsPoint(5, 5), "MultiPoint fromWkt failed")
910910

911911
def testMoveVertex(self):
912912
multipoint = QgsGeometry.fromWkt("MultiPoint ((5 0),(0 0),(0 4),(5 4),(5 1),(1 1),(1 3),(4 3),(4 2),(2 2))")

0 commit comments

Comments
 (0)
Please sign in to comment.