QGIS API Documentation  3.4.15-Madeira (e83d02e274)
Public Member Functions | Static Public Member Functions | List of all members
QgsRectangle Class Reference

A rectangle specified with double values. More...

#include <qgsrectangle.h>

Inheritance diagram for QgsRectangle:
Inheritance graph
[legend]

Public Member Functions

 QgsRectangle ()=default
 Constructor for a null rectangle. More...
 
 QgsRectangle (double xMin, double yMin=0, double xMax=0, double yMax=0)
 Constructor. More...
 
 QgsRectangle (const QgsPointXY &p1, const QgsPointXY &p2)
 Construct a rectangle from two points. The rectangle is normalized after construction. More...
 
 QgsRectangle (const QRectF &qRectF)
 Construct a rectangle from a QRectF. The rectangle is normalized after construction. More...
 
 QgsRectangle (const QgsRectangle &other)
 Copy constructor. More...
 
 ~QgsRectangle ()=default
 
double area () const
 Returns the area of the rectangle. More...
 
QString asPolygon () const
 Returns the rectangle as a polygon. More...
 
QString asWktCoordinates () const
 Returns a string representation of the rectangle in WKT format. More...
 
QString asWktPolygon () const
 Returns a string representation of the rectangle as a WKT Polygon. More...
 
QgsRectangle buffered (double width) const
 Gets rectangle enlarged by buffer. More...
 
QgsPointXY center () const
 Returns the center point of the rectangle. More...
 
void combineExtentWith (const QgsRectangle &rect)
 Expands the rectangle so that it covers both the original rectangle and the given rectangle. More...
 
void combineExtentWith (double x, double y)
 Expands the rectangle so that it covers both the original rectangle and the given point. More...
 
void combineExtentWith (const QgsPointXY &point)
 Expands the rectangle so that it covers both the original rectangle and the given point. More...
 
bool contains (const QgsRectangle &rect) const
 Returns true when rectangle contains other rectangle. More...
 
bool contains (const QgsPointXY &p) const
 Returns true when rectangle contains a point. More...
 
void grow (double delta)
 Grows the rectangle in place by the specified amount. More...
 
double height () const
 Returns the height of the rectangle. More...
 
void include (const QgsPointXY &p)
 Updates the rectangle to include the specified point. More...
 
QgsRectangle intersect (const QgsRectangle &rect) const
 Returns the intersection with the given rectangle. More...
 
bool intersects (const QgsRectangle &rect) const
 Returns true when rectangle intersects with other rectangle. More...
 
void invert ()
 Swap x/y coordinates in the rectangle. More...
 
bool isEmpty () const
 Returns true if the rectangle is empty. More...
 
bool isFinite () const
 Returns true if the rectangle has finite boundaries. More...
 
bool isNull () const
 Test if the rectangle is null (all coordinates zero or after call to setMinimal()). More...
 
void normalize ()
 Normalize the rectangle so it has non-negative width/height. More...
 
 operator QVariant () const
 Allows direct construction of QVariants from rectangles. More...
 
bool operator!= (const QgsRectangle &r1) const
 Comparison operator. More...
 
QgsRectangle operator+ (QgsVector v) const
 Returns a rectangle offset from this one in the direction of the vector. More...
 
QgsRectangleoperator+= (QgsVector v)
 Moves this rectangle in the direction of the vector. More...
 
QgsRectangle operator- (QgsVector v) const
 Returns a rectangle offset from this one in the direction of the reversed vector. More...
 
QgsRectangleoperator-= (QgsVector v)
 Moves this rectangle in the direction of the reversed vector. More...
 
QgsRectangleoperator= (const QgsRectangle &r1)
 Assignment operator. More...
 
bool operator== (const QgsRectangle &r1) const
 Comparison operator. More...
 
double perimeter () const
 Returns the perimeter of the rectangle. More...
 
void scale (double scaleFactor, const QgsPointXY *c=nullptr)
 Scale the rectangle around its center point. More...
 
void scale (double scaleFactor, double centerX, double centerY)
 Scale the rectangle around its center point. More...
 
QgsRectangle scaled (double scaleFactor, const QgsPointXY *center=nullptr) const
 Scale the rectangle around its center point. More...
 
void set (const QgsPointXY &p1, const QgsPointXY &p2)
 Sets the rectangle from two QgsPoints. More...
 
