Skip to content

Commit ff7bb9a

Browse files
committedFeb 11, 2018
Remove inefficient method for creating empty geometry of same
WKB type, and use optimized method instead Refs #17809
1 parent 65827ad commit ff7bb9a

29 files changed

+72
-48
lines changed
 

‎python/core/geometry/qgsabstractgeometry.sip.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,6 @@ Returns Java-style iterator for traversal of vertices of the geometry
596596
.. versionadded:: 3.0
597597
%End
598598

599-
protected:
600-
601599
virtual QgsAbstractGeometry *createEmptyWithSameType() const = 0 /Factory/;
602600
%Docstring
603601
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
@@ -612,6 +610,8 @@ To create it, the geometry is default constructed and then the WKB is changed.
612610
Not available in Python bindings
613611
%End
614612

613+
protected:
614+
615615
virtual bool hasChildGeometries() const;
616616
%Docstring
617617
Returns whether the geometry has any child geometries (false for point / curve, true otherwise)

‎python/core/geometry/qgscircularstring.sip.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ Sets the circular string's points
127127
virtual double yAt( int index ) const;
128128

129129

130-
protected:
131130
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;
132131

132+
133+
protected:
134+
133135
virtual QgsRectangle calculateBoundingBox() const;
134136

135137

‎python/core/geometry/qgscompoundcurve.sip.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,13 @@ Appends first point if not already closed.
160160
virtual double yAt( int index ) const;
161161

162162

163+
virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;
164+
165+
163166
protected:
164167

165168
virtual QgsRectangle calculateBoundingBox() const;
166169

167-
virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;
168-
169170

170171
};
171172

‎python/core/geometry/qgscurvepolygon.sip.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,12 @@ Returns approximate rotation angle for a vertex. Usually average angle between a
198198

199199
virtual QgsCurvePolygon *toCurveType() const /Factory/;
200200

201-
protected:
201+
202202
virtual QgsCurvePolygon *createEmptyWithSameType() const /Factory/;
203203

204+
205+
protected:
206+
204207
virtual int childCount() const;
205208

206209
virtual QgsAbstractGeometry *childGeometry( int index ) const;

‎python/core/geometry/qgsgeometrycollection.sip.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ Returns a geometry without curves. Caller takes ownership
176176

177177

178178

179-
protected:
180179
virtual QgsGeometryCollection *createEmptyWithSameType() const /Factory/;
181180

181+
182+
protected:
182183
virtual int childCount() const;
183184

184185
virtual QgsAbstractGeometry *childGeometry( int index ) const;

‎python/core/geometry/qgslinestring.sip.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,12 @@ of the curve.
290290
virtual bool convertTo( QgsWkbTypes::Type type );
291291

292292

293-
protected:
293+
294294
virtual QgsLineString *createEmptyWithSameType() const /Factory/;
295295

296+
297+
protected:
298+
296299
virtual QgsRectangle calculateBoundingBox() const;
297300

298301

‎python/core/geometry/qgsmulticurve.sip.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ Returns a copy of the multi curve, where each component curve has had its line d
5353

5454

5555

56-
protected:
57-
5856
virtual QgsMultiCurve *createEmptyWithSameType() const /Factory/;
5957

6058

59+
6160
};
6261

6362

‎python/core/geometry/qgsmultilinestring.sip.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
4949
:return: the converted geometry. Caller takes ownership*
5050
%End
5151

52-
protected:
52+
5353
virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/;
5454

55+
56+
protected:
57+
5558
virtual bool wktOmitChildType() const;
5659

5760
};

‎python/core/geometry/qgsmultipoint.sip.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ class QgsMultiPoint: QgsGeometryCollection
5151
virtual double segmentLength( QgsVertexId startVertex ) const;
5252

5353

54-
protected:
54+
5555
virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;
5656

57+
58+
protected:
59+
5760
virtual bool wktOmitChildType() const;
5861

5962

‎python/core/geometry/qgsmultipolygon.sip.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
5151
virtual QgsAbstractGeometry *boundary() const /Factory/;
5252

5353

54-
protected:
5554
virtual QgsMultiPolygon *createEmptyWithSameType() const /Factory/;
5655

56+
57+
protected:
58+
5759
virtual bool wktOmitChildType() const;
5860

5961
};

‎python/core/geometry/qgsmultisurface.sip.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class QgsMultiSurface: QgsGeometryCollection
4545

4646

4747

48-
protected:
4948
virtual QgsMultiSurface *createEmptyWithSameType() const /Factory/;
5049

5150

‎python/core/geometry/qgspoint.sip.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,11 @@ Angle undefined. Always returns 0.0
419419

420420

421421

422-
protected:
423422
virtual QgsPoint *createEmptyWithSameType() const /Factory/;
424423

424+
425+
protected:
426+
425427
virtual int childCount() const;
426428

427429
virtual QgsPoint childPoint( int index ) const;

‎python/core/geometry/qgspolygon.sip.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ negative if the point lies outside the polygon.
6262
%End
6363

6464

65-
protected:
66-
6765
virtual QgsPolygon *createEmptyWithSameType() const /Factory/;
6866

6967

68+
protected:
69+
7070

7171
};
7272
/************************************************************************

‎python/core/geometry/qgstriangle.sip.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,10 @@ Example:
425425
%End
426426

427427

428-
protected:
429-
430428
virtual QgsTriangle *createEmptyWithSameType() const /Factory/;
431429

432430

431+
433432
};
434433
/************************************************************************
435434
* This file has been generated automatically from *

‎src/core/geometry/qgsabstractgeometry.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,6 @@ class CORE_EXPORT QgsAbstractGeometry
617617
*/
618618
QgsVertexIterator vertices() const;
619619

