Skip to content

Commit fc6c69b

Browse files
committedNov 14, 2017
Fix calculation of distance to vertex for multi part, multi ring
and curved geometries
1 parent 5d476e5 commit fc6c69b

31 files changed

+461
-249
lines changed
 

‎python/core/geometry/qgsabstractgeometry.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ class QgsAbstractGeometry
366366
:rtype: float
367367
%End
368368

369+
virtual double segmentLength( QgsVertexId startVertex ) const = 0;
370+
%Docstring
371+
Returns the length of the segment of the geometry which begins at ``startVertex``.
372+
.. versionadded:: 3.0
373+
:rtype: float
374+
%End
375+
369376
virtual QgsPoint centroid() const;
370377
%Docstring
371378
Returns the centroid of the geometry

‎python/core/geometry/qgscircularstring.sip

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,10 @@ class QgsCircularString: QgsCurve
7979

8080
virtual QgsPoint endPoint() const;
8181

82-
8382
virtual QgsLineString *curveToLine( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const /Factory/;
8483

85-
%Docstring
86-
Returns a new line string geometry corresponding to a segmentized approximation
87-
of the curve.
88-
\param tolerance segmentation tolerance
89-
\param toleranceType maximum segmentation angle or maximum difference between approximation and curve
90-
91-
Uses a MaximumAngle tolerance of 1 degrees by default (360
92-
segments in a full circle)
93-
:rtype: QgsLineString
94-
%End
95-
9684
virtual QgsCircularString *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const /Factory/;
9785

98-
9986
virtual void draw( QPainter &p ) const;
10087

10188
virtual void transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform,
@@ -120,29 +107,20 @@ class QgsCircularString: QgsCurve
120107

121108
virtual bool hasCurvedSegments() const;
122109

123-
124110
virtual double vertexAngle( QgsVertexId vertex ) const;
125111

126-
%Docstring
127-
Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
128-
\param vertex the vertex id
129-
:return: rotation in radians, clockwise from north*
130-
:rtype: float
131-
%End
112+
virtual double segmentLength( QgsVertexId startVertex ) const;
132113

133114
virtual QgsCircularString *reversed() const /Factory/;
134115

135-
136116
virtual bool addZValue( double zValue = 0 );
137117

138118
virtual bool addMValue( double mValue = 0 );
139119

140-
141120
virtual bool dropZValue();
142121

143122
virtual bool dropMValue();
144123

145-
146124
virtual double xAt( int index ) const;
147125

148126
virtual double yAt( int index ) const;

‎python/core/geometry/qgscompoundcurve.sip

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,9 @@ Appends first point if not already closed.
138138

139139
virtual bool hasCurvedSegments() const;
140140

141-
142141
virtual double vertexAngle( QgsVertexId vertex ) const;
143142

144-
%Docstring
145-
Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
146-
\param vertex the vertex id
147-
:return: rotation in radians, clockwise from north*
148-
:rtype: float
149-
%End
143+
virtual double segmentLength( QgsVertexId startVertex ) const;
150144

151145
virtual QgsCompoundCurve *reversed() const /Factory/;
152146

‎python/core/geometry/qgscurve.sip

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ class QgsCurve: QgsAbstractGeometry
6767
Returns a new line string geometry corresponding to a segmentized approximation
6868
of the curve.
6969
\param tolerance segmentation tolerance
70-
\param toleranceType maximum segmentation angle or maximum difference between approximation and curve*
70+
\param toleranceType maximum segmentation angle or maximum difference between approximation and curve
71+
72+
Uses a MaximumAngle tolerance of 1 degrees by default (360
73+
segments in a full circle)
7174
:rtype: QgsLineString
7275
%End
7376

‎python/core/geometry/qgscurvepolygon.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ Adds an interior ring to the geometry (takes ownership)
185185

186186
virtual QgsPoint vertexAt( QgsVertexId id ) const;
187187

188+
virtual double segmentLength( QgsVertexId startVertex ) const;
189+
188190

189191
virtual bool addZValue( double zValue = 0 );
190192

‎python/core/geometry/qgsgeometrycollection.sip

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,7 @@ Adds a geometry and takes ownership. Returns true in case of success.
145145

146146
virtual double vertexAngle( QgsVertexId vertex ) const;
147147

148-
%Docstring
149-
Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
150-
\param vertex the vertex id
151-
:return: rotation in radians, clockwise from north
152-
:rtype: float
153-
%End
148+
virtual double segmentLength( QgsVertexId startVertex ) const;
154149

155150
virtual int vertexCount( int part = 0, int ring = 0 ) const;
156151

‎python/core/geometry/qgslinestring.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ Closes the line string by appending the first point to the end of the line, if i
255255

256256
virtual double vertexAngle( QgsVertexId vertex ) const;
257257

258+
virtual double segmentLength( QgsVertexId startVertex ) const;
258259

259260
virtual bool addZValue( double zValue = 0 );
260261

‎python/core/geometry/qgsmultipoint.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class QgsMultiPoint: QgsGeometryCollection
4747

4848
virtual int vertexNumberFromVertexId( QgsVertexId id ) const;
4949

50+
virtual double segmentLength( QgsVertexId startVertex ) const;
5051

5152

5253
protected:

‎python/core/geometry/qgspoint.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ class QgsPoint: QgsAbstractGeometry
403403

404404
virtual QgsPoint *toCurveType() const /Factory/;
405405

406+
virtual double segmentLength( QgsVertexId startVertex ) const;
407+
406408

407409
virtual bool addZValue( double zValue = 0 );
408410

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<ogr:FeatureCollection
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation=""
4+
xsi:schemaLocation="http://ogr.maptools.org/ extract_nodes_multilines.xsd"
55
xmlns:ogr="http://ogr.maptools.org/"
66
xmlns:gml="http://www.opengis.net/gml">
77
<gml:boundedBy>
@@ -15,48 +15,48 @@
1515
<ogr:extract_nodes_multilines fid="lines.1">
1616
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>-1,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
1717
<ogr:node_index>0</ogr:node_index>
18-
<ogr:distance>0</ogr:distance>
19-
<ogr:angle>90</ogr:angle>
18+
<ogr:distance>0.00000000000000</ogr:distance>
19+
<ogr:angle>90.00000000000000</ogr:angle>
2020
</ogr:extract_nodes_multilines>
2121
</gml:featureMember>
2222
<gml:featureMember>
2323
<ogr:extract_nodes_multilines fid="lines.1">
2424
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
2525
<ogr:node_index>1</ogr:node_index>
26-
<ogr:distance>2</ogr:distance>
27-
<ogr:angle>90</ogr:angle>
26+
<ogr:distance>2.00000000000000</ogr:distance>
27+
<ogr:angle>90.00000000000000</ogr:angle>
2828
</ogr:extract_nodes_multilines>
2929
</gml:featureMember>
3030
<gml:featureMember>
3131
<ogr:extract_nodes_multilines fid="lines.2">
3232
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,1</gml:coordinates></gml:Point></ogr:geometryProperty>
3333
<ogr:node_index>0</ogr:node_index>
34-
<ogr:distance>0</ogr:distance>
35-
<ogr:angle>90</ogr:angle>
34+
<ogr:distance>0.00000000000000</ogr:distance>
35+
<ogr:angle>90.00000000000000</ogr:angle>
3636
</ogr:extract_nodes_multilines>
3737
</gml:featureMember>
3838
<gml:featureMember>
3939
<ogr:extract_nodes_multilines fid="lines.2">
4040
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,1</gml:coordinates></gml:Point></ogr:geometryProperty>
4141
<ogr:node_index>1</ogr:node_index>
42-
<ogr:distance>2</ogr:distance>
43-
<ogr:angle>90</ogr:angle>
42+
<ogr:distance>2.00000000000000</ogr:distance>
43+
<ogr:angle>90.00000000000000</ogr:angle>
4444
</ogr:extract_nodes_multilines>
4545
</gml:featureMember>
4646
<gml:featureMember>
4747
<ogr:extract_nodes_multilines fid="lines.2">
48-
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.024184261036468,2.414779270633399</gml:coordinates></gml:Point></ogr:geometryProperty>
48+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.02418426103647,2.4147792706334</gml:coordinates></gml:Point></ogr:geometryProperty>
4949
<ogr:node_index>2</ogr:node_index>
50-
<ogr:distance>3.41498595862145</ogr:distance>
51-
<ogr:angle>180.979319654339</ogr:angle>
50+
<ogr:distance>2.00000000000000</ogr:distance>
51+
<ogr:angle>180.97931965433949</ogr:angle>
5252
</ogr:extract_nodes_multilines>
5353
</gml:featureMember>
5454
<gml:featureMember>
5555
<ogr:extract_nodes_multilines fid="lines.2">
5656
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,1</gml:coordinates></gml:Point></ogr:geometryProperty>
5757
<ogr:node_index>3</ogr:node_index>
58-
<ogr:distance>4.82997191724289</ogr:distance>
59-
<ogr:angle>180.979319654339</ogr:angle>
58+
<ogr:distance>3.41498595862145</ogr:distance>
59+
<ogr:angle>180.97931965433949</ogr:angle>
6060
</ogr:extract_nodes_multilines>
6161
</gml:featureMember>
6262
<gml:featureMember>
@@ -67,64 +67,64 @@
6767
<ogr:extract_nodes_multilines fid="lines.4">
6868
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,0</gml:coordinates></gml:Point></ogr:geometryProperty>
6969
<ogr:node_index>0</ogr:node_index>
70-
<ogr:distance>0</ogr:distance>
71-
<ogr:angle>0</ogr:angle>
70+
<ogr:distance>0.00000000000000</ogr:distance>
71+
<ogr:angle>0.00000000000000</ogr:angle>
7272
</ogr:extract_nodes_multilines>
7373
</gml:featureMember>
7474
<gml:featureMember>
7575
<ogr:extract_nodes_multilines fid="lines.4">
7676
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
7777
<ogr:node_index>1</ogr:node_index>
78-
<ogr:distance>2</ogr:distance>
79-
<ogr:angle>45</ogr:angle>
78+
<ogr:distance>2.00000000000000</ogr:distance>
79+
<ogr:angle>45.00000000000000</ogr:angle>
8080
</ogr:extract_nodes_multilines>
8181
</gml:featureMember>
8282
<gml:featureMember>
8383
<ogr:extract_nodes_multilines fid="lines.4">
8484
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,2</gml:coordinates></gml:Point></ogr:geometryProperty>
8585
<ogr:node_index>2</ogr:node_index>
86-
<ogr:distance>3</ogr:distance>
87-
<ogr:angle>45</ogr:angle>
86+
<ogr:distance>3.00000000000000</ogr:distance>
87+
<ogr:angle>45.00000000000000</ogr:angle>
8888
</ogr:extract_nodes_multilines>
8989
</gml:featureMember>
9090
<gml:featureMember>
9191
<ogr:extract_nodes_multilines fid="lines.4">
9292
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3</gml:coordinates></gml:Point></ogr:geometryProperty>
9393
<ogr:node_index>3</ogr:node_index>
94-
<ogr:distance>4</ogr:distance>
95-
<ogr:angle>0</ogr:angle>
94+
<ogr:distance>4.00000000000000</ogr:distance>
95+
<ogr:angle>0.00000000000000</ogr:angle>
9696
</ogr:extract_nodes_multilines>
9797
</gml:featureMember>
9898
<gml:featureMember>
9999
<ogr:extract_nodes_multilines fid="lines.4">
100-
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.944337811900192,4.04721689059501</gml:coordinates></gml:Point></ogr:geometryProperty>
100+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.94433781190019,4.04721689059501</gml:coordinates></gml:Point></ogr:geometryProperty>
101101
<ogr:node_index>4</ogr:node_index>
102-
<ogr:distance>5.04869513927144</ogr:distance>
103-
<ogr:angle>88.3476953223487</ogr:angle>
102+
<ogr:distance>4.00000000000000</ogr:distance>
103+
<ogr:angle>88.34769532234870</ogr:angle>
104104
</ogr:extract_nodes_multilines>
105105
</gml:featureMember>
106106
<gml:featureMember>
107107
<ogr:extract_nodes_multilines fid="lines.4">
108-
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.459500959692898,4.119769673704415</gml:coordinates></gml:Point></ogr:geometryProperty>
108+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.4595009596929,4.11976967370441</gml:coordinates></gml:Point></ogr:geometryProperty>
109109
<ogr:node_index>5</ogr:node_index>
110-
<ogr:distance>7.56490450384177</ogr:distance>
111-
<ogr:angle>88.3476953223487</ogr:angle>
110+
<ogr:distance>6.51620936457033</ogr:distance>
111+
<ogr:angle>88.34769532234870</ogr:angle>
112112
</ogr:extract_nodes_multilines>
113113
</gml:featureMember>
114114
<gml:featureMember>
115115
<ogr:extract_nodes_multilines fid="lines.4">
116116
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3</gml:coordinates></gml:Point></ogr:geometryProperty>
117117
<ogr:node_index>6</ogr:node_index>
118-
<ogr:distance>10.2673162217113</ogr:distance>
119-
<ogr:angle>91.1803544802029</ogr:angle>
118+
<ogr:distance>6.51620936457033</ogr:distance>
119+
<ogr:angle>91.18035448020294</ogr:angle>
120120
</ogr:extract_nodes_multilines>
121121
</gml:featureMember>
122122
<gml:featureMember>
123123
<ogr:extract_nodes_multilines fid="lines.4">
124-
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.58042226487524,2.946833013435702</gml:coordinates></gml:Point></ogr:geometryProperty>
124+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.58042226487524,2.9468330134357</gml:coordinates></gml:Point></ogr:geometryProperty>
125125
<ogr:node_index>7</ogr:node_index>
126-
<ogr:distance>12.8482861544157</ogr:distance>
127-
<ogr:angle>91.1803544802029</ogr:angle>
126+
<ogr:distance>9.09717929727474</ogr:distance>
127+
<ogr:angle>91.18035448020294</ogr:angle>
128128
</ogr:extract_nodes_multilines>
129129
</gml:featureMember>
130130
</ogr:FeatureCollection>

0 commit comments

Comments
 (0)
Please sign in to comment.