QGIS API Documentation  3.16.0-Hannover (43b64b13f3)

`#include <qgsquadrilateral.h>`

## Public Types

enum  ConstructionOption { Distance, Projected }
A quadrilateral can be constructed from 3 points where the second distance can be determined by the third point. More...

enum  Point { Point1, Point2, Point3, Point4 }
Simple enumeration to ensure indices in setPoint. More...

## Public Member Functions

Constructor for an empty quadrilateral geometry. More...

QgsQuadrilateral (const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4) SIP_HOLDGIL
Construct a QgsQuadrilateral from four QgsPoint. More...

QgsQuadrilateral (const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3, const QgsPointXY &p4) SIP_HOLDGIL
Construct a QgsQuadrilateral from four QgsPointXY. More...

double area () const SIP_HOLDGIL
Returns the area of the quadrilateral, or 0 if the quadrilateral is empty. More...

bool equals (const QgsQuadrilateral &other, double epsilon=4 *std::numeric_limits< double >::epsilon()) const SIP_HOLDGIL
Compares two QgsQuadrilateral, allowing specification of the maximum allowable difference between points. More...

bool isValid () const SIP_HOLDGIL
Convenient method to determine if a QgsQuadrilateral is valid. More...

bool operator!= (const QgsQuadrilateral &other) const SIP_HOLDGIL

bool operator== (const QgsQuadrilateral &other) const SIP_HOLDGIL

double perimeter () const SIP_HOLDGIL
Returns the perimeter of the quadrilateral, or 0 if the quadrilateral is empty. More...

QgsPointSequence points () const
Returns a list including the vertices of the quadrilateral. More...

bool setPoint (const QgsPoint &newPoint, Point index) SIP_HOLDGIL
Sets the point newPoint at the index. More...

bool setPoints (const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4) SIP_HOLDGIL
Set all points Returns `false` if the QgsQuadrilateral is not valid: More...

QgsLineStringtoLineString (bool force2D=false) const
Returns the quadrilateral as a new linestring. More...

QgsPolygontoPolygon (bool force2D=false) const
Returns the quadrilateral as a new polygon. More...

QString toString (int pointPrecision=17) const
Returns a string representation of the quadrilateral. More...

## Static Public Member Functions

static QgsQuadrilateral fromRectangle (const QgsRectangle &rectangle) SIP_HOLDGIL
Construct a QgsQuadrilateral as a rectangle from a QgsRectangle. More...

static QgsQuadrilateral rectangleFrom3Points (const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, ConstructionOption mode) SIP_HOLDGIL
Construct a QgsQuadrilateral as a Rectangle from 3 points. More...

static QgsQuadrilateral rectangleFromCenterPoint (const QgsPoint &center, const QgsPoint &point) SIP_HOLDGIL
Construct a QgsQuadrilateral as a rectangle from center point center and another point point. More...

static QgsQuadrilateral rectangleFromExtent (const QgsPoint &p1, const QgsPoint &p2) SIP_HOLDGIL
Construct a QgsQuadrilateral as a rectangle from an extent, defined by two opposite corner points. More...

static QgsQuadrilateral squareFromDiagonal (const QgsPoint &p1, const QgsPoint &p2) SIP_HOLDGIL
Construct a QgsQuadrilateral as a square from a diagonal. More...

## Static Public Attributes

static constexpr auto & rectangleFromDiagonal = rectangleFromExtent
Alias for rectangleFromDiagonal. More...

## Detailed Description

A quadrilateral is a polygon with four edges (or sides) and four vertices or corners. This class allows the creation of simple quadrilateral (which does not self-intersect).

Since
QGIS 3.6

Definition at line 35 of file qgsquadrilateral.h.

## ◆ ConstructionOption

A quadrilateral can be constructed from 3 points where the second distance can be determined by the third point.

Enumerator
Distance

Second distance is equal to the distance between 2nd and 3rd point.

Projected

Second distance is equal to the distance of the perpendicualr projection of the 3rd point on the segment or its extension.

Definition at line 69 of file qgsquadrilateral.h.

## ◆ Point

Simple enumeration to ensure indices in setPoint.

Enumerator
Point1
Point2
Point3
Point4

Definition at line 152 of file qgsquadrilateral.h.

## Constructor & Destructor Documentation

default

Constructor for an empty quadrilateral geometry.

 QgsQuadrilateral::QgsQuadrilateral ( const QgsPoint & p1, const QgsPoint & p2, const QgsPoint & p3, const QgsPoint & p4 )

Construct a QgsQuadrilateral from four QgsPoint.

Parameters
 p1 first point p2 second point p3 third point p4 fourth point
setPoints

Definition at line 23 of file qgsquadrilateral.cpp.

 QgsQuadrilateral::QgsQuadrilateral ( const QgsPointXY & p1, const QgsPointXY & p2, const QgsPointXY & p3, const QgsPointXY & p4 )
explicit

Construct a QgsQuadrilateral from four QgsPointXY.

Parameters
 p1 first point p2 second point p3 third point p4 fourth point