620-
protected:
621-
622620
/**
623621
* Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
624622
* To create it, the geometry is default constructed and then the WKB is changed.
@@ -628,6 +626,8 @@ class CORE_EXPORT QgsAbstractGeometry
628626
*/
629627
virtual QgsAbstractGeometry *createEmptyWithSameType() const = 0 SIP_FACTORY;
630628

629+
protected:
630+
631631
/**
632632
* Returns whether the geometry has any child geometries (false for point / curve, true otherwise)
633633
* \note used for vertex_iterator implementation

‎src/core/geometry/qgscircularstring.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
113113
}
114114
#endif
115115

116-
protected:
117116
QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;
117+
118+
protected:
119+
118120
QgsRectangle calculateBoundingBox() const override;
119121

120122
private:

‎src/core/geometry/qgscompoundcurve.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
142142
}
143143
#endif
144144

145+
QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;
146+
145147
protected:
146148

147149
QgsRectangle calculateBoundingBox() const override;
148-
QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;
149150

150151
private:
151152
QVector< QgsCurve * > mCurves;

‎src/core/geometry/qgscurvepolygon.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,11 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
175175
return nullptr;
176176
}
177177
#endif
178-
protected:
178+
179179
QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY;
180+
181+
protected:
182+
180183
int childCount() const override;
181184
QgsAbstractGeometry *childGeometry( int index ) const override;
182185

‎src/core/geometry/qgsgeometrycollection.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
159159
}
160160
#endif
161161

162-
protected:
163162
QgsGeometryCollection *createEmptyWithSameType() const override SIP_FACTORY;
163+
164+
protected:
164165
int childCount() const override;
165166
QgsAbstractGeometry *childGeometry( int index ) const override;
166167

‎src/core/geometry/qgslinestring.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,11 @@ class CORE_EXPORT QgsLineString: public QgsCurve
253253
return nullptr;
254254
}
255255
#endif
256-
protected:
256+
257257
QgsLineString *createEmptyWithSameType() const override SIP_FACTORY;
258+
259+
protected:
260+
258261
QgsRectangle calculateBoundingBox() const override;
259262

260263
private:

‎src/core/geometry/qgsmulticurve.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
7171
}
7272
#endif
7373

74-
protected:
75-
7674
QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;
7775

76+
7877
};
7978

8079
// clazy:excludeall=qstring-allocations

‎src/core/geometry/qgsmultilinestring.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve
6262
return nullptr;
6363
}
6464
#endif
65-
protected:
65+
6666
QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY;
67+
68+
protected:
69+
6770
bool wktOmitChildType() const override;
6871
};
6972

‎src/core/geometry/qgsmultipoint.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection
6262
return nullptr;
6363
}
6464
#endif
65-
protected:
65+
6666
QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;
67+
68+
protected:
69+
6770
bool wktOmitChildType() const override;
6871

6972
};

‎src/core/geometry/qgsmultipolygon.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface
6363
}
6464
#endif
6565

66-
protected:
6766
QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;
67+
68+
protected:
69+
6870
bool wktOmitChildType() const override;
6971
};
7072

‎src/core/geometry/qgsmultisurface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class CORE_EXPORT QgsMultiSurface: public QgsGeometryCollection
6565
}
6666
#endif
6767

68-
protected:
6968
QgsMultiSurface *createEmptyWithSameType() const override SIP_FACTORY;
7069

7170
};

‎src/core/geometry/qgspoint.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,10 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
455455
}
456456
#endif
457457

458-
protected:
459458
QgsPoint *createEmptyWithSameType() const override SIP_FACTORY;
459+
460+
protected:
461+
460462
int childCount() const override;
461463
QgsPoint childPoint( int index ) const override;
462464

‎src/core/geometry/qgspolygon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
8282
}
8383
#endif
8484

85-
protected:
86-
8785
QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY;
8886

87+
protected:
88+
8989
friend class QgsCurvePolygon;
9090

9191
};

‎src/core/geometry/qgstriangle.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,8 @@ class CORE_EXPORT QgsTriangle : public QgsPolygon
412412
}
413413
#endif
414414

415-
protected:
416-
417415
QgsTriangle *createEmptyWithSameType() const override SIP_FACTORY;
418416

417+
419418
};
420419
#endif // QGSTRIANGLE_H

‎src/core/qgsmaptopixelgeometrysimplifier.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,6 @@ static QgsGeometry generalizeWkbGeometryByBoundingBox(
102102
}
103103
}
104104

105-
template<class T>
106-
static T *createEmptySameTypeGeom( const T &geom )
107-
{
108-
// TODO - this is inefficient - we clone the geometry's content only to throw it away immediately
109-
T *output( qgsgeometry_cast<T *>( geom.clone() ) );
110-
Q_ASSERT( output );
111-
output->clear();
112-
return output;
113-
}
114-
115105
QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry(
116106
int simplifyFlags,
117107
SimplifyAlgorithm simplifyAlgorithm,
@@ -280,7 +270,7 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry(
280270
else if ( QgsWkbTypes::isMultiType( flatType ) )
281271
{
282272
const QgsGeometryCollection &srcCollection = dynamic_cast<const QgsGeometryCollection &>( geometry );
283-
std::unique_ptr<QgsGeometryCollection> collection( createEmptySameTypeGeom( srcCollection ) );
273+
std::unique_ptr<QgsGeometryCollection> collection( srcCollection.createEmptyWithSameType() );
284274
const int numGeoms = srcCollection.numGeometries();
285275
for ( int i = 0; i < numGeoms; ++i )
286276
{

0 commit comments

Comments
 (0)
Please sign in to comment.