Skip to content
Permalink
Browse files

Much more efficient QgsRectangle->QgsGeometry conversion

  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent b60489d commit 180d878d8058a881ce13afcef173d42e5fe640b7
Showing with 14 additions and 11 deletions.
  1. +14 −11 src/core/geometry/qgsgeometry.cpp
@@ -223,17 +223,20 @@ QgsGeometry QgsGeometry::fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly

QgsGeometry QgsGeometry::fromRect( const QgsRectangle &rect )
{
QgsPolylineXY ring;
ring.append( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );
ring.append( QgsPointXY( rect.xMaximum(), rect.yMinimum() ) );
ring.append( QgsPointXY( rect.xMaximum(), rect.yMaximum() ) );
ring.append( QgsPointXY( rect.xMinimum(), rect.yMaximum() ) );
ring.append( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );

QgsPolygonXY polygon;
polygon.append( ring );

return fromPolygonXY( polygon );
std::unique_ptr< QgsLineString > ext = qgis::make_unique< QgsLineString >(
QVector< double >() << rect.xMinimum()
<< rect.xMaximum()
<< rect.xMaximum()
<< rect.xMinimum()
<< rect.xMinimum(),
QVector< double >() << rect.yMinimum()
<< rect.yMinimum()
<< rect.yMaximum()
<< rect.yMaximum()
<< rect.yMinimum() );
std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
polygon->setExteriorRing( ext.release() );
return QgsGeometry( std::move( polygon ) );
}

QgsGeometry QgsGeometry::collectGeometry( const QVector< QgsGeometry > &geometries )

0 comments on commit 180d878

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