Class: QgsBox3D

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.

See also

QgsRectangle

Methods

area

Returns the area of the box.

center

Returns the center of the box as a vector.

combineWith

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

contains

Returns True when box contains other box.

corners

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

depth

Returns the depth of the box.

distanceTo

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

grow

Grows the box in place by the specified amount in all dimensions.

height

Returns the height of the box.

intersect

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

intersects

Returns True if box intersects with another box.

is2d

Returns True if the box can be considered a 2-dimensional box, i.e. it has equal minimum and maximum z values.

is3D

Returns True if the box can be considered a 3-dimensional box, i.e. it has valid minimum and maximum z values.

isEmpty

Returns True if the box is empty.

isNull

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

normalize

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

scale

Scale the rectangle around a center QgsPoint.

set

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

setNull

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

setXMaximum

Sets the maximum x value.

setXMinimum

Sets the minimum x value.

setYMaximum

Sets the maximum y value.

setYMinimum

Sets the minimum y value.

setZMaximum

Sets the maximum z value.

setZMinimum

Sets the minimum z value.

toRectangle

Converts the box to a 2D rectangle.

toString

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

volume

Returns the volume of the box.

width

Returns the width of the box.

xMaximum

Returns the maximum x value.

xMinimum

Returns the minimum x value.

yMaximum

Returns the maximum y value.

yMinimum

Returns the minimum y value.

zMaximum

Returns the maximum z value.

zMinimum

Returns the minimum z value.

class qgis.core.QgsBox3D[source]

Bases: object

__init__(x: QgsPoint | QgsVector3D | QgsRectangle | float | None = Py_None, y: QgsPoint | QgsVector3D | float | None = Py_None, z: bool | float | None = Py_None, x2: bool | float | None = Py_None, y2: float | None = Py_None, z2: float | None = Py_None, n: bool | None = Py_None)

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.

Parameters:
  • x (Optional[Union[QgsPoint, QgsVector3D, QgsRectangle, float]] = Py_None)

  • y (Optional[QgsPoint, QgsVector3D, float] = Py_None)

  • z (Optional[Union[bool, float]] = Py_None)

  • x2 (Optional[Union[bool, float]] = Py_None)

  • y2 (Optional[float] = Py_None)

  • z2 (Optional[float] = Py_None)

  • n (Optional[bool] = Py_None)

__init__(a0: QgsBox3D)
Parameters:

a0 (QgsBox3D)

area(self) float[source]

Returns the area of the box.

Added in version 3.40.

Return type:

float

center(self) QgsVector3D[source]

Returns the center of the box as a vector.

Added in version 3.34.

Return type:

QgsVector3D

combineWith(self, box: QgsBox3D)[source]

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

Added in version 3.34.

Parameters:

box (QgsBox3D)

combineWith(self, x: float, y: float, z: float)[source]

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

Added in version 3.34.

Parameters:
  • x (float)

  • y (float)

  • z (float)

contains(self, other: QgsBox3D) bool[source]

Returns True when box contains other box.

Parameters:

other (QgsBox3D)

Return type:

bool

contains(self, point: QgsPoint) bool[source]

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.

Parameters:

point (QgsPoint)

Return type:

bool

contains(self, x: float, y: float, z: float) bool[source]

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.

Added in version 3.34.

Parameters:
  • x (float)

  • y (float)

  • z (float)

Return type:

bool

corners(self) List[QgsVector3D]

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

Return type:

List[QgsVector3D]

depth(self) float[source]

Returns the depth of the box.

See also

width()

See also

height()

Return type:

float

distanceTo(self, point: QVector3D) float[source]

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

Added in version 3.18.

Deprecated since version 3.42: Use distanceTo() with QgsVector3D instead (QVector3D uses floats).

Parameters:

point (QVector3D)

Return type:

float

distanceTo(self, point: QgsVector3D) float[source]

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

Added in version 3.42.

Parameters:

point (QgsVector3D)

Return type:

float

grow(self, delta: float)[source]

Grows the box in place by the specified amount in all dimensions.

