QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
QgsQuadrilateral Class Reference

Quadrilateral geometry type. More...

#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

 QgsQuadrilateral ()
 Constructor for an empty quadrilateral geometry.
 
 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)
 Construct a QgsQuadrilateral from four QgsPointXY.
 
double area () const
 Returns the area of the quadrilateral, or 0 if the quadrilateral is empty.
 
bool 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.
 
bool isValid () const
 Convenient method to determine if a QgsQuadrilateral is valid.
 
bool operator!= (const QgsQuadrilateral &other) const
 
bool operator== (const QgsQuadrilateral &other) const
 
double perimeter () const
 Returns the perimeter of the quadrilateral, or 0 if the quadrilateral is empty.
 
QgsPointSequence points () const
 Returns a list including the vertices of the quadrilateral.
 
bool setPoint (const QgsPoint &newPoint, Point index)
 Sets the point newPoint at the index.
 
bool setPoints (const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4)
 Set all points Returns false if the QgsQuadrilateral is not valid:
 
QgsLineStringtoLineString (bool force2D=false) const
 Returns the quadrilateral as a new linestring.
 
QgsPolygontoPolygon (bool force2D=false) const
 Returns the quadrilateral as a new polygon.
 
QString toString (int pointPrecision=17) const
 Returns a string representation of the quadrilateral.
 

Static Public Member Functions

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

Static Public Attributes

static constexpr auto & rectangleFromDiagonal = rectangleFromExtent
 Alias for rectangleFromDiagonal.
 

Detailed Description

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

Since
QGIS 3.6

Definition at line 36 of file qgsquadrilateral.h.

Member Enumeration Documentation

◆ 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 perpendicular projection of the 3rd point on the segment or its extension.

Definition at line 70 of file qgsquadrilateral.h.

◆ Point

Simple enumeration to ensure indices in setPoint.

Enumerator
Point1 
Point2 
Point3 
Point4 

Definition at line 157 of file qgsquadrilateral.h.

Constructor & Destructor Documentation

◆ QgsQuadrilateral() [1/3]

QgsQuadrilateral::QgsQuadrilateral ( )
default

Constructor for an empty quadrilateral geometry.

◆ QgsQuadrilateral() [2/3]

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

Construct a QgsQuadrilateral from four QgsPoint.

Parameters
p1first point
p2second point
p3third point
p4fourth point
See also
setPoints

Definition at line 23 of file qgsquadrilateral.cpp.

◆ QgsQuadrilateral() [3/3]

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

Construct a QgsQuadrilateral from four QgsPointXY.

Parameters
p1first point
p2second point
p3third point
p4fourth point
See also
setPoints

Definition at line 28 of file qgsquadrilateral.cpp.

Member Function Documentation

◆ area()

double QgsQuadrilateral::area ( ) const

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

Definition at line 436 of file qgsquadrilateral.cpp.

◆ equals()

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
otherthe QgsQuadrilateral to compare
epsilonthe maximum difference allowed / tolerance

Definition at line 246 of file qgsquadrilateral.cpp.

◆ fromRectangle()

QgsQuadrilateral QgsQuadrilateral::fromRectangle ( const QgsRectangle rectangle)
static

Construct a QgsQuadrilateral as a rectangle from a QgsRectangle.

Parameters
rectanglerectangle

Definition at line 219 of file qgsquadrilateral.cpp.

◆ isValid()

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.

Definition at line 330 of file qgsquadrilateral.cpp.

◆ operator!=()

bool QgsQuadrilateral::operator!= ( const QgsQuadrilateral other) const

Definition at line 267 of file qgsquadrilateral.cpp.

◆ operator==()

bool QgsQuadrilateral::operator== ( const QgsQuadrilateral other) const

Definition at line 262 of file qgsquadrilateral.cpp.

◆ perimeter()

double QgsQuadrilateral::perimeter ( ) const

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

Definition at line 442 of file qgsquadrilateral.cpp.

◆ points()

QgsPointSequence QgsQuadrilateral::points ( ) const

Returns a list including the vertices of the quadrilateral.

Definition at line 377 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. M is taken from point p1.

Parameters
p1first point
p2second point
p3third point
modeConstruction mode to construct the rectangle from 3 points
See also
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 and M are taken from point p1. QgsQuadrilateral will have the same dimension as center dimension.

Parameters
centercenter point
pointcorner point

Definition at line 206 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 and M are taken from point p1. QgsQuadrilateral will have the same dimension as p1 dimension.

Parameters
p1first point
p2second point

Definition at line 134 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.

See also
Point

Definition at line 335 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 364 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 and M are taken from point p1. QgsQuadrilateral will have the same dimension as p1 dimension.

Parameters
p1first point
p2second point

Definition at line 177 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 399 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 386 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 421 of file qgsquadrilateral.cpp.

Member Data Documentation

◆ rectangleFromDiagonal

constexpr auto& QgsQuadrilateral::rectangleFromDiagonal = rectangleFromExtent
staticconstexpr

Alias for rectangleFromDiagonal.

Definition at line 107 of file qgsquadrilateral.h.


The documentation for this class was generated from the following files: