Skip to content

Commit

Permalink
Remove inefficient method for creating empty geometry of same
Browse files Browse the repository at this point in the history
WKB type, and use optimized method instead

Refs #17809
  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent 65827ad commit ff7bb9a
Show file tree
Hide file tree
Showing 29 changed files with 72 additions and 48 deletions.
4 changes: 2 additions & 2 deletions python/core/geometry/qgsabstractgeometry.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,6 @@ Returns Java-style iterator for traversal of vertices of the geometry
.. versionadded:: 3.0
%End

protected:

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

protected:

virtual bool hasChildGeometries() const;
%Docstring
Returns whether the geometry has any child geometries (false for point / curve, true otherwise)
Expand Down
4 changes: 3 additions & 1 deletion python/core/geometry/qgscircularstring.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ Sets the circular string's points
virtual double yAt( int index ) const;


protected:
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;


protected:

virtual QgsRectangle calculateBoundingBox() const;


Expand Down
5 changes: 3 additions & 2 deletions python/core/geometry/qgscompoundcurve.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ Appends first point if not already closed.
virtual double yAt( int index ) const;


virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;


protected:

virtual QgsRectangle calculateBoundingBox() const;

virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;


};

Expand Down
5 changes: 4 additions & 1 deletion python/core/geometry/qgscurvepolygon.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,12 @@ Returns approximate rotation angle for a vertex. Usually average angle between a

virtual QgsCurvePolygon *toCurveType() const /Factory/;

protected:

virtual QgsCurvePolygon *createEmptyWithSameType() const /Factory/;


protected:

virtual int childCount() const;

virtual QgsAbstractGeometry *childGeometry( int index ) const;
Expand Down
3 changes: 2 additions & 1 deletion python/core/geometry/qgsgeometrycollection.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ Returns a geometry without curves. Caller takes ownership



protected:
virtual QgsGeometryCollection *createEmptyWithSameType() const /Factory/;


protected:
virtual int childCount() const;

virtual QgsAbstractGeometry *childGeometry( int index ) const;
Expand Down
5 changes: 4 additions & 1 deletion python/core/geometry/qgslinestring.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,12 @@ of the curve.
virtual bool convertTo( QgsWkbTypes::Type type );


protected:

virtual QgsLineString *createEmptyWithSameType() const /Factory/;


protected:

virtual QgsRectangle calculateBoundingBox() const;


Expand Down
3 changes: 1 addition & 2 deletions python/core/geometry/qgsmulticurve.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ Returns a copy of the multi curve, where each component curve has had its line d



protected:

virtual QgsMultiCurve *createEmptyWithSameType() const /Factory/;



};


Expand Down
5 changes: 4 additions & 1 deletion python/core/geometry/qgsmultilinestring.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
:return: the converted geometry. Caller takes ownership*
%End

protected:

virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/;


protected:

virtual bool wktOmitChildType() const;

};
Expand Down
5 changes: 4 additions & 1 deletion python/core/geometry/qgsmultipoint.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ class QgsMultiPoint: QgsGeometryCollection
virtual double segmentLength( QgsVertexId startVertex ) const;


protected:

virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;


protected:

virtual bool wktOmitChildType() const;


Expand Down
4 changes: 3 additions & 1 deletion python/core/geometry/qgsmultipolygon.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
virtual QgsAbstractGeometry *boundary() const /Factory/;


protected:
virtual QgsMultiPolygon *createEmptyWithSameType() const /Factory/;


protected:

virtual bool wktOmitChildType() const;

};
Expand Down
1 change: 0 additions & 1 deletion python/core/geometry/qgsmultisurface.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class QgsMultiSurface: QgsGeometryCollection



protected:
virtual QgsMultiSurface *createEmptyWithSameType() const /Factory/;


Expand Down
4 changes: 3 additions & 1 deletion python/core/geometry/qgspoint.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,11 @@ Angle undefined. Always returns 0.0



protected:
virtual QgsPoint *createEmptyWithSameType() const /Factory/;


protected:

virtual int childCount() const;

virtual QgsPoint childPoint( int index ) const;
Expand Down
4 changes: 2 additions & 2 deletions python/core/geometry/qgspolygon.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ negative if the point lies outside the polygon.
%End


protected:

virtual QgsPolygon *createEmptyWithSameType() const /Factory/;


protected:


};
/************************************************************************
Expand Down
3 changes: 1 addition & 2 deletions python/core/geometry/qgstriangle.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,10 @@ Example:
%End


protected:

virtual QgsTriangle *createEmptyWithSameType() const /Factory/;



};
/************************************************************************
* This file has been generated automatically from *
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsabstractgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,6 @@ class CORE_EXPORT QgsAbstractGeometry
*/
QgsVertexIterator vertices() const;

protected:

