Skip to content

Commit 46a6f25

Browse files
authored
Merge pull request #5418 from nyalldawson/from_polyline
Rename QgsGeometry::fromPolyline as QgsGeometry::fromPolylineXY
2 parents 2f44de0 + c4f3832 commit 46a6f25

File tree

59 files changed

+443
-338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+443
-338
lines changed

doc/api_break.dox

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,9 @@ empty geometry collection)
12831283
- isGeosEmpty() was removed. Use isEmpty() instead.
12841284
- reshapeGeometry() expects QgsLineString as a parameter instead of a list of 2D points (so that it can support 3D geometries)
12851285
- vertexAt() now returns a QgsPoint (previously QgsPointV2) instead of a QgsPointXY (previously QgsPoint)
1286+
- fromPolyline() now requires a list of QgsPoint objects, instead of QgsPointXY 2d points. A new method fromPolylineXY was
1287+
added which uses the old list of 2d QgsPointXY objects. Using the newer method with QgsPoint is greatly preferred, as it
1288+
maintains Z or M dimensions from the input points and is more efficient.
12861289

12871290

12881291
QgsGeometryAnalyzer {#qgis_api_break_3_0_QgsGeometryAnalyzer}
@@ -1892,6 +1895,13 @@ plugins calling this method will need to be updated.
18921895
plugins calling this method will need to be updated.
18931896

18941897

1898+
QgsPolyline {#qgis_api_break_3_0_QgsPolyline}
1899+
-----------
1900+
1901+
- QgsPolyline now consists of a list of QgsPoint, instead of 2d QgsPointXY objects. The 2d polyline variant has
1902+
been renamed to QgsPolylineXY
1903+
1904+
18951905
QgsProject {#qgis_api_break_3_0_QgsProject}
18961906
----------
18971907

python/core/geometry/qgsgeometry.sip

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616

1717

18-
typedef QVector<QgsPointXY> QgsPolyline;
18+
typedef QVector<QgsPointXY> QgsPolylineXY;
19+
20+
typedef QVector<QgsPoint> QgsPolyline;
1921

2022
typedef QVector<QVector<QgsPointXY>> QgsPolygon;
2123

@@ -122,11 +124,35 @@ Creates a new geometry from a QgsPointXY object
122124
Creates a new geometry from a QgsMultiPoint object
123125
:rtype: QgsGeometry
124126
%End
127+
128+
static QgsGeometry fromPolylineXY( const QgsPolylineXY &polyline );
129+
%Docstring
130+
Creates a new LineString geometry from a list of QgsPointXY points.
131+
132+
Using fromPolyline() is preferred, as fromPolyline() is more efficient
133+
and will respect any Z or M dimensions present in the input points.
134+
135+
.. note::
136+
137+
In QGIS 2.x this method was available as fromPolyline().
138+
139+
.. versionadded:: 3.0
140+
.. seealso:: fromPolyline()
141+
:rtype: QgsGeometry
142+
%End
143+
125144
static QgsGeometry fromPolyline( const QgsPolyline &polyline );
126145
%Docstring
127-
Creates a new geometry from a QgsPolyline object
146+
Creates a new LineString geometry from a list of QgsPoint points.
147+
148+
This method will respect any Z or M dimensions present in the input points.
149+
E.g. if input points are PointZ type, the resultant linestring will be
150+
a LineStringZ type.
151+
152+
.. versionadded:: 3.0
128153
:rtype: QgsGeometry
129154
%End
155+
130156
static QgsGeometry fromMultiPolyline( const QgsMultiPolyline &multiline );
131157
%Docstring
132158
Creates a new geometry from a QgsMultiPolyline object
@@ -1065,11 +1091,11 @@ Returns an extruded version of this geometry.
10651091
:rtype: QgsPointXY
10661092
%End
10671093

1068-
QgsPolyline asPolyline() const;
1094+
QgsPolylineXY asPolyline() const;
10691095
%Docstring
10701096
Returns contents of the geometry as a polyline
10711097
if wkbType is WKBLineString, otherwise an empty list
1072-
:rtype: QgsPolyline
1098+
:rtype: QgsPolylineXY
10731099
%End
10741100

10751101
QgsPolygon asPolygon() const;
@@ -1349,13 +1375,13 @@ Returns an extruded version of this geometry.
13491375
:rtype: QgsGeometry
13501376
%End
13511377

1352-
static QgsPolyline createPolylineFromQPolygonF( const QPolygonF &polygon ) /Factory/;
1378+
static QgsPolylineXY createPolylineFromQPolygonF( const QPolygonF &polygon ) /Factory/;
13531379
%Docstring
1354-
Creates a QgsPolyline from a QPolygonF.
1380+
Creates a QgsPolylineXY from a QPolygonF.
13551381
\param polygon source polygon
1356-
:return: QgsPolyline
1382+
:return: QgsPolylineXY
13571383
.. seealso:: createPolygonFromQPolygonF
1358-
:rtype: QgsPolyline
1384+
:rtype: QgsPolylineXY
13591385
%End
13601386

13611387
static QgsPolygon createPolygonFromQPolygonF( const QPolygonF &polygon ) /Factory/;
@@ -1371,7 +1397,7 @@ Returns an extruded version of this geometry.
13711397
static bool compare( PyObject *obj1, PyObject *obj2, double epsilon = 4 * DBL_EPSILON );
13721398
%Docstring
13731399
Compares two geometry objects for equality within a specified tolerance.
1374-
The objects can be of type QgsPolyline, QgsPolygon or QgsMultiPolygon.
1400+
The objects can be of type QgsPolylineXY, QgsPolygon or QgsMultiPolygon.
13751401
The 2 types should match.
13761402
\param p1 first geometry object
13771403
\param p2 second geometry object
@@ -1408,10 +1434,10 @@ Returns an extruded version of this geometry.
14081434
sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
14091435
sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
14101436
{
1411-
QgsPolyline *p0;
1412-
QgsPolyline *p1;
1413-
p0 = reinterpret_cast<QgsPolyline *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1414-
p1 = reinterpret_cast<QgsPolyline *>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1437+
QgsPolylineXY *p0;
1438+
QgsPolylineXY *p1;
1439+
p0 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1440+
p1 = reinterpret_cast<QgsPolylineXY *>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
14151441
if ( sipIsErr )
14161442
{
14171443
sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );

python/plugins/processing/algs/qgis/Gridify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def processFeature(self, feature, feedback):
9191
feedback.reportError(self.tr('Failed to gridify feature with FID {0}').format(feature.id()))
9292
newGeom = None
9393
else:
94-
newGeom = QgsGeometry.fromPolyline(points)
94+
newGeom = QgsGeometry.fromPolylineXY(points)
9595
elif geomType == QgsWkbTypes.MultiLineString:
9696
polyline = []
9797
for line in geom.asMultiPolyline():

python/plugins/processing/algs/qgis/HubDistanceLines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def processAlgorithm(self, parameters, context, feedback):
146146
feat = QgsFeature()
147147
feat.setAttributes(attributes)
148148

149-
feat.setGeometry(QgsGeometry.fromPolyline([src, closest]))
149+
feat.setGeometry(QgsGeometry.fromPolylineXY([src, closest]))
150150

151151
sink.addFeature(feat, QgsFeatureSink.FastInsert)
152152
feedback.setProgress(int(current * total))

python/plugins/processing/algs/qgis/ShortestPathLayerToPoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def processAlgorithm(self, parameters, context, feedback):
260260
route.append(snappedPoints[i])
261261
route.reverse()
262262

263-
geom = QgsGeometry.fromPolyline(route)
263+
geom = QgsGeometry.fromPolylineXY(route)
264264
feat.setGeometry(geom)
265265
feat['start'] = points[i].toString()
266266
feat['end'] = endPoint.toString()

python/plugins/processing/algs/qgis/ShortestPathPointToLayer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def processAlgorithm(self, parameters, context, feedback):
260260
route.append(snappedPoints[0])
261261
route.reverse()
262262

263-
geom = QgsGeometry.fromPolyline(route)
263+
geom = QgsGeometry.fromPolylineXY(route)
264264
feat.setGeometry(geom)
265265
feat['start'] = startPoint.toString()
266266
feat['end'] = points[i].toString()

python/plugins/processing/algs/qgis/ShortestPathPointToPoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def processAlgorithm(self, parameters, context, feedback):
234234
route.reverse()
235235

236236
feedback.pushInfo(self.tr('Writing results...'))
237-
geom = QgsGeometry.fromPolyline(route)
237+
geom = QgsGeometry.fromPolylineXY(route)
238238
feat = QgsFeature()
239239
feat.setFields(fields)
240240
feat['start'] = startPoint.toString()

src/analysis/interpolation/DualEdgeTriangulation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,10 +3060,10 @@ bool DualEdgeTriangulation::saveTriangulation( QgsFeatureSink *sink, QgsFeedback
30603060
//geometry
30613061
QgsPoint *p1 = mPointVector[currentEdge->getPoint()];
30623062
QgsPoint *p2 = mPointVector[mHalfEdge[currentEdge->getDual()]->getPoint()];
3063-
QgsPolyline lineGeom;
3063+
QgsPolylineXY lineGeom;
30643064
lineGeom.push_back( QgsPointXY( p1->x(), p1->y() ) );
30653065
lineGeom.push_back( QgsPointXY( p2->x(), p2->y() ) );
3066-
edgeLineFeature.setGeometry( QgsGeometry::fromPolyline( lineGeom ) );
3066+
edgeLineFeature.setGeometry( QgsGeometry::fromPolylineXY( lineGeom ) );
30673067
edgeLineFeature.initAttributes( 1 );
30683068

30693069
//attributes

src/analysis/network/qgsvectorlayerdirector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
175175
{
176176
QgsPointXY pt1, pt2;
177177
bool isFirstPoint = true;
178-
QgsPolyline::iterator pointIt;
178+
QgsPolylineXY::iterator pointIt;
179179
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
180180
{
181181
pt2 = ct.transform( *pointIt );
@@ -319,7 +319,7 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
319319
QgsPointXY pt1, pt2;
320320

321321
bool isFirstPoint = true;
322-
QgsPolyline::iterator pointIt;
322+
QgsPolylineXY::iterator pointIt;
323323
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
324324
{
325325
pt2 = ct.transform( *pointIt );

src/app/nodetool/qgsnodetool.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,9 @@ void QgsNodeTool::mouseMoveNotDragging( QgsMapMouseEvent *e )
800800
else
801801
{
802802
// straight edge
803-
QgsPolyline points;
803+
QgsPolylineXY points;
804804
points << p0 << p1;
805-
mEdgeBand->setToGeometry( QgsGeometry::fromPolyline( points ), nullptr );
805+
mEdgeBand->setToGeometry( QgsGeometry::fromPolylineXY( points ), nullptr );
806806
}
807807

808808
QgsPointXY edgeCenter;
@@ -1757,9 +1757,9 @@ bool QgsNodeTool::matchEdgeCenterTest( const QgsPointLocator::Match &m, const Qg
17571757
{
17581758
// clip line segment to the extent so the mid-point marker is always visible
17591759
QgsGeometry extentGeom = QgsGeometry::fromRect( visible_extent );
1760-
QgsGeometry lineGeom = QgsGeometry::fromPolyline( QgsPolyline() << p0 << p1 );
1760+
QgsGeometry lineGeom = QgsGeometry::fromPolylineXY( QgsPolylineXY() << p0 << p1 );
17611761
lineGeom = extentGeom.intersection( lineGeom );
1762-
QgsPolyline polyline = lineGeom.asPolyline();
1762+
QgsPolylineXY polyline = lineGeom.asPolyline();
17631763
Q_ASSERT( polyline.count() == 2 );
17641764
p0 = polyline[0];
17651765
p1 = polyline[1];

0 commit comments

Comments
 (0)