QgsGeometry *QgsRubberBand::asGeometry() { QgsGeometry *geom = NULL; switch ( mGeometryType ) { case QGis::Polygon: { QgsPolygon polygon; QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin(); for ( ; it != mPoints.constEnd(); ++it ) { polygon.append( getPolyline( *it ) ); } geom = QgsGeometry::fromPolygon( polygon ); break; } case QGis::Point: { QgsMultiPoint multiPoint; QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin(); for ( ; it != mPoints.constEnd(); ++it ) { multiPoint += getPolyline( *it ); } geom = QgsGeometry::fromMultiPoint( multiPoint ); break; } case QGis::Line: default: { if ( mPoints.size() > 0 ) { if ( mPoints.size() > 1 ) { QgsMultiPolyline multiPolyline; QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin(); for ( ; it != mPoints.constEnd(); ++it ) { multiPolyline.append( getPolyline( *it ) ); } geom = QgsGeometry::fromMultiPolyline( multiPolyline ); } else { geom = QgsGeometry::fromPolyline( getPolyline( mPoints[0] ) ); } } break; } } return geom; }
QgsAbstractGeometryV2* QgsGeometryImport::fromRect( const QgsRectangle& rect ) { QgsPolyline ring; ring.append( QgsPoint( rect.xMinimum(), rect.yMinimum() ) ); ring.append( QgsPoint( rect.xMaximum(), rect.yMinimum() ) ); ring.append( QgsPoint( rect.xMaximum(), rect.yMaximum() ) ); ring.append( QgsPoint( rect.xMinimum(), rect.yMaximum() ) ); ring.append( QgsPoint( rect.xMinimum(), rect.yMinimum() ) ); QgsPolygon polygon; polygon.append( ring ); return fromPolygon( polygon ); }
double QgsGrassGisLib::G_area_of_polygon( const double *x, const double *y, int n ) { QgsPolyline polyline; for ( int i = 0; i < n; i++ ) { polyline.append( QgsPoint( x[i], y[i] ) ); } QgsPolygon polygon; polygon.append( polyline ); QgsGeometry* geo = QgsGeometry::fromPolygon( polygon ); double area = mDistanceArea.measure( geo ); delete geo; if ( !mCrs.geographicFlag() ) { area *= qPow( G_database_units_to_meters_factor(), 2 ); } return area; }