Skip to content

Commit c67e398

Browse files
committedOct 27, 2017
Improvements to QgsAbstractGeometry::snappedToGrid
- Fix loss of coordinates when not rounding a particular dimension - Don't segmentize curved geometries - Add extra unit tests - Make createEmptyWithSameType() protected and skip from Python bindings. This method relies on low-level manipulation of the returned geometry which we do not want to expose as public/fixed API
1 parent 3f5b11b commit c67e398

Some content is hidden

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

48 files changed

+470
-301
lines changed
 

‎python/core/geometry/qgsabstractgeometry.sip

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,6 @@ class QgsAbstractGeometry
7171
virtual ~QgsAbstractGeometry();
7272
QgsAbstractGeometry( const QgsAbstractGeometry &geom );
7373

74-
virtual QgsAbstractGeometry *createEmptyWithSameType() const = 0 /Factory/;
75-
%Docstring
76-
Makes a new geometry with the same class and same WKB and transfers ownership.
77-
To create it, the geometry is default constructedand then the WKB is changed.
78-
:return: the new empty geometry. Callee takes ownership.
79-
.. seealso:: clone
80-
.. versionadded:: 3.0
81-
:rtype: QgsAbstractGeometry
82-
%End
83-
8474
virtual QgsAbstractGeometry *clone() const = 0 /Factory/;
8575
%Docstring
8676
Clones the geometry by performing a deep copy
@@ -412,14 +402,14 @@ Returns the centroid of the geometry
412402
:rtype: QgsAbstractGeometry
413403
%End
414404

415-
virtual QgsAbstractGeometry *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, double tolerance = M_PI / 180., SegmentationToleranceType toleranceType = MaximumAngle ) const = 0 /Factory/;
405+
virtual QgsAbstractGeometry *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const = 0 /Factory/;
416406
%Docstring
417407
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
418-
It transfers ownership to the callee.
419-
If it couldn't make the gridified geometry it returns None.
408+
Ownership is transferred to the caller.
409+
410+
If the gridified geometry could not be calculated a None will be returned.
420411
It may generate an invalid geometry (in some corner cases).
421412
It can also be thought as rounding the edges and it may be useful for removing errors.
422-
If the geometry is curved, it will be segmentized before gridifying it.
423413
Example:
424414
\code
425415
geometry->snappedToGrid(1, 1);
@@ -430,10 +420,6 @@ Returns the centroid of the geometry
430420
\param vSpacing Vertical spacing of the grid (y axis). 0 to disable.
431421
\param dSpacing Depth spacing of the grid (z axis). 0 (default) to disable.
432422
\param mSpacing Custom dimension spacing of the grid (m axis). 0 (default) to disable.
433-
\param tolerance In case of segmentation, the tolerance to use (passed to segmentize as is).
434-
\param toleranceType In case of segmentation, the toleranceType to use (passed to segmentize as is).
435-
:return: the segmentized geometry or None if it wasn't possible to make. Caller takes ownership.
436-
.. seealso:: segmentize
437423
.. versionadded:: 3.0
438424
:rtype: QgsAbstractGeometry
439425
%End
@@ -528,6 +514,7 @@ Returns the centroid of the geometry
528514

529515
protected:
530516

517+
531518
virtual bool hasChildGeometries() const;
532519
%Docstring
533520
Returns whether the geometry has any child geometries (false for point / curve, true otherwise)

‎python/core/geometry/qgscircularstring.sip

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,24 @@ class QgsCircularString: QgsCurve
2525
QgsCircularString();
2626

2727
virtual bool operator==( const QgsCurve &other ) const;
28+
2829
virtual bool operator!=( const QgsCurve &other ) const;
2930

31+
3032
virtual QString geometryType() const;
33+
3134
virtual int dimension() const;
32-
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;
35+
3336
virtual QgsCircularString *clone() const /Factory/;
37+
3438
virtual void clear();
3539

40+
3641
virtual bool fromWkb( QgsConstWkbPtr &wkb );
42+
3743
virtual bool fromWkt( const QString &wkt );
3844

45+
3946
virtual QByteArray asWkb() const;
4047

4148
virtual QString asWkt( int precision = 17 ) const;
@@ -67,10 +74,14 @@ class QgsCircularString: QgsCurve
6774
%End
6875

6976
virtual double length() const;
77+
7078
virtual QgsPoint startPoint() const;
79+
7180
virtual QgsPoint endPoint() const;
7281

82+
7383
virtual QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const /Factory/;
84+
7485
%Docstring
7586
Returns a new line string geometry corresponding to a segmentized approximation
7687
of the curve.
@@ -82,6 +93,9 @@ class QgsCircularString: QgsCurve
8293
:rtype: QgsLineString
8394
%End
8495

96+
virtual QgsCircularString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const /Factory/;
97+
98+
8599
virtual void draw( QPainter &p ) const;
86100

87101
virtual void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform,
@@ -90,17 +104,15 @@ class QgsCircularString: QgsCurve
90104

91105
virtual void addToPainterPath( QPainterPath &path ) const;
92106

93-
94107
virtual void drawAsPolygon( QPainter &p ) const;
95108

96-
97109
virtual bool insertVertex( QgsVertexId position, const QgsPoint &vertex );
110+
98111
virtual bool moveVertex( QgsVertexId position, const QgsPoint &newPos );
112+
99113
virtual bool deleteVertex( QgsVertexId position );
100114

101-
virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/,
102-
QgsVertexId &vertexAfter /Out/,
103-
bool *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;
115+
virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, bool *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;
104116

105117
virtual bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const;
106118

@@ -120,21 +132,28 @@ class QgsCircularString: QgsCurve
120132

121133
virtual QgsCircularString *reversed() const /Factory/;
122134

135+
123136
virtual bool addZValue( double zValue = 0 );
137+
124138
virtual bool addMValue( double mValue = 0 );
125139

140+
126141
virtual bool dropZValue();
142+
127143
virtual bool dropMValue();
128144

145+
129146
virtual double xAt( int index ) const;
130147

131148
virtual double yAt( int index ) const;
132149

133150

134151
protected:
152+
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;
135153

136154
virtual QgsRectangle calculateBoundingBox() const;
137155

156+
138157
};
139158

140159

0 commit comments

Comments
 (0)
Please sign in to comment.