Skip to content
Permalink
Browse files

Remove inefficient method for creating empty geometry of same

WKB type, and use optimized method instead

Refs #17809
  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent 65827ad commit ff7bb9aa53f0180f17dea27f270d7012792f0e17
@@ -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.
@@ -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)
@@ -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;


@@ -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/;


};

@@ -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;
@@ -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;
@@ -290,9 +290,12 @@ of the curve.
virtual bool convertTo( QgsWkbTypes::Type type );


protected:

virtual QgsLineString *createEmptyWithSameType() const /Factory/;


protected:

virtual QgsRectangle calculateBoundingBox() const;


@@ -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/;



};


@@ -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;

};
@@ -51,9 +51,12 @@ class QgsMultiPoint: QgsGeometryCollection
virtual double segmentLength( QgsVertexId startVertex ) const;


protected:

virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;


protected:

virtual bool wktOmitChildType() const;


@@ -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;

};
@@ -45,7 +45,6 @@ class QgsMultiSurface: QgsGeometryCollection



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


@@ -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;
@@ -62,11 +62,11 @@ negative if the point lies outside the polygon.
%End


protected:

virtual QgsPolygon *createEmptyWithSameType() const /Factory/;


protected:


};
/************************************************************************
@@ -425,11 +425,10 @@ Example:
%End


protected:

virtual QgsTriangle *createEmptyWithSameType() const /Factory/;



};
/************************************************************************
* This file has been generated automatically from *
@@ -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.
@@ -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
@@ -113,8 +113,10 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
}
#endif

protected:
QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;

protected:

QgsRectangle calculateBoundingBox() const override;

private:
@@ -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;
@@ -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;

@@ -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;

@@ -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:
@@ -71,10 +71,9 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
}
#endif

protected:

QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;


};

// clazy:excludeall=qstring-allocations
@@ -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;
};

@@ -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;

};
@@ -63,8 +63,10 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface
}
#endif

protected:
QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;

protected:

bool wktOmitChildType() const override;
};

@@ -65,7 +65,6 @@ class CORE_EXPORT QgsMultiSurface: public QgsGeometryCollection
}
#endif

protected:
QgsMultiSurface *createEmptyWithSameType() const override SIP_FACTORY;

};
@@ -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;

@@ -82,10 +82,10 @@ class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
}
#endif

protected:

QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY;

protected:

friend class QgsCurvePolygon;

};
@@ -412,9 +412,8 @@ class CORE_EXPORT QgsTriangle : public QgsPolygon
}
#endif

protected:

QgsTriangle *createEmptyWithSameType() const override SIP_FACTORY;


};
#endif // QGSTRIANGLE_H
@@ -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,
@@ -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 )
{

0 comments on commit ff7bb9a

Please sign in to comment.
You can’t perform that action at this time.