void set (double xMin, double yMin, double xMax, double yMax)
 Sets the rectangle from four points. More...
 
void setMinimal ()
 Set a rectangle so that min corner is at max and max corner is at min. More...
 
void setXMaximum (double x)
 Set the maximum x value. More...
 
void setXMinimum (double x)
 Set the minimum x value. More...
 
void setYMaximum (double y)
 Set the maximum y value. More...
 
void setYMinimum (double y)
 Set the minimum y value. More...
 
QgsRectangle snappedToGrid (double spacing) const
 Returns a copy of this rectangle that is snapped to a grid with the specified spacing between the grid lines. More...
 
QgsBox3d toBox3d (double zMin, double zMax) const
 Converts the rectangle to a 3D box, with the specified zMin and zMax z values. More...
 
QRectF toRectF () const
 Returns a QRectF with same coordinates as the rectangle. More...
 
QString toString (int precision=16) const
 Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the specified precision. More...
 
double width () const
 Returns the width of the rectangle. More...
 
double xMaximum () const
 Returns the x maximum value (right side of rectangle). More...
 
double xMinimum () const
 Returns the x minimum value (left side of rectangle). More...
 
double yMaximum () const
 Returns the y maximum value (top side of rectangle). More...
 
double yMinimum () const
 Returns the y minimum value (bottom side of rectangle). More...
 

Static Public Member Functions

static QgsRectangle fromCenterAndSize (QgsPointXY center, double width, double height)
 Creates a new rectangle, given the specified center point and width and height. More...
 
static QgsRectangle fromWkt (const QString &wkt)
 Creates a new rectangle from a wkt string. More...
 

Detailed Description

A rectangle specified with double values.

QgsRectangle is used to store a rectangle when double values are required. Examples are storing a layer extent or the current view extent of a map

See also
QgsBox3d

Definition at line 40 of file qgsrectangle.h.

Constructor & Destructor Documentation

QgsRectangle::QgsRectangle ( )
default

Constructor for a null rectangle.

QgsRectangle::QgsRectangle ( double  xMin,
double  yMin = 0,
double  xMax = 0,
double  yMax = 0 
)
inlineexplicit

Constructor.

Definition at line 48 of file qgsrectangle.h.

QgsRectangle::QgsRectangle ( const QgsPointXY p1,
const QgsPointXY p2 
)
inline

Construct a rectangle from two points. The rectangle is normalized after construction.

Definition at line 58 of file qgsrectangle.h.

QgsRectangle::QgsRectangle ( const QRectF &  qRectF)
inline

Construct a rectangle from a QRectF. The rectangle is normalized after construction.

Definition at line 64 of file qgsrectangle.h.

QgsRectangle::QgsRectangle ( const QgsRectangle other)
inline

Copy constructor.

Definition at line 73 of file qgsrectangle.h.

QgsRectangle::~QgsRectangle ( )
default

Member Function Documentation

double QgsRectangle::area ( ) const
inline

Returns the area of the rectangle.

See also
width()
height()
perimeter()
Since
QGIS 3.0

Definition at line 217 of file qgsrectangle.h.

QString QgsRectangle::asPolygon ( ) const

Returns the rectangle as a polygon.

Definition at line 157 of file qgsrectangle.cpp.

QString QgsRectangle::asWktCoordinates ( ) const

Returns a string representation of the rectangle in WKT format.

Definition at line 104 of file qgsrectangle.cpp.

QString QgsRectangle::asWktPolygon ( ) const

Returns a string representation of the rectangle as a WKT Polygon.

Definition at line 113 of file qgsrectangle.cpp.

QgsRectangle QgsRectangle::buffered ( double  width) const
inline

Gets rectangle enlarged by buffer.

Note
In earlier QGIS releases this method was named buffer().
See also
grow()
Since
QGIS 3.0

Definition at line 303 of file qgsrectangle.h.

QgsPointXY QgsRectangle::center ( ) const
inline

Returns the center point of the rectangle.

Definition at line 229 of file qgsrectangle.h.

void QgsRectangle::combineExtentWith ( const QgsRectangle rect)
inline

Expands the rectangle so that it covers both the original rectangle and the given rectangle.

Definition at line 358 of file qgsrectangle.h.