setPoints

Definition at line 28 of file qgsquadrilateral.cpp.

## ◆ area()

Returns the area of the quadrilateral, or 0 if the quadrilateral is empty.

Definition at line 416 of file qgsquadrilateral.cpp.

## ◆ equals()

 bool QgsQuadrilateral::equals ( const QgsQuadrilateral & other, double epsilon = `4 * std::numeric_limits::epsilon()` ) const

Compares two QgsQuadrilateral, allowing specification of the maximum allowable difference between points.

Parameters
 other the QgsQuadrilateral to compare epsilon the maximum difference allowed / tolerance

Definition at line 229 of file qgsquadrilateral.cpp.

## ◆ fromRectangle()

static

Construct a QgsQuadrilateral as a rectangle from a QgsRectangle.

Parameters
 rectangle rectangle

Definition at line 202 of file qgsquadrilateral.cpp.

## ◆ isValid()

Convenient method to determine if a QgsQuadrilateral is valid.

A QgsQuadrilateral must be simple (not self-intersecting) and cannot have collinear points.

Definition at line 313 of file qgsquadrilateral.cpp.

## ◆ operator!=()

Definition at line 250 of file qgsquadrilateral.cpp.

## ◆ operator==()

Definition at line 245 of file qgsquadrilateral.cpp.

## ◆ perimeter()

Returns the perimeter of the quadrilateral, or 0 if the quadrilateral is empty.

Definition at line 421 of file qgsquadrilateral.cpp.

## ◆ points()

Returns a list including the vertices of the quadrilateral.

Definition at line 360 of file qgsquadrilateral.cpp.

## ◆ rectangleFrom3Points()

 QgsQuadrilateral QgsQuadrilateral::rectangleFrom3Points ( const QgsPoint & p1, const QgsPoint & p2, const QgsPoint & p3, ConstructionOption mode )
static

Construct a QgsQuadrilateral as a Rectangle from 3 points.

In the case where one of the points is of type PointZ. The other points will also be of type Z, even if they are of type Point. In addition, the z used will be the one of the first point with a Z. This ensures consistency in point types and the ability to export to a Polygon or LineString.

Parameters
 p1 first point p2 second point p3 third point mode Construction mode to construct the rectangle from 3 points
ConstructionOption

Definition at line 33 of file qgsquadrilateral.cpp.

## ◆ rectangleFromCenterPoint()

 QgsQuadrilateral QgsQuadrilateral::rectangleFromCenterPoint ( const QgsPoint & center, const QgsPoint & point )
static

Construct a QgsQuadrilateral as a rectangle from center point center and another point point.

Z is taken from center point.

Parameters
 center center point point corner point

Definition at line 189 of file qgsquadrilateral.cpp.

## ◆ rectangleFromExtent()

 QgsQuadrilateral QgsQuadrilateral::rectangleFromExtent ( const QgsPoint & p1, const QgsPoint & p2 )
static

Construct a QgsQuadrilateral as a rectangle from an extent, defined by two opposite corner points.

Z is taken from point p1.

Parameters
 p1 first point p2 second point

Definition at line 117 of file qgsquadrilateral.cpp.

## ◆ setPoint()

 bool QgsQuadrilateral::setPoint ( const QgsPoint & newPoint, Point index )

Sets the point newPoint at the index.

Returns `false` if the QgsQuadrilateral is not valid.

Point

Definition at line 318 of file qgsquadrilateral.cpp.

## ◆ setPoints()

 bool QgsQuadrilateral::setPoints ( const QgsPoint & p1, const QgsPoint & p2, const QgsPoint & p3, const QgsPoint & p4 )

Set all points Returns `false` if the QgsQuadrilateral is not valid:

• The points do not have the same type
• The quadrilateral would have auto intersections
• The quadrilateral has double points
• The quadrilateral has collinear points

Definition at line 347 of file qgsquadrilateral.cpp.

## ◆ squareFromDiagonal()

 QgsQuadrilateral QgsQuadrilateral::squareFromDiagonal ( const QgsPoint & p1, const QgsPoint & p2 )
static

Construct a QgsQuadrilateral as a square from a diagonal.

Z is taken from point p1.

Parameters
 p1 first point p2 second point

Definition at line 159 of file qgsquadrilateral.cpp.

## ◆ toLineString()

 QgsLineString * QgsQuadrilateral::toLineString ( bool force2D = `false` ) const

Returns the quadrilateral as a new linestring.

Ownership is transferred to the caller.

Definition at line 382 of file qgsquadrilateral.cpp.

## ◆ toPolygon()

 QgsPolygon * QgsQuadrilateral::toPolygon ( bool force2D = `false` ) const

Returns the quadrilateral as a new polygon.

Ownership is transferred to the caller.

Definition at line 369 of file qgsquadrilateral.cpp.

## ◆ toString()

 QString QgsQuadrilateral::toString ( int pointPrecision = `17` ) const

Returns a string representation of the quadrilateral.

Members will be truncated to the specified precision.

Definition at line 401 of file qgsquadrilateral.cpp.