/**
* Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
* To create it, the geometry is default constructed and then the WKB is changed.
Expand All @@ -628,6 +626,8 @@ class CORE_EXPORT QgsAbstractGeometry
*/
virtual QgsAbstractGeometry *createEmptyWithSameType() const = 0 SIP_FACTORY;

protected:

/**
* Returns whether the geometry has any child geometries (false for point / curve, true otherwise)
* \note used for vertex_iterator implementation
Expand Down
4 changes: 3 additions & 1 deletion src/core/geometry/qgscircularstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
}
#endif

protected:
QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;

protected:

QgsRectangle calculateBoundingBox() const override;

private:
Expand Down
3 changes: 2 additions & 1 deletion src/core/geometry/qgscompoundcurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
}
#endif

QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;

protected:

QgsRectangle calculateBoundingBox() const override;
QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;

private:
QVector< QgsCurve * > mCurves;
Expand Down
5 changes: 4 additions & 1 deletion src/core/geometry/qgscurvepolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
return nullptr;
}
#endif
protected:

QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY;

protected:

int childCount() const override;
QgsAbstractGeometry *childGeometry( int index ) const override;

Expand Down
3 changes: 2 additions & 1 deletion src/core/geometry/qgsgeometrycollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
}
#endif

protected:
QgsGeometryCollection *createEmptyWithSameType() const override SIP_FACTORY;

protected:
int childCount() const override;
QgsAbstractGeometry *childGeometry( int index ) const override;

Expand Down
5 changes: 4 additions & 1 deletion src/core/geometry/qgslinestring.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,11 @@ class CORE_EXPORT QgsLineString: public QgsCurve
return nullptr;
}
#endif
protected:

QgsLineString *createEmptyWithSameType() const override SIP_FACTORY;

protected:

QgsRectangle calculateBoundingBox() const override;

private:
Expand Down
3 changes: 1 addition & 2 deletions src/core/geometry/qgsmulticurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
}
#endif

protected:

QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;


};

// clazy:excludeall=qstring-allocations
Expand Down
5 changes: 4 additions & 1 deletion src/core/geometry/qgsmultilinestring.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve
return nullptr;
}
#endif
protected:

QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY;

protected:

bool wktOmitChildType() const override;
};

Expand Down
5 changes: 4 additions & 1 deletion src/core/geometry/qgsmultipoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection
return nullptr;
}
#endif
protected:

QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;

protected:

bool wktOmitChildType() const override;

};
Expand Down
4 changes: 3 additions & 1 deletion src/core/geometry/qgsmultipolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface
}
#endif

protected:
QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;

protected:

bool wktOmitChildType() const override;
};

Expand Down
1 change: 0 additions & 1 deletion src/core/geometry/qgsmultisurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class CORE_EXPORT QgsMultiSurface: public QgsGeometryCollection
}
#endif

protected:
QgsMultiSurface *createEmptyWithSameType() const override SIP_FACTORY;

};
Expand Down
4 changes: 3 additions & 1 deletion src/core/geometry/qgspoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,10 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
}
#endif

protected:
QgsPoint *createEmptyWithSameType() const override SIP_FACTORY;

protected:

int childCount() const override;
QgsPoint childPoint( int index ) const override;

Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgspolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
}
#endif

protected:

QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY;

protected:

friend class QgsCurvePolygon;

};
Expand Down
3 changes: 1 addition & 2 deletions src/core/geometry/qgstriangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,8 @@ class CORE_EXPORT QgsTriangle : public QgsPolygon
}
#endif

protected:

QgsTriangle *createEmptyWithSameType() const override SIP_FACTORY;


};
#endif // QGSTRIANGLE_H
12 changes: 1 addition & 11 deletions src/core/qgsmaptopixelgeometrysimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ static QgsGeometry generalizeWkbGeometryByBoundingBox(
}
}

template<class T>
static T *createEmptySameTypeGeom( const T &geom )
{
// TODO - this is inefficient - we clone the geometry's content only to throw it away immediately
T *output( qgsgeometry_cast<T *>( geom.clone() ) );
Q_ASSERT( output );
output->clear();
return output;
}

QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry(
int simplifyFlags,
SimplifyAlgorithm simplifyAlgorithm,
Expand Down Expand Up @@ -280,7 +270,7 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry(
else if ( QgsWkbTypes::isMultiType( flatType ) )
{
const QgsGeometryCollection &srcCollection = dynamic_cast<const QgsGeometryCollection &>( geometry );
std::unique_ptr<QgsGeometryCollection> collection( createEmptySameTypeGeom( srcCollection ) );
std::unique_ptr<QgsGeometryCollection> collection( srcCollection.createEmptyWithSameType() );
const int numGeoms = srcCollection.numGeometries();
for ( int i = 0; i < numGeoms; ++i )
{
Expand Down

0 comments on commit ff7bb9a

Please sign in to comment.