Skip to content
Permalink
Browse files

add overload methods

  • Loading branch information
lbartoletti authored and m-kuhn committed Sep 4, 2017
1 parent 6ae929e commit 629f46d308656a6326ff14fbe8efc8954af7c542
@@ -577,12 +577,28 @@ Returns true if WKB of the geometry is of WKBMulti* type
:rtype: QgsGeometry
%End

QgsGeometry orientedMinimumBoundingBox( ) const;
%Docstring
Returns the oriented minimum bounding box for the geometry, which is the smallest (by area)
rotated rectangle which fully encompasses the geometry.
.. versionadded:: 3.0
:rtype: QgsGeometry
%End

QgsGeometry minimalEnclosingCircle( QgsPointXY &center /Out/, double &radius /Out/, unsigned int segments = 36 ) const;
%Docstring
Returns the minimal enclosing circle for the geometry.
\param center Center of the minimal enclosing circle returneds
\param radius Radius of the minimal enclosing circle returned
.. seealso:: QgsEllipse.toPolygon()
.. versionadded:: 3.0
:rtype: QgsGeometry
%End

QgsGeometry minimalEnclosingCircle( unsigned int segments = 36 ) const;
%Docstring
Returns the minimal enclosing circle for the geometry.
.. seealso:: QgsEllipse.toPolygon()
.. versionadded:: 3.0
:rtype: QgsGeometry
%End
@@ -2536,24 +2536,22 @@ static QVariant fcnConvexHull( const QVariantList &values, const QgsExpressionCo
return result;
}


static QVariant fcnMinimalCircle( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
{
QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
QgsPointXY center;
double radius;
unsigned int segments = 36;
if ( values.length() == 2 )
segments = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
QgsGeometry geom = fGeom.minimalEnclosingCircle( center, radius, segments );
QgsGeometry geom = fGeom.minimalEnclosingCircle( segments );
QVariant result = !geom.isNull() ? QVariant::fromValue( geom ) : QVariant();
return result;
}

static QVariant fcnOrientedBBox( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
{
QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
double area, angle, width, height;
QgsGeometry geom = fGeom.orientedMinimumBoundingBox( area, angle, width, height );
QgsGeometry geom = fGeom.orientedMinimumBoundingBox( );
QVariant result = !geom.isNull() ? QVariant::fromValue( geom ) : QVariant();
return result;
}
@@ -1009,6 +1009,12 @@ QgsGeometry QgsGeometry::orientedMinimumBoundingBox( double &area, double &angle
return minBounds;
}

QgsGeometry QgsGeometry::orientedMinimumBoundingBox() const
{
double area, angle, width, height;
return orientedMinimumBoundingBox( area, angle, width, height );
}

static QgsCircle __recMinimalEnclosingCircle( QgsMultiPoint points, QgsMultiPoint boundary )
{
auto l_boundary = boundary.length();
@@ -1084,6 +1090,14 @@ QgsGeometry QgsGeometry::minimalEnclosingCircle( QgsPointXY &center, double &rad

}

QgsGeometry QgsGeometry::minimalEnclosingCircle( unsigned int segments ) const
{
QgsPointXY center;
double radius;
return minimalEnclosingCircle( center, radius, segments );

}

QgsGeometry QgsGeometry::orthogonalize( double tolerance, int maxIterations, double angleThreshold ) const
{
QgsInternalGeometryEngine engine( *this );
@@ -599,6 +599,13 @@ class CORE_EXPORT QgsGeometry
*/
QgsGeometry orientedMinimumBoundingBox( double &area SIP_OUT, double &angle SIP_OUT, double &width SIP_OUT, double &height SIP_OUT ) const;

/**
* Returns the oriented minimum bounding box for the geometry, which is the smallest (by area)
* rotated rectangle which fully encompasses the geometry.
* \since QGIS 3.0
*/
QgsGeometry orientedMinimumBoundingBox( ) const;

/**
* Returns the minimal enclosing circle for the geometry.
* \param center Center of the minimal enclosing circle returneds
@@ -608,6 +615,13 @@ class CORE_EXPORT QgsGeometry
*/
QgsGeometry minimalEnclosingCircle( QgsPointXY &center SIP_OUT, double &radius SIP_OUT, unsigned int segments = 36 ) const;

/**
* Returns the minimal enclosing circle for the geometry.
* \param segments Number of segments used to segment geometry. \see QgsEllipse::toPolygon()
* \since QGIS 3.0
*/
QgsGeometry minimalEnclosingCircle( unsigned int segments = 36 ) const;

/**
* Attempts to orthogonalize a line or polygon geometry by shifting vertices to make the geometries
* angles either right angles or flat lines. This is an iterative algorithm which will loop until
@@ -2303,12 +2303,9 @@ class TestQgsExpression: public QObject
QTest::newRow( "bounds" ) << "bounds( $geometry )" << geom << false << true << QgsGeometry::fromRect( geom.boundingBox() );

geom = QgsGeometry::fromPolygon( polygon );
double bbox_area, bbox_angle, bbox_width, bbox_height;
QTest::newRow( "oriented_bbox" ) << "oriented_bbox( $geometry )" << geom << false << true << geom.orientedMinimumBoundingBox( bbox_area, bbox_angle, bbox_width, bbox_height );
QTest::newRow( "oriented_bbox" ) << "oriented_bbox( $geometry )" << geom << false << true << geom.orientedMinimumBoundingBox( );
geom = QgsGeometry::fromPolygon( polygon );
QgsPointXY circ_center;
double circ_radius;
QTest::newRow( "minimal_circle" ) << "minimal_circle( $geometry )" << geom << false << true << geom.minimalEnclosingCircle( circ_center, circ_radius );
QTest::newRow( "minimal_circle" ) << "minimal_circle( $geometry )" << geom << false << true << geom.minimalEnclosingCircle( );

geom = QgsGeometry::fromPolygon( polygon );
QTest::newRow( "translate" ) << "translate( $geometry, 1, 2)" << geom << false << true << QgsGeometry::fromWkt( QStringLiteral( "POLYGON ((1 2,11 12,11 2,1 2))" ) );

0 comments on commit 629f46d

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