mapteksdk.data.primitives.primitive_attributes module

Access to primitive attributes.

Unlike object attributes, which have one value for the entire object, primitive attributes have one value for each primitive of a particular type. For example, a point primitive attribute has one value for each point and a block primitive attribute has one value for each block.

Users of the SDK should never need to construct these objects directly. Instead, they should be accessed via the point_attributes, edge_attributes, facet_attributes, cell_attributes and block_attributes properties.

class PrimitiveType(value)

Bases: Enum

Enumeration of fundamental primitive types.

POINT = 1
EDGE = 2
FACET = 3
TETRA = 4
CELL = 5
BLOCK = 6
class PrimitiveAttributes(primitive_type, owner_object)

Bases: object

Provides access to the attributes for a given primitive type on an object.

A primitive attribute is an attribute with one value for each primitive of a particular type. For example, if an object contains ten points then a point primitive attribute would have ten values - one for each point. Primitive attributes can be accessed by name using the [] operator (This is similar to accessing a dictionary).

Parameters
  • primitive_type (PrimitiveType) – The type of primitive these attributes are from.

  • owner_object (Any) – The object that the attributes are from.

Warning

Primitive attributes set through the Python SDK may not appear in the user interface of Maptek applications.

Edge and facet primitive attributes are not well supported by Maptek applications. You can read and write values from/to them via the SDK, however they are not visible from the application side.

Notes

It is not recommended to create PrimitiveAttribute objects directly. Instead use PointProperties.point_attributes, EdgeProperties.edge_attributes or FacetProperties.facet_attributes.

Examples

Create a point primitive attribute of type string called “temperature”. Note that new_set.point_attributes[“temperature”][i] is the value associated with new_set.points[i] (so point[0] has the attribute “Hot”, point[1] has the attribute “Warm” and point[2] has the attribute[“Cold”]).

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import PointSet
>>> project = Project()
>>> with project.new("cad/points", PointSet) as new_set:
>>>     new_set.points = [[1, 1, 0], [2, 0, 1], [3, 2, 0]]
>>>     new_set.point_attributes["temperature"] = ["Hot", "Warm", "Cold"]

Colour the point set created in the previous example with a colour map such that points with attribute “Hot” are red, “Warm” are orange and “Cold” are blue.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import StringColourMap
>>> project = Project()
>>> with project.new("legends/heatMap", StringColourMap) as new_legend:
>>>     new_legend.legend = ["Hot", "Warm", "Cold"]
>>>     new_legend.colours = [[255, 0, 0], [255, 165, 0], [0, 0, 255]]
>>> with project.edit("cad/points") as edit_set:
>>>     edit_set.point_attributes.set_colour_map("temperature", new_legend)
property names

Returns the names of the attributes. Use this to iterate over all attributes.

Returns

The names of the attributes associated with this primitive.

Return type

dict_keys

Raises

RuntimeError – If an attribute is deleted while iterating over names.

Examples

Iterate over all attributes and print their values. This assumes there is a object with points at cad/points.

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.edit("cad/points") as point_set:
...     for name in point_set.point_attributes.names:
...         print(point_set.point_attributes[name])
delete_attribute(name)

Deletes the attribute with name, if it exists.

This method does not throw an exception if the attribute does not exist.

Parameters

name (string) – The name of the primitive attribute to delete.

property colour_map

Get the colour map used to colour the primitives.

This returns the colour map passed into set_colour_map.

Returns

  • ObjectID – Object id of the colour map associated with this object.

  • None – If no colour map is associated with this object.

property colour_map_attribute

Returns the attribute the colour map is associated with.

Returns

  • string – Name of attribute associated with the colour map.

  • None – If no colour map is associated with this primitive.

set_colour_map(attribute, colour_map)

Set the colour map for this type of primitive.

Parameters
  • attribute (string) – The name of the attribute to colour by.

  • colour_map (ObjectID or NumericColourMap or StringColourMap) – Object id of the colour map to use for this object. You can also pass the colour map directly.

Raises
  • ValueError – If colour map is an invalid type.

  • RuntimeError – If this object’s primitive type is not point.

Warning

An object can have only one colour map associated with it at a time! If this function is called multiple times (including on different primitives) it is undefined which call (if any) will be honoured.

Associating a colour map to edge, facet or cell attributes is not currently supported by the viewer. Attempting to do so will raise a RuntimeError.

Notes

Calling this functions triggers an implicit save operation on the owning object, causing all changes to be saved to the Project.

property primitive_count

The number of primitives of the given type in the object.

Returns

Number of points, edges, facets or blocks. Which is returned depends on primitive type given when this object was created.

Return type

int

Raises

ValueError – If the type of primitive is unsupported.

save_attributes()

Saves changes to the attributes to the Project.

This should not need to be explicitly called - it is called during save() and close() of an inheriting object. It is not recommended to call this function directly.

type_of_attribute(name)

Returns the ctype of the specified attribute.