Skip to content

Commit 180d878

Browse files
committed
Much more efficient QgsRectangle->QgsGeometry conversion
1 parent b60489d commit 180d878

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/core/geometry/qgsgeometry.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,20 @@ QgsGeometry QgsGeometry::fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly
223223

224224
QgsGeometry QgsGeometry::fromRect( const QgsRectangle &rect )
225225
{
226-
QgsPolylineXY ring;
227-
ring.append( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );
228-
ring.append( QgsPointXY( rect.xMaximum(), rect.yMinimum() ) );
229-
ring.append( QgsPointXY( rect.xMaximum(), rect.yMaximum() ) );
230-
ring.append( QgsPointXY( rect.xMinimum(), rect.yMaximum() ) );
231-
ring.append( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );
232-
233-
QgsPolygonXY polygon;
234-
polygon.append( ring );
235-
236-
return fromPolygonXY( polygon );
226+
std::unique_ptr< QgsLineString > ext = qgis::make_unique< QgsLineString >(
227+
QVector< double >() << rect.xMinimum()
228+
<< rect.xMaximum()
229+
<< rect.xMaximum()
230+
<< rect.xMinimum()
231+
<< rect.xMinimum(),
232+
QVector< double >() << rect.yMinimum()
233+
<< rect.yMinimum()
234+
<< rect.yMaximum()
235+
<< rect.yMaximum()
236+
<< rect.yMinimum() );
237+
std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
238+
polygon->setExteriorRing( ext.release() );
239+
return QgsGeometry( std::move( polygon ) );
237240
}
238241

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

0 commit comments

Comments
 (0)