void QgsRectangle::combineExtentWith ( double  x,
double  y 
)
inline

Expands the rectangle so that it covers both the original rectangle and the given point.

Definition at line 374 of file qgsrectangle.h.

void QgsRectangle::combineExtentWith ( const QgsPointXY point)
inline

Expands the rectangle so that it covers both the original rectangle and the given point.

Since
QGIS 3.2

Definition at line 392 of file qgsrectangle.h.

bool QgsRectangle::contains ( const QgsRectangle rect) const
inline

Returns true when rectangle contains other rectangle.

Definition at line 341 of file qgsrectangle.h.

bool QgsRectangle::contains ( const QgsPointXY p) const
inline

Returns true when rectangle contains a point.

Definition at line 349 of file qgsrectangle.h.

QgsRectangle QgsRectangle::fromCenterAndSize ( QgsPointXY  center,
double  width,
double  height 
)
static

Creates a new rectangle, given the specified center point and width and height.

Since
QGIS 3.0

Definition at line 52 of file qgsrectangle.cpp.

QgsRectangle QgsRectangle::fromWkt ( const QString &  wkt)
static

Creates a new rectangle from a wkt string.

The WKT must contain only 5 vertices, representing a rectangle aligned with X and Y axes.

Since
QGIS 3.0

Definition at line 34 of file qgsrectangle.cpp.

void QgsRectangle::grow ( double  delta)
inline

Grows the rectangle in place by the specified amount.

See also
buffered()

Definition at line 274 of file qgsrectangle.h.

double QgsRectangle::height ( ) const
inline

Returns the height of the rectangle.

See also
width()
area()

Definition at line 208 of file qgsrectangle.h.

void QgsRectangle::include ( const QgsPointXY p)
inline

Updates the rectangle to include the specified point.

Definition at line 285 of file qgsrectangle.h.

QgsRectangle QgsRectangle::intersect ( const QgsRectangle rect) const
inline

Returns the intersection with the given rectangle.

Definition at line 311 of file qgsrectangle.h.

bool QgsRectangle::intersects ( const QgsRectangle rect) const
inline

Returns true when rectangle intersects with other rectangle.

Definition at line 327 of file qgsrectangle.h.

void QgsRectangle::invert ( )
inline

Swap x/y coordinates in the rectangle.

Definition at line 531 of file qgsrectangle.h.

bool QgsRectangle::isEmpty ( ) const
inline

Returns true if the rectangle is empty.

An empty rectangle may still be non-null if it contains valid information (e.g. bounding box of a point).

Definition at line 425 of file qgsrectangle.h.

bool QgsRectangle::isFinite ( ) const
inline

Returns true if the rectangle has finite boundaries.

Will return false if any of the rectangle boundaries are NaN or Inf.

Definition at line 515 of file qgsrectangle.h.

bool QgsRectangle::isNull ( ) const
inline

Test if the rectangle is null (all coordinates zero or after call to setMinimal()).

A null rectangle is also an empty rectangle.

Since
QGIS 2.4

Definition at line 435 of file qgsrectangle.h.

void QgsRectangle::normalize ( )
inline

Normalize the rectangle so it has non-negative width/height.

Definition at line 181 of file qgsrectangle.h.

QgsRectangle::operator QVariant ( ) const
inline

Allows direct construction of QVariants from rectangles.

Definition at line 545 of file qgsrectangle.h.

bool QgsRectangle::operator!= ( const QgsRectangle r1) const
inline

Comparison operator.

Returns
False if rectangles are equal

Definition at line 489 of file qgsrectangle.h.

QgsRectangle QgsRectangle::operator+ ( QgsVector  v) const

Returns a rectangle offset from this one in the direction of the vector.

Since
QGIS 3.0

Definition at line 77 of file qgsrectangle.cpp.

QgsRectangle & QgsRectangle::operator+= ( QgsVector  v)

Moves this rectangle in the direction of the vector.

Since
QGIS 3.0

Definition at line 95 of file qgsrectangle.cpp.

QgsRectangle QgsRectangle::operator- ( QgsVector  v) const

Returns a rectangle offset from this one in the direction of the reversed vector.

Since
QGIS 3.0

Definition at line 68 of file qgsrectangle.cpp.

QgsRectangle & QgsRectangle::operator-= ( QgsVector  v)

