QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 ()
 
 QgsQuadrilateral (const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4)
 Construct a QgsQuadrilateral from four QgsPoint. More...
 
 QgsQuadrilateral (const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3, const QgsPointXY &p4)
 Construct a QgsQuadrilateral from four QgsPointXY. More...
 
double area () const
 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
 Compares two QgsQuadrilateral, allowing specification of the maximum allowable difference between points. More...
 
bool isValid () const
 Convenient method to determine if a QgsQuadrilateral is valid. More...
 
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. More...
 
QgsPointSequence points () const
 Returns a list including the vertices of the quadrilateral. More...
 
bool setPoint (const QgsPoint &newPoint, Point index)
 Sets the point newPoint at the index. More...
 
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: 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)
 Construct a QgsQuadrilateral as a rectangle from a QgsRectangle. More...
 
static QgsQuadrilateral rectangleFrom3Points (const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, ConstructionOption mode)
 Construct a QgsQuadrilateral as a Rectangle from 3 points. More...
 
static QgsQuadrilateral rectangleFromCenterPoint (const QgsPoint &center, const QgsPoint &point)
 Construct a QgsQuadrilateral as a rectangle from center point center and another point point. More...
 
static QgsQuadrilateral rectangleFromExtent (const QgsPoint &p1, const QgsPoint &p2)
 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)
 Construct a QgsQuadrilateral as a square from a diagonal. More...
 

Static Public Attributes

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

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 35 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 
Projected 

Definition at line 65 of file qgsquadrilateral.h.

◆ Point

Simple enumeration to ensure indices in setPoint.

Enumerator
Point1 
Point2 
Point3 
Point4 

Definition at line 148 of file qgsquadrilateral.h.

Constructor & Destructor Documentation

◆ QgsQuadrilateral() [1/3]

QgsQuadrilateral::QgsQuadrilateral ( )
default

◆ 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 416 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 229 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 202 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 313 of file qgsquadrilateral.cpp.

◆ operator!=()

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

Definition at line 250 of file qgsquadrilateral.cpp.

◆ operator==()

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

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

◆ points()

QgsPointSequence QgsQuadrilateral::points ( ) const

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
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 is taken from center point.

Parameters
centercenter point
pointcorner 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
p1first point
p2second 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.

See also
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
p1first point
p2second 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.

Member Data Documentation

◆ rectangleFromDiagonal

constexpr auto& QgsQuadrilateral::rectangleFromDiagonal = rectangleFromExtent
static

Alias for rectangleFromDiagonal.

Definition at line 100 of file qgsquadrilateral.h.


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