QGIS API Documentation 3.39.0-Master (734b709c2f9)
Searching...
No Matches
QgsBox3D Class Reference

A 3-dimensional box composed of x, y, z coordinates. More...

#include <qgsbox3d.h>

## Public Member Functions

QgsBox3D (const QgsPoint &p1, const QgsPoint &p2, bool normalize=true)
Constructs a QgsBox3D from two points representing opposite corners of the box.

QgsBox3D (const QgsRectangle &rect, double zMin=std::numeric_limits< double >::quiet_NaN(), double zMax=std::numeric_limits< double >::quiet_NaN(), bool normalize=true)
Constructs a QgsBox3D from a rectangle.

QgsBox3D (double xmin=std::numeric_limits< double >::quiet_NaN(), double ymin=std::numeric_limits< double >::quiet_NaN(), double zmin=std::numeric_limits< double >::quiet_NaN(), double xmax=std::numeric_limits< double >::quiet_NaN(), double ymax=std::numeric_limits< double >::quiet_NaN(), double zmax=std::numeric_limits< double >::quiet_NaN(), bool normalize=true)
Constructor for QgsBox3D which accepts the ranges of x/y/z coordinates.

double area () const
Returns the area of the box.

QgsVector3D center () const
Returns the center of the box as a vector.

void combineWith (const QgsBox3D &box)
Expands the bbox so that it covers both the original rectangle and the given rectangle.

void combineWith (double x, double y, double z)
Expands the bbox so that it covers both the original rectangle and the given point.

bool contains (const QgsBox3D &other) const
Returns true when box contains other box.

bool contains (const QgsPoint &point) const
Returns true when box contains a point.

bool contains (double x, double y, double z) const
Returns true when box contains a point (x, y, z).

QVector< QgsVector3Dcorners () const
Returns an array of all box corners as 3D vectors.

double depth () const
Returns the depth of the box.

double distanceTo (const QVector3D &point) const
Returns the smallest distance between the box and the point point (returns 0 if the point is inside the box)

double height () const
Returns the height of the box.

QgsBox3D intersect (const QgsBox3D &other) const
Returns the intersection of this box and another 3D box.

bool intersects (const QgsBox3D &other) const
Returns true if box intersects with another box.

bool is2d () const
Returns true if the box can be considered a 2-dimensional box, i.e.

bool is3D () const
Returns true if the box can be considered a 3-dimensional box, i.e.

bool isEmpty () const
Returns true if the box is empty.

bool isNull () const
Test if the box is null (holding no spatial information).

void normalize ()
Normalize the box so it has non-negative width/height/depth.

QgsBox3D operator+ (const QgsVector3D &v) const
Returns a box offset from this one in the direction of the vector.

QgsBox3Doperator+= (const QgsVector3D &v)
Moves this box in the direction of the vector.

QgsBox3D operator- (const QgsVector3D &v) const
Returns a box offset from this one in the direction of the reversed vector.

QgsBox3Doperator-= (const QgsVector3D &v)
Moves this box in the direction of the reversed vector.

bool operator== (const QgsBox3D &other) const

void scale (double scaleFactor, const QgsPoint &center=QgsPoint())
Scale the rectangle around a center QgsPoint.

void scale (double scaleFactor, double centerX, double centerY, double centerZ)
Scale the rectangle around a center coordinates.

void set (double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, bool normalize=true)
Sets the box from a set of (x,y,z) minimum and maximum coordinates.

void setNull ()
Mark a box as being null (holding no spatial information).

void setXMaximum (double x)
Sets the maximum x value.

void setXMinimum (double x)
Sets the minimum x value.

void setYMaximum (double y)
Sets the maximum y value.

void setYMinimum (double y)
Sets the minimum y value.

void setZMaximum (double z)
Sets the maximum z value.

void setZMinimum (double z)
Sets the minimum z value.

QgsRectangle toRectangle () const
Converts the box to a 2D rectangle.

