Skip to content

Commit

Permalink
Merge pull request #5349 from pblottiere/bugfix-reshape-tool
Browse files Browse the repository at this point in the history
[bugfix] Fixes #17118 Reshape tool with z support
  • Loading branch information
pblottiere committed Oct 16, 2017
2 parents 364847f + d319e65 commit 54040cb
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 6 deletions.
9 changes: 9 additions & 0 deletions python/core/geometry/qgsgeometry.sip
Expand Up @@ -396,6 +396,15 @@ class QgsGeometry
*/
int reshapeGeometry( const QList<QgsPoint>& reshapeWithLine );

/**
* Replaces a part of this geometry with another line with Z support
*
* @return 0 in case of success
*
* @note added in 2.18
*/
int reshapeGeometry( const QList<QgsPointV2>& reshapeWithLine );

/** Changes this geometry such that it does not intersect the other geometry
* @param other geometry that should not be intersect
* @return 0 in case of success
Expand Down
9 changes: 9 additions & 0 deletions python/gui/qgsmaptoolcapture.sip
Expand Up @@ -163,6 +163,15 @@ class QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
*/
QList<QgsPoint> points();

/**
* List of digitized points with z support
*
* @return List of points
*
* @node added in 2.18
*/
QList<QgsPointV2> pointsV2();

/**
* Set the points on which to work
*
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolreshape.cpp
Expand Up @@ -97,7 +97,7 @@ void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
QgsGeometry* geom = f.geometry();
if ( geom )
{
reshapeReturn = geom->reshapeGeometry( points() );
reshapeReturn = geom->reshapeGeometry( pointsV2() );
if ( reshapeReturn == 0 )
{
//avoid intersections on polygon layers
Expand Down
17 changes: 12 additions & 5 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -800,28 +800,35 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome

/** Replaces a part of this geometry with another line*/
int QgsGeometry::reshapeGeometry( const QList<QgsPoint>& reshapeWithLine )
{
QgsPointSequenceV2 reshapeLine;
convertPointList( reshapeWithLine, reshapeLine );
return reshapeGeometry( reshapeLine );
}

int QgsGeometry::reshapeGeometry( const QList<QgsPointV2>& reshapeLine )
{
if ( !d->geometry )
{
return 0;
}

QgsPointSequenceV2 reshapeLine;
convertPointList( reshapeWithLine, reshapeLine );
QgsLineStringV2 reshapeLineString;
reshapeLineString.setPoints( reshapeLine );

QgsGeos geos( d->geometry );
int errorCode = 0;
QgsAbstractGeometryV2* geom = geos.reshapeGeometry( reshapeLineString, &errorCode );

if ( errorCode == 0 && geom )
{
detach( false );
delete d->geometry;
d->geometry = geom;
removeWkbGeos();
d->geometry = geom;
return 0;
}

delete geom;

return errorCode;
}

Expand Down
9 changes: 9 additions & 0 deletions src/core/geometry/qgsgeometry.h
Expand Up @@ -438,6 +438,15 @@ class CORE_EXPORT QgsGeometry
*/
int reshapeGeometry( const QList<QgsPoint>& reshapeWithLine );

/**
* Replaces a part of this geometry with another line with Z support
*
* @return 0 in case of success
*
* @note added in 2.18
*/
int reshapeGeometry( const QList<QgsPointV2>& reshapeLine );

/** Changes this geometry such that it does not intersect the other geometry
* @param other geometry that should not be intersect
* @return 0 in case of success
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -722,6 +722,13 @@ QList<QgsPoint> QgsMapToolCapture::points()
return points;
}

QgsPointSequenceV2 QgsMapToolCapture::pointsV2()
{
QgsPointSequenceV2 pts;
mCaptureCurve.points( pts );
return pts;
}

void QgsMapToolCapture::setPoints( const QList<QgsPoint>& pointList )
{
QgsPointSequenceV2 pts;
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgsmaptoolcapture.h
Expand Up @@ -194,6 +194,15 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
*/
QList<QgsPoint> points();

/**
* List of digitized points with z support
*
* @return List of points
*
* @note added in 2.18
*/
QgsPointSequenceV2 pointsV2();

/**
* Set the points on which to work
*
Expand Down
11 changes: 11 additions & 0 deletions tests/src/python/test_qgsgeometry.py
Expand Up @@ -1685,6 +1685,16 @@ def testReshape(self):
wkt = g.exportToWkt()
assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)

# Test reshape with z support
wkt = 'LineStringZ (-1 0 -3, 0 0 20, 5 0 9999)'
g = QgsGeometry.fromWkt(wkt)

self.assertEqual(g.reshapeGeometry([QgsPointV2(QgsWKBTypes.PointZ, -1, 0, -3), QgsPointV2(QgsWKBTypes.PointZ, -6, 5, 55)]), 0)
wkt = g.exportToWkt()

expWkt = 'LineStringZ (-6 5 55, -1 0 -3, 0 0 20, 5 0 9999)'
assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)

def testConvertToMultiType(self):
""" Test converting geometries to multi type """
point = QgsGeometry.fromWkt('Point (1 2)')
Expand Down Expand Up @@ -3515,5 +3525,6 @@ def testAngleAtVertex(self):
self.assertAlmostEqual(polygon.angleAtVertex(3), math.radians(225.0), places=3)
self.assertAlmostEqual(polygon.angleAtVertex(4), math.radians(135.0), places=3)


if __name__ == '__main__':
unittest.main()

0 comments on commit 54040cb

Please sign in to comment.