Added in version 3.42.

Parameters:

delta (float)

height(self) float[source]

Returns the height of the box.

See also

width()

See also

depth()

Return type:

float

intersect(self, other: QgsBox3D) QgsBox3D[source]

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

Parameters:

other (QgsBox3D)

Return type:

QgsBox3D

intersects(self, other: QgsBox3D) bool[source]

Returns True if box intersects with another box.

Parameters:

other (QgsBox3D)

Return type:

bool

is2d(self) bool[source]

Returns True if the box can be considered a 2-dimensional box, i.e. it has equal minimum and maximum z values.

Return type:

bool

is3D(self) bool[source]

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.

Added in version 3.34.

Return type:

bool

isEmpty(self) bool[source]

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

Added in version 3.34.

Return type:

bool

isNull(self) bool[source]

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

A null box is also an empty box.

See also

setNull()

Added in version 3.34.

Return type:

bool

normalize(self)[source]

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

scale(self, scaleFactor: float, center: QgsPoint = QgsPoint())[source]

Scale the rectangle around a center QgsPoint.

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

Added in version 3.26.

Parameters:
  • scaleFactor (float)

  • center (QgsPoint = QgsPoint())

scale(self, scaleFactor: float, centerX: float, centerY: float, centerZ: float)[source]

Scale the rectangle around a center coordinates.

Added in version 3.26.

Parameters:
  • scaleFactor (float)

  • centerX (float)

  • centerY (float)

  • centerZ (float)

set(self, xMin: float, yMin: float, zMin: float, xMax: float, yMax: float, zMax: float, normalize: bool = True)[source]

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

Added in version 3.40.

Parameters:
  • xMin (float)

  • yMin (float)

  • zMin (float)

  • xMax (float)

  • yMax (float)

  • zMax (float)

  • normalize (bool = True)

setNull(self)[source]

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

Added in version 3.34.

setXMaximum(self, x: float)[source]

Sets the maximum x value.

See also

xMaximum()

See also

setXMinimum()

Parameters:

x (float)

setXMinimum(self, x: float)[source]

Sets the minimum x value.

See also

xMinimum()

See also

setXMaximum()

Parameters:

x (float)

setYMaximum(self, y: float)[source]

Sets the maximum y value.

See also

yMaximum()

See also

setYMinimum()

Parameters:

y (float)

setYMinimum(self, y: float)[source]

Sets the minimum y value.

See also

yMinimum()

See also

setYMaximum()

Parameters:

y (float)

setZMaximum(self, z: float)[source]

Sets the maximum z value.

See also

zMaximum()

See also

setZMinimum()

Parameters:

z (float)

setZMinimum(self, z: float)[source]

Sets the minimum z value.

See also

zMinimum()

See also

setZMaximum()

Parameters:

z (float)

toRectangle(self) QgsRectangle[source]

Converts the box to a 2D rectangle.

Return type:

QgsRectangle

toString(self, precision: int = 16) str[source]

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.

Added in version 3.34.

Parameters:

precision (int = 16)

Return type:

str

volume(self) float[source]

Returns the volume of the box.

Return type:

float

width(self) float[source]

Returns the width of the box.

See also

height()

See also

depth()

Return type:

float

xMaximum(self) float[source]

Returns the maximum x value.

See also

setXMaximum()

See also

xMinimum()

Return type:

float

xMinimum(self) float[source]

Returns the minimum x value.

See also

setXMinimum()

See also

xMaximum()

Return type:

float

yMaximum(self) float[source]

Returns the maximum y value.

See also

setYMaximum()

See also

yMinimum()

Return type:

float

yMinimum(self) float[source]

Returns the minimum y value.

See also

setYMinimum()

See also

yMaximum()

Return type:

float

zMaximum(self) float[source]

Returns the maximum z value.

See also

setZMaximum()

See also

zMinimum()

Return type:

float

zMinimum(self) float[source]

Returns the minimum z value.

See also

setZMinimum()

See also

zMaximum()

Return type:

float