QgsQuadrilateral class

Quadrilateral geometry type.

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).

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.
enum Point { Point1, Point2, Point3, Point4 }
Simple enumeration to ensure indices in setPoint.

Public static variables

static auto& rectangleFromDiagonal constexpr
Alias for rectangleFromDiagonal.

Public static functions

static auto fromRectangle(const QgsRectangle& rectangle) -> QgsQuadrilateral
Construct a QgsQuadrilateral as a rectangle from a QgsRectangle.
static auto rectangleFrom3Points(const QgsPoint& p1, const QgsPoint& p2, const QgsPoint& p3, ConstructionOption mode) -> QgsQuadrilateral
Construct a QgsQuadrilateral as a Rectangle from 3 points.
static auto rectangleFromCenterPoint(const QgsPoint& center, const QgsPoint& point) -> QgsQuadrilateral
Construct a QgsQuadrilateral as a rectangle from center point center and another point point.
static auto rectangleFromExtent(const QgsPoint& p1, const QgsPoint& p2) -> QgsQuadrilateral
Construct a QgsQuadrilateral as a rectangle from an extent, defined by two opposite corner points.
static auto squareFromDiagonal(const QgsPoint& p1, const QgsPoint& p2) -> QgsQuadrilateral
Construct a QgsQuadrilateral as a square from a diagonal.

Constructors, destructors, conversion operators

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

Public functions

auto area() const -> double
Returns the area of the quadrilateral, or 0 if the quadrilateral is empty.
auto equals(const QgsQuadrilateral& other, double epsilon = 4*std::numeric_limits<double>::epsilon()) const -> bool
Compares two QgsQuadrilateral, allowing specification of the maximum allowable difference between points.
auto isValid() const -> bool
Convenient method to determine if a QgsQuadrilateral is valid.
auto perimeter() const -> double
Returns the perimeter of the quadrilateral, or 0 if the quadrilateral is empty.
auto points() const -> QgsPointSequence
Returns a list including the vertices of the quadrilateral.
auto setPoint(const QgsPoint& newPoint, Point index) -> bool
Sets the point newPoint at the index.
auto setPoints(const QgsPoint& p1, const QgsPoint& p2, const QgsPoint& p3, const QgsPoint& p4) -> bool
Set all points Returns false if the QgsQuadrilateral is not valid:
auto toLineString(bool force2D = false) const -> QgsLineString*
Returns the quadrilateral as a new linestring.
auto toPolygon(bool force2D = false) const -> QgsPolygon*
Returns the quadrilateral as a new polygon.
auto toString(int pointPrecision = 17) const -> QString
Returns a string representation of the quadrilateral.

Function documentation

static QgsQuadrilateral QgsQuadrilateral::fromRectangle(const QgsRectangle& rectangle)

Construct a QgsQuadrilateral as a rectangle from a QgsRectangle.

Parameters
rectangle rectangle

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

Construct a QgsQuadrilateral as a Rectangle from 3 points.

Parameters
p1 first point
p2 second point
p3 third point
mode Construction mode to construct the 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.

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

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

Parameters
center center point
point corner point

Z is taken from center point.

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

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

Parameters
p1 first point
p2 second point

Z is taken from point p1.

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

Construct a QgsQuadrilateral as a square from a diagonal.

Parameters
p1 first point
p2 second point

Z is taken from point p1.

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

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

bool QgsQuadrilateral::equals(const QgsQuadrilateral& other, double epsilon = 4*std::numeric_limits<double>::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

bool QgsQuadrilateral::isValid() const

Convenient method to determine if a QgsQuadrilateral is valid.

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

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

Sets the point newPoint at the index.

Returns false if the QgsQuadrilateral is not valid.

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

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

Returns the quadrilateral as a new linestring.

Ownership is transferred to the caller.

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

Returns the quadrilateral as a new polygon.

Ownership is transferred to the caller.

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

Returns a string representation of the quadrilateral.

Members will be truncated to the specified precision.