mapteksdk.data.blocks module

Block model data types.

Block models are objects constructed entirely from block primitives. There are different kinds of block models, however only DenseBlockModels and SubblockedBlockModels are currently supported.

exception InvalidBlockCentroidError

Bases: ValueError

Error raised for block centroids which lie outside of the block model.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception InvalidBlockSizeError

Bases: ValueError

Error raised for invalid block sizes.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class DenseBlockModel(object_id=None, lock_type=LockType.READWRITE, x_res=None, y_res=None, z_res=None, x_count=None, y_count=None, z_count=None)

Bases: mapteksdk.data.base.Topology, mapteksdk.data.primitives.block_properties.BlockProperties, mapteksdk.data.rotation.RotationMixin

A dense block model consists of blocks which are the same size arranged in a three dimensional grid structure. The block model is dense because it does not allow ‘holes’ in the model - every region in the grid must contain a block.

For example, a dense block model with an x_res of 1, a y_res of 2 and a z_res of 3 means all of the blocks in the model are 1 by 2 by 3 units in size. If the dense block model’s x_count was 10, the y_count was 15 and the z_count was 5 then the model would consist of 10 * 15 * 5 = 750 blocks each of which was 1x2x3 units. These blocks would be arranged in a grid with 10 rows, 15 columns and 5 slices with no gaps.

The blocks of a dense block model are defined at creation and cannot be changed.

Parameters
  • x_res (float) – The x resolution. Must be greater than zero.

  • y_res (float) – The y resolution. Must be greater than zero.

  • z_res (float) – The z resolution. Must be greater than zero.

  • x_count (int) – The number of columns in the block model. Must be greater than zero.

  • y_count (int) – The number of rows in the block model. Must be greater than zero.

  • z_count (int) – The number of slices in the block model. Must be greater than zero.

Notes

Parameters should only be passed for new block models.

Raises
  • ValueError – If x_res, y_res, z_res, x_count, y_count or z_count is less than or equal to zero.

  • TypeError – If x_res, y_res, z_res, x_count, y_count or z_count is not numeric.

  • TypeError – If x_count, y_count or z_count are numeric but not integers.

Examples