Moves this rectangle in the direction of the reversed vector.

Since
QGIS 3.0

Definition at line 86 of file qgsrectangle.cpp.

QgsRectangle& QgsRectangle::operator= ( const QgsRectangle r1)
inline

Assignment operator.

Parameters
r1QgsRectangle to assign from

Definition at line 498 of file qgsrectangle.h.

bool QgsRectangle::operator== ( const QgsRectangle r1) const
inline

Comparison operator.

Returns
True if rectangles are equal

Definition at line 477 of file qgsrectangle.h.

double QgsRectangle::perimeter ( ) const
inline

Returns the perimeter of the rectangle.

See also
area()
Since
QGIS 3.0

Definition at line 224 of file qgsrectangle.h.

void QgsRectangle::scale ( double  scaleFactor,
const QgsPointXY c = nullptr 
)
inline

Scale the rectangle around its center point.

Definition at line 234 of file qgsrectangle.h.

void QgsRectangle::scale ( double  scaleFactor,
double  centerX,
double  centerY 
)
inline

Scale the rectangle around its center point.

Definition at line 254 of file qgsrectangle.h.

QgsRectangle QgsRectangle::scaled ( double  scaleFactor,
const QgsPointXY center = nullptr 
) const

Scale the rectangle around its center point.

Since
QGIS 3.4

Definition at line 61 of file qgsrectangle.cpp.

void QgsRectangle::set ( const QgsPointXY p1,
const QgsPointXY p2 
)
inline

Sets the rectangle from two QgsPoints.

The rectangle is normalised after construction.

Definition at line 104 of file qgsrectangle.h.

void QgsRectangle::set ( double  xMin,
double  yMin,
double  xMax,
double  yMax 
)
inline

Sets the rectangle from four points.

The rectangle is normalised after construction.

Definition at line 117 of file qgsrectangle.h.

void QgsRectangle::setMinimal ( )
inline

Set a rectangle so that min corner is at max and max corner is at min.

It is NOT normalized.

Definition at line 150 of file qgsrectangle.h.

void QgsRectangle::setXMaximum ( double  x)
inline

Set the maximum x value.

Definition at line 134 of file qgsrectangle.h.

void QgsRectangle::setXMinimum ( double  x)
inline

Set the minimum x value.

Definition at line 129 of file qgsrectangle.h.

void QgsRectangle::setYMaximum ( double  y)
inline

Set the maximum y value.

Definition at line 144 of file qgsrectangle.h.

void QgsRectangle::setYMinimum ( double  y)
inline

Set the minimum y value.

Definition at line 139 of file qgsrectangle.h.

QgsRectangle QgsRectangle::snappedToGrid ( double  spacing) const

Returns a copy of this rectangle that is snapped to a grid with the specified spacing between the grid lines.

Since
QGIS 3.4

Definition at line 185 of file qgsrectangle.cpp.

QgsBox3d QgsRectangle::toBox3d ( double  zMin,
double  zMax 
) const

Converts the rectangle to a 3D box, with the specified zMin and zMax z values.

Since
QGIS 3.0

Definition at line 180 of file qgsrectangle.cpp.

QRectF QgsRectangle::toRectF ( ) const
inline

Returns a QRectF with same coordinates as the rectangle.

Definition at line 456 of file qgsrectangle.h.

QString QgsRectangle::toString ( int  precision = 16) const

Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the specified precision.

If the specified precision is less than 0, a suitable minimum precision is used.

Definition at line 127 of file qgsrectangle.cpp.

double QgsRectangle::width ( ) const
inline

Returns the width of the rectangle.

See also
height()
area()

Definition at line 201 of file qgsrectangle.h.

double QgsRectangle::xMaximum ( ) const
inline

Returns the x maximum value (right side of rectangle).

Definition at line 161 of file qgsrectangle.h.

double QgsRectangle::xMinimum ( ) const
inline

Returns the x minimum value (left side of rectangle).

Definition at line 166 of file qgsrectangle.h.

double QgsRectangle::yMaximum ( ) const
inline

Returns the y maximum value (top side of rectangle).

Definition at line 171 of file qgsrectangle.h.

double QgsRectangle::yMinimum ( ) const
inline

Returns the y minimum value (bottom side of rectangle).

Definition at line 176 of file qgsrectangle.h.


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