mapteksdk.data.primitives.cell_properties module

Support for cell primitives.

Cell primitives are quadrilaterals defined by four points. In Python, a cell is represented as a numpy array containing four integers representing the indices of the points used to define the corners of the cell. For example, the cell [0, 1, 2, 3] indicates the quadrilateral with the 0th, 1st, 2nd and 3rd point as the four corners. Because cells are defined based on points, all objects which inherit from CellProperties must also inherit from PointProperties.

class CellProperties

Bases: object

Mixin class which provides spatial objects support for cell primitives.

Functions and properties defined on this class are available on all classes which support cells. Inheriting classes may impose restrictions on the quadrilaterals which can be included in that object.

is_read_only: bool
property major_dimension_count: int

The major dimension count of the Cell Network.

If the inheriting object is stored in row major order, then this will correspond to the row count. If stored in column major order then this will correspond to the column count.

property minor_dimension_count: int

The major dimension count of the Cell Network.

If the inheriting object is stored in row major order, then this will correspond to the column count. If stored in column major order then this will correspond to the row count.

property cells: CellArray

This property maps the cells to the points which define them.

Use this to refer to the points which define the four corners of a cell.

This is a numpy array of shape (n, 4) where n is the cell count. If cells[i] is [a, b, c, d] then the four corner points of the ith cell are points[a], points[b], points[c] and points[d].

Notes

Sparse cell objects (such as Scans) may contain cells with point indices of -1. These represent invalid points. In the future, this may be changed to be a masked array instead.

Examples

This example creates a GridSurface object with 3 rows and 3 columns of points and prints the cells. Then it prints the four points which define the first cell (index 0).

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import GridSurface
>>> project = Project()
>>> with project.new("surfaces/small_square", GridSurface(
...         major_dimension_count=3, minor_dimension_count=3,
...         x_step=0.1, y_step=0.1)) as small_square:
...     print("Cells:")
...     print(small_square.cells)
...     print("The points which define the first cell are:")
...     for index in small_square.cells[0]:
...         print(f"Point {index}:", small_square.points[index])
Cells:
[[0 3 4 1]
 [1 4 5 2]
 [3 6 7 4]
 [4 7 8 5]]
The points which define the first cell are:
Point 0: [0. 0. 0.]
Point 3: [0.3 0.  0. ]
Point 4: [0.  0.1 0. ]
Point 1: [0.1 0.  0. ]
property cell_count: int

The number of cells in the cell network.

By default this is equal to the (major_dimension_count - 1) x (minor_dimension_count - 1), however subclasses may override this function to return different values.

property cell_visibility: BooleanArray

The visibility of the cells as a flat array.

This array will contain cell_count booleans - one for each cell. True indicates the cell is visible and False indicates the cell is invisible.

property cell_selection: BooleanArray

The selection of the cells as a flat array.

This array will contain cell_count booleans - one for each cell. True indicates the cell is selected and False indicates the cell is not selected.

property cell_point_count: int

The number of points in the cell network, including invalid points.

The point_count of a cell network only counts the valid points. However, sparse cell networks (such as Scans) may also contain invalid points for which point properties are not stored. This is equal to: major_dimension_count * minor_dimension_count.

If the object contains invalid points, then cell_point_count > point_count.

See also

mapteksdk.data.primitives.PointProperties.point_count

The count of valid points in the object.

property cell_attributes: PrimitiveAttributes

Access custom cell attributes.

These are arrays of values of the same type, with one value for each cell.

Use Object.cell_attributes[attribute_name] to access a cell attribute called attribute_name. See PrimitiveAttributes for valid operations on cell attributes.

Returns:

Access to the cell attributes.

Return type:

PrimitiveAttributes

Raises:

ValueError – If the type of the attribute is not supported.

save_cell_attribute(attribute_name, data)

Create and/or edit the values of the cell attribute attribute_name.

This is equivalent to Object.cell_attributes[attribute_name] = data.

Saving a cell attribute using an AttributeKey allows for additional metadata to be specified.

Parameters:
  • attribute_name (str | AttributeKey) – The name or key of the attribute.

  • data (array_like) – An array_like of length cell_count containing the values for attribute_name.

Raises:
  • ValueError – If the type of the attribute is not supported.

  • AmbiguousNameError – If there is already an attribute with the same name, but with different metadata.

delete_cell_attribute(attribute_name)

Delete a cell attribute.

This is equivalent to: cell_attributes.delete_attribute(attribute_name)

Parameters:

attribute_name (str | AttributeKey) – The name or key of the attribute.