Create a block model as described above and make every second block invisible.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.new("blockmodels/model", DenseBlockModel(
>>>         x_res=1, y_res=2, z_res=3, x_count=10, y_count=15, z_count=5
>>>         )) as new_model:
>>>     new_model.block_visibility = [True, False] * ((10 * 15 * 5) // 2)
classmethod static_type()

Return the type of dense block model as stored in a Project.

This can be used for determining if the type of an object is a dense block model.

property block_count

The count of blocks in the model.

property block_visibility_3d

A view of the block visibility reshaped into 3 dimensions. block_visibility_3d[slice, row, column] gives the visibility for the specified slice, row and column.

Raises
  • ValueError – If set using a value which cannot be converted to a bool.

  • ValueError – If set to a value which cannot be broadcast to the right shape.

Examples

Make a 10x10x10 block model and make every block in the 4th row invisible, excluding blocks in the 0th slice.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.new("blockmodels/visibility_3d", DenseBlockModel(
...         x_count=10, y_count=10, z_count=10, x_res=1, y_res=1, z_res=0.5
...         )) as new_blocks:
...     new_blocks.block_visibility_3d[:, 5, :] = False
...     new_blocks.block_visibility_3d[0, :, :] = True
property block_selection_3d

A view of the block selection reshaped into 3 dimensions. block_selection_3d[slice, row, column] gives the visibility for the block in the specified slice, row and column.

Raises
  • ValueError – If set using a value which cannot be converted to a bool.

  • ValueError – If set to a value which cannot be broadcast to the right shape.

save()

Save the changes made to the object.

Generally a user does not need to call this function because it is called automatically at the end of a with block using Project.new() or Project.edit().

attribute_names()

Returns a list containing the names of all object-level attributes. Use this to iterate over the object attributes.

Returns

List containing the attribute names.

Return type

list

Examples

Iterate over all object attributes of the object stared at “target” and print their values.

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.read("target") as read_object:
...     for name in read_object.attribute_names():
...         print(name, ":", read_object.get_attribute(name))
property block_attributes

Access block attributes.

block_model.block_attributes[“Blocktastic”] will return the block attribute called “Blocktastic”.

Returns

Access to the block attributes.

Return type

PrimitiveAttributes

property block_centroids

The centroids of the blocks. This is represented as an ndarray of shape (block_count, 3) of the form: [[x1, y1, z1], [x2, y2, z2], …, [xN, yN, zN]] Where N is the block_count.

property block_colours

The colour of the blocks, represented as a ndarray of shape (block_count, 4) with each row i representing the colour of the ith block in the model in the form [Red, Green, Blue, Alpha].

When setting block colours, you may omit the Alpha component.

property block_resolution

The resolution of the block model.

This is the x_res, y_res and z_res values used when creating the model in an array. Once the block model has been created, these values cannot be changed.

property block_selection

The block selection represented as an ndarray of bools with shape: (block_count,). True indicates the block is selected; False indicates it is not selected.

Notes

In mapteksdk version 1.0, block_selection returned a 3D ndarray. To get the same functionality, see block_selection_3d property of dense block models.

property block_sizes

The block sizes represented as an ndarray of shape (block_count, 3). Each row represents the size of one block in the form [x, y, z] where x, y and z are positive numbers.

This means that the extent for the block with index i is calculated as: (block_centroids[i] - block_sizes[i] / 2, block_centroids[i] + block_sizes[i] / 2)

Notes

For DenseBlockModels, all block_sizes are the same.

property block_to_grid_index

An ndarray containing the mapping of the blocks to the row, column and slice their centroid lies within. This has shape (N, 3) where N is the block_count and each item is of the form [column, row, slice].

This means that the column, row and slice of the block centred at block_centroids[i] is block_to_grid_index[i].

For DenseBlockModels, there is only one block per grid cell and thus each item of the block_to_grid_index will be unique.

property block_visibility

The block visibility represented as an ndarray of bools with shape: (block_count,). True indicates the block is visible, False indicates it is not visible.

Notes

In mapteksdk version 1.0 block_visibility returned a 3D ndarray. To get the same functionality, see block_visibility_3d property of dense block models.

close()

Closes the object and saves the changes to the Project, preventing any further changes.

property column_count

The number of columns in the underlying block model.

This can be thought of as the number of blocks in the X direction (assuming no rotation is made). This can only be set by the block model’s constructor.

convert_to_block_coordinates(world_coordinates)

Converts points in world coordinates to points in block coordinates.

The block coordinate system for a particular model is defined such that [0, 0, 0] is the centre of the block in row 0, column 0 and slice 0. The X axis is aligned with the columns, the Y axis is aligned with the rows and the Z axis is aligned with the slices of the model. This makes the centre of the primary block in column i, row j and slice k to be: [x_res * i, y_res * j, z_res * k].

This function performs no error checking that the points lies within the model.

Parameters

world_coordinates (array_like) – Points in world coordinates to convert to block coordinates.

Returns

Numpy array containing world_coordinates converted to be in block_coordinates.

Return type

numpy.ndarray

Raises

ValueError – If world_coordinates has an invalid shape.

Notes

If a block model has origin = [0, 0, 0] and has not been rotated, then the block and world coordinate systems are identical.

Block models of differing size, origin or rotation will have different block coordinate systems.

convert_to_world_coordinates(block_coordinates)

Converts points in block coordinates to points in world coordinates.

This is the inverse of the transformation performed by convert_to_block_coordinates.

Parameters

block_coordinates (array_like) – Points in block coordinates to convert to world coordinates.

Returns

Numpy array containing block_coordinates converted to world_coordinates.

Return type

numpy.ndarray

Raises

ValueError – If block_coordinates has an invalid shape.

Notes

Block models of differing size, origin or rotation will have different block coordinate systems.

property coordinate_system

The coordinate system the points of this object are in.

Warning

Setting this property does not change the points. This is only a label stating the coordinate system the points are in.

Notes

If the object has no coordinate system, this will be None.

Changes are done directly in the project and will not be undone if an error occurs.

Examples

Creating an edge network and setting the coordinate system to be WGS84. Note that setting the coordinate system does not change the points. It is only stating which coordinate system the points are in.

>>> from pyproj import CRS
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import Polygon
>>> project = Project()
>>> with project.new("cad/rectangle", Polygon) as new_edges:
...     # Coordinates are in the form [longitude, latitude]
...     new_edges.points = [[112, 9], [112, 44], [154, 44], [154, 9]]
...     new_edges.coordinate_system = CRS.from_epsg(4326)

Often a standard map projection is not convenient or accurate for a given application. In such cases a local transform can be provided to allow coordinates to be specified in a more convenient system. The below example defines a local transform where the origin is translated 1.2 degrees north and 2.1 degree east, points are scaled to be twice as far from the horizontal origin and the coordinates are rotated 45 degrees clockwise about the horizontal_origin. Note that the points of the polygon are specified in the coordinate system after the local transform has been applied.

>>> import math
>>> from pyproj import CRS
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import Polygon, CoordinateSystem, LocalTransform
>>> project = Project()
>>> transform = LocalTransform(
...     horizontal_origin = [1.2, 2.1],
...     horizontal_scale_factor = 2,
...     horizontal_rotation = math.pi / 4)
>>> system = CoordinateSystem(CRS.from_epsg(20249), transform)
>>> with project.new("cad/rectangle_transform", Polygon) as new_edges:
...     new_edges.points = [[112, 9], [112, 44], [154, 44], [154, 9]]
...     new_edges.coordinate_system = system

See also

mapteksdk.data.coordinate_systems.CoordinateSystem

Allows for a coordinate system to be defined with an optional local transform.

property created_date

The date and time (in UTC) of when this object was created.

Returns

The date and time the object was created. 0:0:0 1/1/1970 if the operation failed.

Return type

datetime.datetime

delete_all_attributes()

Delete all object attributes attached to an object.

This only deletes object attributes and has no effect on PrimitiveAttributes.

Raises

RuntimeError – If all attributes cannot be deleted.

delete_attribute(attribute)

Deletes a single object-level attribute.

Deleting a non-existent object attribute will not raise an error.

Parameters

attribute (str) – Name of attribute to delete.

Returns

True if the object attribute existed and was deleted; False if the object attribute did not exist.

Return type

bool

Raises

RuntimeError – If the attribute cannot be deleted.

delete_block_attribute(attribute_name)

Delete a block attribute.

Parameters

attribute_name (str) – The name of attribute to delete.

Raises

Exception – If the object is opened in read-only mode.

dissociate_raster(raster)

Removes the raster from the object.

This is done directly on the Project and will not be undone if an error occurs.

Parameters

raster (ObjectID or Raster) – The raster to dissociate.

Returns

True if the raster was successfully dissociated from the object, False if the raster was not associated with the object.

Return type

bool

Raises

TypeError – If raster is not a Raster.

Notes

This only removes the association between the Raster and the object, it does not clear the registration information from the Raster.

Examples

Dissociate the first raster found on a picked object.

>>> from mapteksdk.project import Project
>>> from mapteksdk import operations
>>> project = Project()
>>> oid = operations.object_pick(
...     support_label="Pick an object to remove a raster from.")
... with project.edit(oid) as data_object:
...     report = f"There were no raster to remove from {oid.path}"
...     for index in data_object.rasters:
...         data_object.dissociate_raster(data_object.rasters[index])
...         report = f"Removed raster {index} from {oid.path}"
...         break
... # Now that the raster is dissociated and the object is closed,
... # the raster can be associated with a different object.
... operations.write_report("Remove Raster", report)
property extent

The axes aligned bounding extent of the object.

get_attribute(name)

Returns the value for the attribute with the specified name.

Parameters

name (str) – The name of the object attribute to get the value for.

Returns

The value of the object attribute name. For dtype = datetime.datetime this is an integer representing the number of milliseconds since 1st Jan 1970. For dtype = datetime.date this is a tuple of the form: (year, month, day).

Return type

any

Raises

KeyError – If there is no object attribute called name.

Warning

In the future this function may be changed to return datetime.datetime and datetime.date objects instead of the current representation for object attributes of type datetime.datetime or datetime.date.

get_attribute_type(name)

Returns the type of the attribute with the specified name.

Parameters

name (str) – Name of the attribute whose type should be returned.

Returns

The type of the object attribute name.

Return type

type

Raises

KeyError – If there is no object attribute called name.

get_colour_map()

Return the ID of the colour map object currently associated with this object.

Returns

The ID of the colour map object or null object ID if there is no colour map.

Return type

ObjectID

grid_index(start, stop=None)

Generates a boolean index for accessing block properties by row, column and slice instead of by block. The boolean index will include all subblocks between primary block start (inclusive) and primary block stop (exclusive), or all subblocks within primary block start if stop is not specified.

Parameters
  • start (array_like or int) – An array_like containing three elements - [column, row, slice]. The returned boolean index will include all blocks in a greater column, row and slice. If this is an integer, that integer is interpreted as the column, row and slice.

  • end (array_like or int) – An array_like containing three elements - [column, row, slice]. If None (Default) this is start + 1 (The resulting index will contain all blocks within primary block start). If not None, the boolean index will include all blocks between start (inclusive) and end (exclusive). If this is an integer, that integer is interpreted as the column, row and slice index.

Returns

A boolean index into the block property arrays. This is an array of booleans of shape (block_count,). If element i is True then subblock i is within the range specified by start and stop. If False it is not within that range.

Return type

ndarray

Raises
  • TypeError – If start or stop are invalid types.

  • ValueError – If start or stop are incorrect shapes.

Examples

These examples require a block model to be at “blockmodels/target”

This example selects all subblocks within the primary block in column 0, row 0 and slice 0:

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.edit("blockmodels/target") as edit_model:
...     index = edit_model.grid_index([0, 0, 0])
...     edit_model.block_selection[index] = True

By passing two values to grid index, it is possible to operate on all subblocks within a range of subblocks. This example passes [0, 2, 2] and [4, 5, 6] meaning all subblocks which have 0 <= column < 4 and 2 <= row < 5 and 2 <= slice < 6 will be selected by grid_index. By passing this index to block visibility, all subblocks within those primary blocks are made invisible.

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.edit("blockmodels/target") as edit_model:
...     index = edit_model.grid_index([0, 2, 2], [4, 5, 6])
...     edit_model.block_visibility[index] = False
property id

Object ID that uniquely references this object in the project.

Returns

The unique id of this object.

Return type

ObjectID

property lock_type

Indicates whether operating in read-only or read-write mode.

Returns

The type of lock.

Return type

LockType

property modified_date

The date and time (in UTC) of when this object was last modified.

Returns

The date and time this object was last modified. 0:0:0 1/1/1970 if the operation failed.

Return type

datetime.datetime

property orientation

The rotation of the object represented as Vulcan-style dip, plunge and bearing. This will return the tuple: (dip, plunge, bearing)

The returned values are in radians.

Notes

This is a derived property. It is recalculated each time this is called.

property origin

The origin of the block model represented as a point.

Setting the origin will translate the entire block model to be centred around the new origin.

Notes

For DenseBlockModels the resulting changes to the block_centroids will not occur until save is called. For SubblockedBlockModels the resulting changes to the block_centroids are immediately available, however changing the origin of such a model is slower.

Examples

Changing the origin will change the block model centroids, in this case by translating them by 1 unit in the X direction, 2 units in the Y direction and 3 units in the Z direction. Note that as this is a DenseBlockModel, the model needs to be saved (in this case via closing ending the with block) before the changes to the centroids will occur.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.new("blockmodels/model", DenseBlockModel(
...         x_res=2, y_res=3, z_res=4,
...         x_count=2, y_count=2, z_count=2)) as new_model:
...     new_model.origin = [1, 2, 3]
>>> with project.edit("blockmodels/model") as edit_model:
...     print(edit_model.block_centroids)
[[1, 2, 3], [3, 2, 3], [1, 5, 3], [3, 5, 3], [1, 2, 7], [3, 2, 7],
[1, 5, 7], [3, 5, 7]]
property rasters

A dictionary of raster indices and Object IDs of the raster images currently associated with this object.

The keys are the raster ids and the values are the Object IDs of the associated rasters. Note that all raster ids are integers however they may not be consecutive - for example, an object may have raster ids 0, 1, 5 and 200.

Notes

Rasters with higher indices appear on top of rasters with lower indices. The maximum possible raster id is 255.

Removing a raster from this dictionary will not remove the raster association from the object. Use dissociate_raster to do this.

Examples

Iterate over all rasters on an object and invert the colours. Note that this will fail if there is no object at the path “target” and it will do nothing if no rasters are associated with the target.

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.read("target") as read_object:
...     for raster in read_object.rasters.values():
...         with project.edit(raster) as edit_raster:
...             edit_raster.pixels[:, :3] = 255 - edit_raster.pixels[:, :3]
rotate(angle, axis)

Rotates the object by the specified angle around the specified axis.

Parameters
  • angle (float) – The angle to rotate by in radians. Positive is clockwise, negative is anticlockwise (When looking in the direction of axis).

  • axis (Axis) – The axis to rotate by.

Examples

Create a 2x2x2 dense block model which is rotated by pi / 4 radians (45 degrees) around the X axis.

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel, Axis
>>> project = Project()
>>> with project.new("blockmodels/dense_rotated", DenseBlockModel(
...         x_res=1, y_res=1, z_res=1,
...         x_count=2, y_count=2, z_count=3)) as new_model:
...     new_model.rotate(math.pi / 4, Axis.X)

If you want to specify the angle in degrees instead of radians, use the math.radians function. Additionally rotate can be called multiple times to rotate the block model in multiple axes. Both of these are shown in the below example. The resulting block model is rotated 32 degrees around the Y axis and 97 degrees around the Z axis.

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel, Axis
>>> project = Project()
>>> with project.new("blockmodels/dense_rotated_degrees", DenseBlockModel(
...         x_res=1, y_res=1, z_res=1,
...         x_count=2, y_count=2, z_count=3)) as new_model:
...     new_model.rotate(math.radians(32), Axis.Y)
...     new_model.rotate(math.radians(97), Axis.Z)
rotate_2d(angle)

Rotates the object in two dimensions. This is equivalent to rotate with axis=Axis.Z

Parameters

angle (float) – The angle to rotate by in radians. Positive is clockwise, negative is anticlockwise.

property rotation

Returns the magnitude of the rotation of the object in radians.

This value is the total rotation of the object relative to its original position.

Notes

If the object has been rotated in multiple axes, this will not be the sum of the rotations performed. For example, a rotation of 90 degrees around the X axis, followed by a rotation of 90 degrees around the Y axis corresponds to a single rotation of 120 degrees so this function would return (2 * pi) / 3 radians.

property row_count

The number of rows in the underlying block model.

This can be thought of as the number of blocks in the Y direction (assuming no rotation is made). This can only be set by the block model’s constructor.

save_block_attribute(attribute_name, data)

Create a new block attribute with the specified name and associate the specified data.

Parameters
  • attribute_name (str) – The name of attribute.

  • data (array_like) – Data for the associated attribute. This should be a ndarray of shape (block_count,). The ith entry in this array is the value of this primitive attribute for the ith block.

Raises
  • Exception – If the object is opened in read-only mode.

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

set_attribute(name, dtype, data)

Sets the value for the object attribute with the specified name. This will overwrite any existing attribute with the specified name.

Parameters
  • name (str) – The name of the object attribute for which the value should be set.

  • dtype (type) – The type of data to assign to the attribute. This should be a type from the ctypes module or datetime.datetime or datetime.date. Passing bool is equivalent to passing ctypes.c_bool. Passing str is equivalent to passing ctypes.c_char_p. Passing int is equivalent to passing ctypes.c_int16. Passing float is equivalent to passing ctypes.c_double.

  • data (any) – The value to assign to object attribute name. For dtype = datetime.datetime this can either be a datetime object or timestamp which will be passed directly to datetime.utcfromtimestamp(). For dtype = datetime.date this can either be a date object or a tuple of the form: (year, month, day).

Raises
  • ValueError – If dtype is an unsupported type.

  • TypeError – If value is an inappropriate type for object attribute name.

  • RuntimeError – If a different error occurs.

Warning

Object attributes are saved separately from the object itself - any changes made by this function (assuming it does not raise an error) will be saved even if save() is not called (for example, due to an error being raised by another function).

Examples

Create an object attribute on an object at “target” and then read its value.

>>> import ctypes
>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.edit("target") as edit_object:
...     edit_object.set_attribute("count", ctypes.c_int16, 0)
... with project.read("target") as read_object:
...     print(read_object.get_attribute("count"))
0
set_orientation(dip, plunge, bearing)

Overwrite the existing rotation with a rotation defined by the specified dip, plunge and bearing.

An orientation of (dip, plunge, bearing) radians is equivalent to rotating the model -dip radians around the X axis, -plunge radians around the Y axis and -(bearing - pi / 2) radians around the Z axis.

Parameters
  • dip (float) – Relative rotation of the Y axis around the X axis in radians. This should be between -pi and pi (inclusive).

  • plunge (float) – Relative rotation of the X axis around the Y axis in radians. This should be between -pi / 2 and pi / 2 (exclusive).

  • bearing (float) – Absolute bearing of the X axis around the Z axis in radians. This should be between -pi and pi (inclusive).

Raises

TypeError – If dip, plunge or bearing are not numbers.

Examples

Set orientation of a new 3x3x3 block model to be plunge = 45 degrees, dip = 30 degrees and bearing = -50 degrees

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.new("blockmodels/model_1", DenseBlockModel(
...         x_res=1, y_res=1, z_res=1,
...         x_count=3, y_count=3, z_count=3)) as new_model:
>>>     new_model.set_orientation(math.radians(45),
...                               math.radians(30),
...                               math.radians(-50))

Copy the rotation from one block model to another. Requires two block models.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.edit("blockmodels/model_1") as model_1:
...     with project.edit("blockmodels/model_2") as model_2:
...         model_2.set_orientation(*model_1.orientation)
set_rotation(angle, axis)

Overwrites the existing rotation with a rotation around the specified axis by the specified angle.

This is useful for resetting the rotation to a known point.

Parameters
  • angle (float) – Angle to set the rotation to in radians. Positive is clockwise, negative is anticlockwise.

  • axis (Axis) – Axis to rotate around.

set_rotation_2d(angle)

Overwrite the existing rotation with a simple 2d rotation.

Parameters

angle (float) – Angle to set the rotation to in radians.

property slice_count

The number of slices in the underlying block model.

This can be thought of as the number of blocks in the Z direction (assuming no rotation is made). This can only be set by the block model’s constructor.

class SubblockedBlockModel(object_id=None, lock_type=LockType.READWRITE, x_res=None, y_res=None, z_res=None, x_count=None, y_count=None, z_count=None)

Bases: mapteksdk.data.base.Topology, mapteksdk.data.primitives.block_properties.BlockProperties, mapteksdk.data.rotation.RotationMixin

A dense subblocked block model. Each primary block can contain subblocks allowing for the model to hold greater detail in areas of greater interest and less detail in areas of less interest.

Block attributes, such as block_visibility and block_colour, have one value per subblock. A subblocked block model is empty when created and contains no blocks. Use the add_subblocks function to add additional subblocks to the model.

Note that it is possible for a subblocked block model to include invalid subblocks. For example, subblocks which are outside of the extents of the block model. These blocks will not be displayed in the viewer.

If interoperability with Vulcan is desired, the subblock sizes should always be a multiple of the primary block sizes (the resolution defined on construction) and you should be careful to ensure subblocks do not intersect each other.

Parameters
  • x_res (float) – The x resolution. Must be greater than zero.

  • y_res (float) – The y resolution. Must be greater than zero.

  • z_res (float) – The z resolution. Must be greater than zero.

  • x_count (int) – The number of columns in the block model. Must be greater than zero.

  • y_count (int) – The number of rows in the block model. Must be greater than zero.

  • z_count (int) – The number of slices in the block model. Must be greater than zero.

Notes

Parameters should only be passed for new block models.

Raises
  • ValueError – If x_res, y_res, z_res, x_count, y_count or z_count is less than or equal to zero.

  • TypeError – If x_res, y_res, z_res, x_count, y_count or z_count is not numeric.

  • TypeError – If x_count, y_count or z_count are numeric but not integers.

Examples

Creating a subblocked block model with two parent blocks, one of which is completely filled by a single subblock and another which is split into three subblocks. Each subblock is made invisible individually. Though the block model has two primary blocks, it has four subblocks so four values are required for the visibility.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import SubblockedBlockModel
>>> centroids = [[0, 0, 0], [-1, 3, 0], [1, 3, 0], [0, 5, 0]]
>>> sizes = [[4, 4, 4], [2, 2, 4], [2, 2, 4], [4, 2, 4]]
>>> visibility = [True, True, False, False]
>>> project = Project()
>>> with project.new("blockmodels/subblocked_model", SubblockedBlockModel(
...         x_count=1, y_count=2, z_count=1, x_res=4, y_res=4, z_res=4
...         )) as new_blocks:
...     new_blocks.add_subblocks(centroids, sizes)
...     new_blocks.block_visibility = visibility
classmethod static_type()

Return the type of subblocked block model as stored in a Project.

This can be used for determining if the type of an object is a subblocked block model.

add_subblocks(block_centroids, block_sizes, use_block_coordinates=True)

Adds an array of subblocks to the subblocked block model.

By default the block_centroids should be in block model coordinates rather than world coordinates. See convert_to_world_coordinates() for more information.

Parameters
  • block_centroid (array_like) – An array of block centroids of the new blocks. This is of the form: [x, y, z].

  • block_sizes (array_like) – An array of block sizes of the new blocks, each containing three floats. This is of the form: [x_size, y_size, z_size].

  • use_block_coordinates (bool) – If True (default) then the coordinates of the block centroids will be interpreted as block model coordinates (They will be passed through convert_to_world_coordinates()). If False, then the coordinates of the block centroids will be interpreted as world coordinates.

Raises

Notes

Calling this function in a loop is very slow. You should calculate all of the subblocks and pass them to this function in a single call.

Examples

The block centroids are specified in block model coordinates relative to the bottom left hand corner of the block model. In the below example, the block model is rotated around all three axes and translated away from the origin. By specifying the centroids in block model coordinates, the centroids remain simple. The output shows the resulting block centroids of the model. To get the same model with use_block_coordinates=False these are the centroids which would be required. As you can see they are significantly more complicated.

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import SubblockedBlockModel, Axis
>>> centroids = [[-1.5, -1, -1], [-0.5, -1, -1], [-1, 1, -1],
...              [-1.5, -1, 1], [-0.5, -1, 1], [-1, 1, 1],
...              [-1.5, -1, 3], [-0.5, -1, 3], [-1, 1, 3]]
>>> sizes = [[1, 2, 2], [1, 2, 2], [2, 2, 2],
...          [1, 2, 2], [1, 2, 2], [2, 2, 2],
...          [1, 2, 2], [1, 2, 2], [2, 2, 2]]
>>> project = Project()
>>> with project.new("blockmodels/transformed", SubblockedBlockModel(
...         x_count=1, y_count=2, z_count=3, x_res=4, y_res=4, z_res=4
...         )) as new_blocks:
...     new_blocks.origin = [94, -16, 12]
...     new_blocks.rotate(math.pi / 3, Axis.X)
...     new_blocks.rotate(-math.pi / 4, Axis.Y)
...     new_blocks.rotate(math.pi * 0.75, Axis.Z)
...     new_blocks.add_subblocks(centroids, sizes)
...     print(new_blocks.block_centroids)
[[ 95.95710678 -16.64693601  11.96526039]
 [ 95.45710678 -15.86036992  12.32763283]
 [ 94.70710678 -16.09473435  10.42170174]
 [ 94.54289322 -17.87168089  12.67236717]
 [ 94.04289322 -17.08511479  13.03473961]
 [ 93.29289322 -17.31947922  11.12880852]
 [ 93.12867966 -19.09642576  13.37947395]
 [ 92.62867966 -18.30985966  13.74184639]
 [ 91.87867966 -18.54422409  11.8359153 ]]

Specifying the block centroids in world coordinates is useful when the centroids are already available in world coordinates. This example shows copying the blocks from the model created in the previous example into a new model. Notice that the origin and rotations are the same for the copy. If this were not the case the centroids would likely lie outside of the block model and would not appear in the viewer.

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import SubblockedBlockModel, Axis
>>> project = Project()
>>> with project.new("blockmodels/transformed_copy", SubblockedBlockModel(
...         x_count=1, y_count=2, z_count=3, x_res=4, y_res=4, z_res=4
...         )) as new_blocks:
...     new_blocks.origin = [94, -16, 12]
...     new_blocks.rotate(math.pi / 3, Axis.X)
...     new_blocks.rotate(-math.pi / 4, Axis.Y)
...     new_blocks.rotate(math.pi * 0.75, Axis.Z)
...     with project.read("blockmodels/transformed") as read_blocks:
...         new_blocks.add_subblocks(read_blocks.block_centroids,
...                                  read_blocks.block_sizes,
...                                  use_block_coordinates=False)
remove_block(index)

Deletes the block at the specified index.

This operation is performed directly on the project to ensure that all properties (such as block_visibility and block_attributes) for the deleted block are deleted as well.

Does nothing if requesting to delete a nonexistent block.

Parameters

index (int) – Index of the block to the delete.

Warning

Any unsaved changes to the object when this function is called are discarded before the block is deleted. If you wish to keep these changes, call save() before calling this function.

rotate(angle, axis)

Rotates the object by the specified angle around the specified axis.

Parameters
  • angle (float) – The angle to rotate by in radians. Positive is clockwise, negative is anticlockwise (When looking in the direction of axis).

  • axis (Axis) – The axis to rotate by.

Examples

Create a 2x2x2 dense block model which is rotated by pi / 4 radians (45 degrees) around the X axis.

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel, Axis
>>> project = Project()
>>> with project.new("blockmodels/dense_rotated", DenseBlockModel(
...         x_res=1, y_res=1, z_res=1,
...         x_count=2, y_count=2, z_count=3)) as new_model:
...     new_model.rotate(math.pi / 4, Axis.X)

If you want to specify the angle in degrees instead of radians, use the math.radians function. Additionally rotate can be called multiple times to rotate the block model in multiple axes. Both of these are shown in the below example. The resulting block model is rotated 32 degrees around the Y axis and 97 degrees around the Z axis.

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel, Axis
>>> project = Project()
>>> with project.new("blockmodels/dense_rotated_degrees", DenseBlockModel(
...         x_res=1, y_res=1, z_res=1,
...         x_count=2, y_count=2, z_count=3)) as new_model:
...     new_model.rotate(math.radians(32), Axis.Y)
...     new_model.rotate(math.radians(97), Axis.Z)
set_rotation(angle, axis)

Overwrites the existing rotation with a rotation around the specified axis by the specified angle.

This is useful for resetting the rotation to a known point.

Parameters
  • angle (float) – Angle to set the rotation to in radians. Positive is clockwise, negative is anticlockwise.

  • axis (Axis) – Axis to rotate around.

set_orientation(dip, plunge, bearing)

Overwrite the existing rotation with a rotation defined by the specified dip, plunge and bearing.

An orientation of (dip, plunge, bearing) radians is equivalent to rotating the model -dip radians around the X axis, -plunge radians around the Y axis and -(bearing - pi / 2) radians around the Z axis.

Parameters
  • dip (float) – Relative rotation of the Y axis around the X axis in radians. This should be between -pi and pi (inclusive).

  • plunge (float) – Relative rotation of the X axis around the Y axis in radians. This should be between -pi / 2 and pi / 2 (exclusive).

  • bearing (float) – Absolute bearing of the X axis around the Z axis in radians. This should be between -pi and pi (inclusive).

Raises

TypeError – If dip, plunge or bearing are not numbers.

Examples

Set orientation of a new 3x3x3 block model to be plunge = 45 degrees, dip = 30 degrees and bearing = -50 degrees

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.new("blockmodels/model_1", DenseBlockModel(
...         x_res=1, y_res=1, z_res=1,
...         x_count=3, y_count=3, z_count=3)) as new_model:
>>>     new_model.set_orientation(math.radians(45),
...                               math.radians(30),
...                               math.radians(-50))

Copy the rotation from one block model to another. Requires two block models.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.edit("blockmodels/model_1") as model_1:
...     with project.edit("blockmodels/model_2") as model_2:
...         model_2.set_orientation(*model_1.orientation)
attribute_names()

Returns a list containing the names of all object-level attributes. Use this to iterate over the object attributes.

Returns

List containing the attribute names.

Return type

list

Examples

Iterate over all object attributes of the object stared at “target” and print their values.

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.read("target") as read_object:
...     for name in read_object.attribute_names():
...         print(name, ":", read_object.get_attribute(name))
property block_attributes

Access block attributes.

block_model.block_attributes[“Blocktastic”] will return the block attribute called “Blocktastic”.

Returns

Access to the block attributes.

Return type

PrimitiveAttributes

property block_centroids

The centroids of the blocks. This is represented as an ndarray of shape (block_count, 3) of the form: [[x1, y1, z1], [x2, y2, z2], …, [xN, yN, zN]] Where N is the block_count.

property block_colours

The colour of the blocks, represented as a ndarray of shape (block_count, 4) with each row i representing the colour of the ith block in the model in the form [Red, Green, Blue, Alpha].

When setting block colours, you may omit the Alpha component.

property block_count

The count of blocks in the model.

property block_resolution

The resolution of the block model.

This is the x_res, y_res and z_res values used when creating the model in an array. Once the block model has been created, these values cannot be changed.

property block_selection

The block selection represented as an ndarray of bools with shape: (block_count,). True indicates the block is selected; False indicates it is not selected.

Notes

In mapteksdk version 1.0, block_selection returned a 3D ndarray. To get the same functionality, see block_selection_3d property of dense block models.

property block_sizes

The block sizes represented as an ndarray of shape (block_count, 3). Each row represents the size of one block in the form [x, y, z] where x, y and z are positive numbers.

This means that the extent for the block with index i is calculated as: (block_centroids[i] - block_sizes[i] / 2, block_centroids[i] + block_sizes[i] / 2)

Notes

For DenseBlockModels, all block_sizes are the same.

property block_to_grid_index

An ndarray containing the mapping of the blocks to the row, column and slice their centroid lies within. This has shape (N, 3) where N is the block_count and each item is of the form [column, row, slice].

This means that the column, row and slice of the block centred at block_centroids[i] is block_to_grid_index[i].

For DenseBlockModels, there is only one block per grid cell and thus each item of the block_to_grid_index will be unique.

property block_visibility

The block visibility represented as an ndarray of bools with shape: (block_count,). True indicates the block is visible, False indicates it is not visible.

Notes

In mapteksdk version 1.0 block_visibility returned a 3D ndarray. To get the same functionality, see block_visibility_3d property of dense block models.

close()

Closes the object and saves the changes to the Project, preventing any further changes.

property column_count

The number of columns in the underlying block model.

This can be thought of as the number of blocks in the X direction (assuming no rotation is made). This can only be set by the block model’s constructor.

convert_to_block_coordinates(world_coordinates)

Converts points in world coordinates to points in block coordinates.

The block coordinate system for a particular model is defined such that [0, 0, 0] is the centre of the block in row 0, column 0 and slice 0. The X axis is aligned with the columns, the Y axis is aligned with the rows and the Z axis is aligned with the slices of the model. This makes the centre of the primary block in column i, row j and slice k to be: [x_res * i, y_res * j, z_res * k].

This function performs no error checking that the points lies within the model.

Parameters

world_coordinates (array_like) – Points in world coordinates to convert to block coordinates.

Returns

Numpy array containing world_coordinates converted to be in block_coordinates.

Return type

numpy.ndarray

Raises

ValueError – If world_coordinates has an invalid shape.

Notes

If a block model has origin = [0, 0, 0] and has not been rotated, then the block and world coordinate systems are identical.

Block models of differing size, origin or rotation will have different block coordinate systems.

convert_to_world_coordinates(block_coordinates)

Converts points in block coordinates to points in world coordinates.

This is the inverse of the transformation performed by convert_to_block_coordinates.

Parameters

block_coordinates (array_like) – Points in block coordinates to convert to world coordinates.

Returns

Numpy array containing block_coordinates converted to world_coordinates.

Return type

numpy.ndarray

Raises

ValueError – If block_coordinates has an invalid shape.

Notes

Block models of differing size, origin or rotation will have different block coordinate systems.

property coordinate_system

The coordinate system the points of this object are in.

Warning

Setting this property does not change the points. This is only a label stating the coordinate system the points are in.

Notes

If the object has no coordinate system, this will be None.

Changes are done directly in the project and will not be undone if an error occurs.

Examples

Creating an edge network and setting the coordinate system to be WGS84. Note that setting the coordinate system does not change the points. It is only stating which coordinate system the points are in.

>>> from pyproj import CRS
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import Polygon
>>> project = Project()
>>> with project.new("cad/rectangle", Polygon) as new_edges:
...     # Coordinates are in the form [longitude, latitude]
...     new_edges.points = [[112, 9], [112, 44], [154, 44], [154, 9]]
...     new_edges.coordinate_system = CRS.from_epsg(4326)

Often a standard map projection is not convenient or accurate for a given application. In such cases a local transform can be provided to allow coordinates to be specified in a more convenient system. The below example defines a local transform where the origin is translated 1.2 degrees north and 2.1 degree east, points are scaled to be twice as far from the horizontal origin and the coordinates are rotated 45 degrees clockwise about the horizontal_origin. Note that the points of the polygon are specified in the coordinate system after the local transform has been applied.

>>> import math
>>> from pyproj import CRS
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import Polygon, CoordinateSystem, LocalTransform
>>> project = Project()
>>> transform = LocalTransform(
...     horizontal_origin = [1.2, 2.1],
...     horizontal_scale_factor = 2,
...     horizontal_rotation = math.pi / 4)
>>> system = CoordinateSystem(CRS.from_epsg(20249), transform)
>>> with project.new("cad/rectangle_transform", Polygon) as new_edges:
...     new_edges.points = [[112, 9], [112, 44], [154, 44], [154, 9]]
...     new_edges.coordinate_system = system

See also

mapteksdk.data.coordinate_systems.CoordinateSystem

Allows for a coordinate system to be defined with an optional local transform.

property created_date

The date and time (in UTC) of when this object was created.

Returns

The date and time the object was created. 0:0:0 1/1/1970 if the operation failed.

Return type

datetime.datetime

delete_all_attributes()

Delete all object attributes attached to an object.

This only deletes object attributes and has no effect on PrimitiveAttributes.

Raises

RuntimeError – If all attributes cannot be deleted.

delete_attribute(attribute)

Deletes a single object-level attribute.

Deleting a non-existent object attribute will not raise an error.

Parameters

attribute (str) – Name of attribute to delete.

Returns

True if the object attribute existed and was deleted; False if the object attribute did not exist.

Return type

bool

Raises

RuntimeError – If the attribute cannot be deleted.

delete_block_attribute(attribute_name)

Delete a block attribute.

Parameters

attribute_name (str) – The name of attribute to delete.

Raises

Exception – If the object is opened in read-only mode.

dissociate_raster(raster)

Removes the raster from the object.

This is done directly on the Project and will not be undone if an error occurs.

Parameters

raster (ObjectID or Raster) – The raster to dissociate.

Returns

True if the raster was successfully dissociated from the object, False if the raster was not associated with the object.

Return type

bool

Raises

TypeError – If raster is not a Raster.

Notes

This only removes the association between the Raster and the object, it does not clear the registration information from the Raster.

Examples

Dissociate the first raster found on a picked object.

>>> from mapteksdk.project import Project
>>> from mapteksdk import operations
>>> project = Project()
>>> oid = operations.object_pick(
...     support_label="Pick an object to remove a raster from.")
... with project.edit(oid) as data_object:
...     report = f"There were no raster to remove from {oid.path}"
...     for index in data_object.rasters:
...         data_object.dissociate_raster(data_object.rasters[index])
...         report = f"Removed raster {index} from {oid.path}"
...         break
... # Now that the raster is dissociated and the object is closed,
... # the raster can be associated with a different object.
... operations.write_report("Remove Raster", report)
property extent

The axes aligned bounding extent of the object.

get_attribute(name)

Returns the value for the attribute with the specified name.

Parameters

name (str) – The name of the object attribute to get the value for.

Returns

The value of the object attribute name. For dtype = datetime.datetime this is an integer representing the number of milliseconds since 1st Jan 1970. For dtype = datetime.date this is a tuple of the form: (year, month, day).

Return type

any

Raises

KeyError – If there is no object attribute called name.

Warning

In the future this function may be changed to return datetime.datetime and datetime.date objects instead of the current representation for object attributes of type datetime.datetime or datetime.date.

get_attribute_type(name)

Returns the type of the attribute with the specified name.

Parameters

name (str) – Name of the attribute whose type should be returned.

Returns

The type of the object attribute name.

Return type

type

Raises

KeyError – If there is no object attribute called name.

get_colour_map()

Return the ID of the colour map object currently associated with this object.

Returns

The ID of the colour map object or null object ID if there is no colour map.

Return type

ObjectID

grid_index(start, stop=None)

Generates a boolean index for accessing block properties by row, column and slice instead of by block. The boolean index will include all subblocks between primary block start (inclusive) and primary block stop (exclusive), or all subblocks within primary block start if stop is not specified.

Parameters
  • start (array_like or int) – An array_like containing three elements - [column, row, slice]. The returned boolean index will include all blocks in a greater column, row and slice. If this is an integer, that integer is interpreted as the column, row and slice.

  • end (array_like or int) – An array_like containing three elements - [column, row, slice]. If None (Default) this is start + 1 (The resulting index will contain all blocks within primary block start). If not None, the boolean index will include all blocks between start (inclusive) and end (exclusive). If this is an integer, that integer is interpreted as the column, row and slice index.

Returns

A boolean index into the block property arrays. This is an array of booleans of shape (block_count,). If element i is True then subblock i is within the range specified by start and stop. If False it is not within that range.

Return type

ndarray

Raises
  • TypeError – If start or stop are invalid types.

  • ValueError – If start or stop are incorrect shapes.

Examples

These examples require a block model to be at “blockmodels/target”

This example selects all subblocks within the primary block in column 0, row 0 and slice 0:

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.edit("blockmodels/target") as edit_model:
...     index = edit_model.grid_index([0, 0, 0])
...     edit_model.block_selection[index] = True

By passing two values to grid index, it is possible to operate on all subblocks within a range of subblocks. This example passes [0, 2, 2] and [4, 5, 6] meaning all subblocks which have 0 <= column < 4 and 2 <= row < 5 and 2 <= slice < 6 will be selected by grid_index. By passing this index to block visibility, all subblocks within those primary blocks are made invisible.

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.edit("blockmodels/target") as edit_model:
...     index = edit_model.grid_index([0, 2, 2], [4, 5, 6])
...     edit_model.block_visibility[index] = False
property id

Object ID that uniquely references this object in the project.

Returns

The unique id of this object.

Return type

ObjectID

property lock_type

Indicates whether operating in read-only or read-write mode.

Returns

The type of lock.

Return type

LockType

property modified_date

The date and time (in UTC) of when this object was last modified.

Returns

The date and time this object was last modified. 0:0:0 1/1/1970 if the operation failed.

Return type

datetime.datetime

property orientation

The rotation of the object represented as Vulcan-style dip, plunge and bearing. This will return the tuple: (dip, plunge, bearing)

The returned values are in radians.

Notes

This is a derived property. It is recalculated each time this is called.

property origin

The origin of the block model represented as a point.

Setting the origin will translate the entire block model to be centred around the new origin.

Notes

For DenseBlockModels the resulting changes to the block_centroids will not occur until save is called. For SubblockedBlockModels the resulting changes to the block_centroids are immediately available, however changing the origin of such a model is slower.

Examples

Changing the origin will change the block model centroids, in this case by translating them by 1 unit in the X direction, 2 units in the Y direction and 3 units in the Z direction. Note that as this is a DenseBlockModel, the model needs to be saved (in this case via closing ending the with block) before the changes to the centroids will occur.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.new("blockmodels/model", DenseBlockModel(
...         x_res=2, y_res=3, z_res=4,
...         x_count=2, y_count=2, z_count=2)) as new_model:
...     new_model.origin = [1, 2, 3]
>>> with project.edit("blockmodels/model") as edit_model:
...     print(edit_model.block_centroids)
[[1, 2, 3], [3, 2, 3], [1, 5, 3], [3, 5, 3], [1, 2, 7], [3, 2, 7],
[1, 5, 7], [3, 5, 7]]
property rasters

A dictionary of raster indices and Object IDs of the raster images currently associated with this object.

The keys are the raster ids and the values are the Object IDs of the associated rasters. Note that all raster ids are integers however they may not be consecutive - for example, an object may have raster ids 0, 1, 5 and 200.

Notes

Rasters with higher indices appear on top of rasters with lower indices. The maximum possible raster id is 255.

Removing a raster from this dictionary will not remove the raster association from the object. Use dissociate_raster to do this.

Examples

Iterate over all rasters on an object and invert the colours. Note that this will fail if there is no object at the path “target” and it will do nothing if no rasters are associated with the target.

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.read("target") as read_object:
...     for raster in read_object.rasters.values():
...         with project.edit(raster) as edit_raster:
...             edit_raster.pixels[:, :3] = 255 - edit_raster.pixels[:, :3]
rotate_2d(angle)

Rotates the object in two dimensions. This is equivalent to rotate with axis=Axis.Z

Parameters

angle (float) – The angle to rotate by in radians. Positive is clockwise, negative is anticlockwise.

property rotation

Returns the magnitude of the rotation of the object in radians.

This value is the total rotation of the object relative to its original position.

Notes

If the object has been rotated in multiple axes, this will not be the sum of the rotations performed. For example, a rotation of 90 degrees around the X axis, followed by a rotation of 90 degrees around the Y axis corresponds to a single rotation of 120 degrees so this function would return (2 * pi) / 3 radians.

property row_count

The number of rows in the underlying block model.

This can be thought of as the number of blocks in the Y direction (assuming no rotation is made). This can only be set by the block model’s constructor.

save()

Save the changes made to the object.

Generally a user does not need to call this function because it is called automatically at the end of a with block using Project.new() or Project.edit().

save_block_attribute(attribute_name, data)

Create a new block attribute with the specified name and associate the specified data.

Parameters
  • attribute_name (str) – The name of attribute.

  • data (array_like) – Data for the associated attribute. This should be a ndarray of shape (block_count,). The ith entry in this array is the value of this primitive attribute for the ith block.

Raises
  • Exception – If the object is opened in read-only mode.

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

set_attribute(name, dtype, data)

Sets the value for the object attribute with the specified name. This will overwrite any existing attribute with the specified name.

Parameters
  • name (str) – The name of the object attribute for which the value should be set.

  • dtype (type) – The type of data to assign to the attribute. This should be a type from the ctypes module or datetime.datetime or datetime.date. Passing bool is equivalent to passing ctypes.c_bool. Passing str is equivalent to passing ctypes.c_char_p. Passing int is equivalent to passing ctypes.c_int16. Passing float is equivalent to passing ctypes.c_double.

  • data (any) – The value to assign to object attribute name. For dtype = datetime.datetime this can either be a datetime object or timestamp which will be passed directly to datetime.utcfromtimestamp(). For dtype = datetime.date this can either be a date object or a tuple of the form: (year, month, day).

Raises
  • ValueError – If dtype is an unsupported type.

  • TypeError – If value is an inappropriate type for object attribute name.

  • RuntimeError – If a different error occurs.

Warning

Object attributes are saved separately from the object itself - any changes made by this function (assuming it does not raise an error) will be saved even if save() is not called (for example, due to an error being raised by another function).

Examples

Create an object attribute on an object at “target” and then read its value.

>>> import ctypes
>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.edit("target") as edit_object:
...     edit_object.set_attribute("count", ctypes.c_int16, 0)
... with project.read("target") as read_object:
...     print(read_object.get_attribute("count"))
0
set_rotation_2d(angle)

Overwrite the existing rotation with a simple 2d rotation.

Parameters

angle (float) – Angle to set the rotation to in radians.

property slice_count

The number of slices in the underlying block model.

This can be thought of as the number of blocks in the Z direction (assuming no rotation is made). This can only be set by the block model’s constructor.