QString toString (int precision=16) const
Returns a string representation of form xmin,ymin,zmin : xmax,ymax,zmax Coordinates will be truncated to the specified precision.

double volume () const
Returns the volume of the box.

double width () const
Returns the width of the box.

double xMaximum () const
Returns the maximum x value.

double xMinimum () const
Returns the minimum x value.

double yMaximum () const
Returns the maximum y value.

double yMinimum () const
Returns the minimum y value.

double zMaximum () const
Returns the maximum z value.

double zMinimum () const
Returns the minimum z value.

## Detailed Description

A 3-dimensional box composed of x, y, z coordinates.

A box composed of x/y/z minimum and maximum values. It is often used to return the 3D extent of a geometry or collection of geometries.

Note
In QGIS 3.34 this class was renamed from QgsBox3d to QgsBox3D. The old QgsBox3d name remains available in PyQGIS for compatibility.
QgsRectangle

Definition at line 42 of file qgsbox3d.h.

## ◆ QgsBox3D() [1/3]

 QgsBox3D::QgsBox3D ( double xmin = std::numeric_limits::quiet_NaN(), double ymin = std::numeric_limits::quiet_NaN(), double zmin = std::numeric_limits::quiet_NaN(), double xmax = std::numeric_limits::quiet_NaN(), double ymax = std::numeric_limits::quiet_NaN(), double zmax = std::numeric_limits::quiet_NaN(), bool normalize = true )

Constructor for QgsBox3D which accepts the ranges of x/y/z coordinates.

If normalize is false then the normalization step will not be applied automatically.

Definition at line 23 of file qgsbox3d.cpp.

## ◆ QgsBox3D() [2/3]

 QgsBox3D::QgsBox3D ( const QgsPoint & p1, const QgsPoint & p2, bool normalize = true )

Constructs a QgsBox3D from two points representing opposite corners of the box.

The box is normalized after construction. If normalize is false then the normalization step will not be applied automatically.

Definition at line 34 of file qgsbox3d.cpp.

## ◆ QgsBox3D() [3/3]

 QgsBox3D::QgsBox3D ( const QgsRectangle & rect, double zMin = std::numeric_limits::quiet_NaN(), double zMax = std::numeric_limits::quiet_NaN(), bool normalize = true )

Constructs a QgsBox3D from a rectangle.

If normalize is false then the normalization step will not be applied automatically.

Definition at line 45 of file qgsbox3d.cpp.

## ◆ area()

 double QgsBox3D::area ( ) const
inline

Returns the area of the box.

Since
QGIS 3.40

Definition at line 288 of file qgsbox3d.h.

## ◆ center()

 QgsVector3D QgsBox3D::center ( ) const

Returns the center of the box as a vector.

Since
QGIS 3.34

Definition at line 106 of file qgsbox3d.cpp.

## ◆ combineWith() [1/2]

 void QgsBox3D::combineWith ( const QgsBox3D & box )

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

Since
QGIS 3.34

Definition at line 196 of file qgsbox3d.cpp.

## ◆ combineWith() [2/2]

 void QgsBox3D::combineWith ( double x, double y, double z )

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

Since
QGIS 3.34

Definition at line 218 of file qgsbox3d.cpp.

## ◆ contains() [1/3]

 bool QgsBox3D::contains ( const QgsBox3D & other ) const

Returns true when box contains other box.

Definition at line 149 of file qgsbox3d.cpp.

## ◆ contains() [2/3]

 bool QgsBox3D::contains ( const QgsPoint & point ) const

Returns true when box contains a point.

If the point is a 2D point (no z-coordinate), then the containment test will be performed on the x/y extent of the box only.

Definition at line 164 of file qgsbox3d.cpp.

## ◆ contains() [3/3]

 bool QgsBox3D::contains ( double x, double y, double z ) const

Returns true when box contains a point (x, y, z).

A point on the border of the box will also return true

