Skip to content

Commit 54040cb

Browse files
authoredOct 16, 2017
Merge pull request #5349 from pblottiere/bugfix-reshape-tool
[bugfix] Fixes #17118 Reshape tool with z support
2 parents 364847f + d319e65 commit 54040cb

File tree

8 files changed

+67
-6
lines changed

8 files changed

+67
-6
lines changed
 

‎python/core/geometry/qgsgeometry.sip

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,15 @@ class QgsGeometry
396396
*/
397397
int reshapeGeometry( const QList<QgsPoint>& reshapeWithLine );
398398

399+
/**
400+
* Replaces a part of this geometry with another line with Z support
401+
*
402+
* @return 0 in case of success
403+
*
404+
* @note added in 2.18
405+
*/
406+
int reshapeGeometry( const QList<QgsPointV2>& reshapeWithLine );
407+
399408
/** Changes this geometry such that it does not intersect the other geometry
400409
* @param other geometry that should not be intersect
401410
* @return 0 in case of success

‎python/gui/qgsmaptoolcapture.sip

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ class QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
163163
*/
164164
QList<QgsPoint> points();
165165

166+
/**
167+
* List of digitized points with z support
168+
*
169+
* @return List of points
170+
*
171+
* @node added in 2.18
172+
*/
173+
QList<QgsPointV2> pointsV2();
174+
166175
/**
167176
* Set the points on which to work
168177
*

‎src/app/qgsmaptoolreshape.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
9797
QgsGeometry* geom = f.geometry();
9898
if ( geom )
9999
{
100-
reshapeReturn = geom->reshapeGeometry( points() );
100+
reshapeReturn = geom->reshapeGeometry( pointsV2() );
101101
if ( reshapeReturn == 0 )
102102
{
103103
//avoid intersections on polygon layers

‎src/core/geometry/qgsgeometry.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,28 +800,35 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome
800800

801801
/** Replaces a part of this geometry with another line*/
802802
int QgsGeometry::reshapeGeometry( const QList<QgsPoint>& reshapeWithLine )
803+
{
804+
QgsPointSequenceV2 reshapeLine;
805+
convertPointList( reshapeWithLine, reshapeLine );
806+
return reshapeGeometry( reshapeLine );
807+
}
808+
809+
int QgsGeometry::reshapeGeometry( const QList<QgsPointV2>& reshapeLine )
803810
{
804811
if ( !d->geometry )
805812
{
806813
return 0;
807814
}
808815

809-
QgsPointSequenceV2 reshapeLine;
810-
convertPointList( reshapeWithLine, reshapeLine );
811816
QgsLineStringV2 reshapeLineString;
812817
reshapeLineString.setPoints( reshapeLine );
813-
814818
QgsGeos geos( d->geometry );
815819
int errorCode = 0;
816820
QgsAbstractGeometryV2* geom = geos.reshapeGeometry( reshapeLineString, &errorCode );
821+
817822
if ( errorCode == 0 && geom )
818823
{
819824
detach( false );
820-
delete d->geometry;
821-
d->geometry = geom;
822825
removeWkbGeos();
826+
d->geometry = geom;
823827
return 0;
824828
}
829+
830+
delete geom;
831+
825832
return errorCode;
826833
}
827834

‎src/core/geometry/qgsgeometry.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,15 @@ class CORE_EXPORT QgsGeometry
438438
*/
439439
int reshapeGeometry( const QList<QgsPoint>& reshapeWithLine );
440440

441+
/**
442+
* Replaces a part of this geometry with another line with Z support
443+
*
444+
* @return 0 in case of success
445+
*
446+
* @note added in 2.18
447+
*/
448+
int reshapeGeometry( const QList<QgsPointV2>& reshapeLine );
449+
441450
/** Changes this geometry such that it does not intersect the other geometry
442451
* @param other geometry that should not be intersect
443452
* @return 0 in case of success

‎src/gui/qgsmaptoolcapture.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,13 @@ QList<QgsPoint> QgsMapToolCapture::points()
722722
return points;
723723
}
724724

725+
QgsPointSequenceV2 QgsMapToolCapture::pointsV2()
726+
{
727+
QgsPointSequenceV2 pts;
728+
mCaptureCurve.points( pts );
729+
return pts;
730+
}
731+
725732
void QgsMapToolCapture::setPoints( const QList<QgsPoint>& pointList )
726733
{
727734
QgsPointSequenceV2 pts;

‎src/gui/qgsmaptoolcapture.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
194194
*/
195195
QList<QgsPoint> points();
196196

197+
/**
198+
* List of digitized points with z support
199+
*
200+
* @return List of points
201+
*
202+
* @note added in 2.18
203+
*/
204+
QgsPointSequenceV2 pointsV2();
205+
197206
/**
198207
* Set the points on which to work
199208
*

‎tests/src/python/test_qgsgeometry.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,16 @@ def testReshape(self):
16851685
wkt = g.exportToWkt()
16861686
assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
16871687

1688+
# Test reshape with z support
1689+
wkt = 'LineStringZ (-1 0 -3, 0 0 20, 5 0 9999)'
1690+
g = QgsGeometry.fromWkt(wkt)
1691+
1692+
self.assertEqual(g.reshapeGeometry([QgsPointV2(QgsWKBTypes.PointZ, -1, 0, -3), QgsPointV2(QgsWKBTypes.PointZ, -6, 5, 55)]), 0)
1693+
wkt = g.exportToWkt()
1694+
1695+
expWkt = 'LineStringZ (-6 5 55, -1 0 -3, 0 0 20, 5 0 9999)'
1696+
assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
1697+
16881698
def testConvertToMultiType(self):
16891699
""" Test converting geometries to multi type """
16901700
point = QgsGeometry.fromWkt('Point (1 2)')
@@ -3515,5 +3525,6 @@ def testAngleAtVertex(self):
35153525
self.assertAlmostEqual(polygon.angleAtVertex(3), math.radians(225.0), places=3)
35163526
self.assertAlmostEqual(polygon.angleAtVertex(4), math.radians(135.0), places=3)
35173527

3528+
35183529
if __name__ == '__main__':
35193530
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.