If the point is a 2D point (no z-coordinate), then the containment test will be performed on the x/y extent of the box only.

Since
QGIS 3.34

Definition at line 176 of file qgsbox3d.cpp.

## ◆ corners()

 QVector< QgsVector3D > QgsBox3D::corners ( ) const

Returns an array of all box corners as 3D vectors.

Definition at line 338 of file qgsbox3d.cpp.

## ◆ depth()

 double QgsBox3D::depth ( ) const
inline

Returns the depth of the box.

width()
height()

Definition at line 274 of file qgsbox3d.h.

## ◆ distanceTo()

 double QgsBox3D::distanceTo ( const QVector3D & point ) const

Returns the smallest distance between the box and the point point (returns 0 if the point is inside the box)

Since
QGIS 3.18

Definition at line 236 of file qgsbox3d.cpp.

## ◆ height()

 double QgsBox3D::height ( ) const
inline

Returns the height of the box.

width()
depth()

Definition at line 267 of file qgsbox3d.h.

## ◆ intersect()

 QgsBox3D QgsBox3D::intersect ( const QgsBox3D & other ) const

Returns the intersection of this box and another 3D box.

Definition at line 113 of file qgsbox3d.cpp.

## ◆ intersects()

 bool QgsBox3D::intersects ( const QgsBox3D & other ) const

Returns true if box intersects with another box.

Definition at line 132 of file qgsbox3d.cpp.

## ◆ is2d()

 bool QgsBox3D::is2d ( ) const

Returns true if the box can be considered a 2-dimensional box, i.e.

it has equal minimum and maximum z values.

Definition at line 122 of file qgsbox3d.cpp.

## ◆ is3D()

 bool QgsBox3D::is3D ( ) const

Returns true if the box can be considered a 3-dimensional box, i.e.

it has valid minimum and maximum z values. If the box is not normalized, this returns false.

Since
QGIS 3.34

Definition at line 127 of file qgsbox3d.cpp.

## ◆ isEmpty()

 bool QgsBox3D::isEmpty ( ) const

Returns true if the box is empty.

An empty box may still be non-null if it contains valid spatial information (e.g. bounding box of a point or of a vertical or horizontal segment).

Since
QGIS 3.34

Definition at line 299 of file qgsbox3d.cpp.

## ◆ isNull()

 bool QgsBox3D::isNull ( ) const

Test if the box is null (holding no spatial information).

A null box is also an empty box.

setNull()
Since
QGIS 3.34

Definition at line 289 of file qgsbox3d.cpp.

## ◆ normalize()

 void QgsBox3D::normalize ( )

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

Definition at line 97 of file qgsbox3d.cpp.

## ◆ operator+()

 QgsBox3D QgsBox3D::operator+ ( const QgsVector3D & v ) const

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

Since
QGIS 3.34

Definition at line 360 of file qgsbox3d.cpp.

## ◆ operator+=()

 QgsBox3D & QgsBox3D::operator+= ( const QgsVector3D & v )

Moves this box in the direction of the vector.

Since
QGIS 3.34

Definition at line 375 of file qgsbox3d.cpp.

## ◆ operator-()

 QgsBox3D QgsBox3D::operator- ( const QgsVector3D & v ) const

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

Since
QGIS 3.34

Definition at line 354 of file qgsbox3d.cpp.

## ◆ operator-=()

 QgsBox3D & QgsBox3D::operator-= ( const QgsVector3D & v )

Moves this box in the direction of the reversed vector.

Since
QGIS 3.34

Definition at line 366 of file qgsbox3d.cpp.

## ◆ operator==()

 bool QgsBox3D::operator== ( const QgsBox3D & other ) const

Definition at line 251 of file qgsbox3d.cpp.

## ◆ scale() [1/2]

 void QgsBox3D::scale ( double scaleFactor, const QgsPoint & center = QgsPoint() )

Scale the rectangle around a center QgsPoint.

If no center point is specified then the current center of the box will be used.

Since
QGIS 3.26

Definition at line 258 of file qgsbox3d.cpp.

## ◆ scale() [2/2]

 void QgsBox3D::scale ( double scaleFactor, double centerX, double centerY, double centerZ )

Scale the rectangle around a center coordinates.

Since
QGIS 3.26

Definition at line 277 of file qgsbox3d.cpp.

## ◆ set()

 void QgsBox3D::set ( double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, bool normalize = true )
inline

Sets the box from a set of (x,y,z) minimum and maximum coordinates.

Since
QGIS 3.40

Definition at line 148 of file qgsbox3d.h.

## ◆ setNull()

 void QgsBox3D::setNull ( )

Mark a box as being null (holding no spatial information).

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

Since
QGIS 3.34

It is NOT normalized.

Definition at line 90 of file qgsbox3d.cpp.

## ◆ setXMaximum()

 void QgsBox3D::setXMaximum ( double x )

Sets the maximum x value.

xMaximum()
setXMinimum()

Definition at line 61 of file qgsbox3d.cpp.

## ◆ setXMinimum()

 void QgsBox3D::setXMinimum ( double x )

Sets the minimum x value.

xMinimum()
setXMaximum()

Definition at line 56 of file qgsbox3d.cpp.

## ◆ setYMaximum()

 void QgsBox3D::setYMaximum ( double y )

Sets the maximum y value.

yMaximum()
setYMinimum()

Definition at line 71 of file qgsbox3d.cpp.

## ◆ setYMinimum()

 void QgsBox3D::setYMinimum ( double y )

Sets the minimum y value.

yMinimum()
setYMaximum()

Definition at line 66 of file qgsbox3d.cpp.

## ◆ setZMaximum()

 void QgsBox3D::setZMaximum ( double z )

Sets the maximum z value.

zMaximum()
setZMinimum()

Definition at line 81 of file qgsbox3d.cpp.

## ◆ setZMinimum()

 void QgsBox3D::setZMinimum ( double z )

Sets the minimum z value.

zMinimum()
setZMaximum()

Definition at line 76 of file qgsbox3d.cpp.

## ◆ toRectangle()

 QgsRectangle QgsBox3D::toRectangle ( ) const
inline

Converts the box to a 2D rectangle.

Definition at line 361 of file qgsbox3d.h.

## ◆ toString()

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

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

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

Since
QGIS 3.34

Definition at line 304 of file qgsbox3d.cpp.

## ◆ volume()

 double QgsBox3D::volume ( ) const
inline

Returns the volume of the box.

Definition at line 293 of file qgsbox3d.h.

## ◆ width()

 double QgsBox3D::width ( ) const
inline

Returns the width of the box.

height()
depth()

Definition at line 260 of file qgsbox3d.h.

## ◆ xMaximum()

 double QgsBox3D::xMaximum ( ) const
inline

Returns the maximum x value.

setXMaximum()
xMinimum()

Definition at line 185 of file qgsbox3d.h.

## ◆ xMinimum()

 double QgsBox3D::xMinimum ( ) const
inline

Returns the minimum x value.

setXMinimum()
xMaximum()

Definition at line 178 of file qgsbox3d.h.

## ◆ yMaximum()

 double QgsBox3D::yMaximum ( ) const
inline

Returns the maximum y value.

setYMaximum()
yMinimum()

Definition at line 213 of file qgsbox3d.h.

## ◆ yMinimum()

 double QgsBox3D::yMinimum ( ) const
inline

Returns the minimum y value.

setYMinimum()
yMaximum()

Definition at line 206 of file qgsbox3d.h.

## ◆ zMaximum()

 double QgsBox3D::zMaximum ( ) const
inline

Returns the maximum z value.

setZMaximum()
zMinimum()

Definition at line 241 of file qgsbox3d.h.

## ◆ zMinimum()

 double QgsBox3D::zMinimum ( ) const
inline

Returns the minimum z value.