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 PrimitiveAttributes(primitive_type, owner_object)

Bases: MutableMapping[AttributeKey, ndarray]

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). This class supports most (but not all) functions supported by a dictionary.

Parameters:
  • primitive_type (PrimitiveType) – The type of primitive these attributes have one value for.

  • owner_object (Topology) – 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 the properties in the See Also section.

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)
primitive_type: PrimitiveType

The type of primitive the attributes are associated with.

owner: Topology

The object the attributes are read and set to.

property names: Sequence[str]

Returns the names of the attributes.

This can be used to iterate over all of the attributes for this primitive type.

Returns:

The names of the attributes associated with this primitive.

Return type:

Sequence[str]

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 (AttributeKey | str) – The name of the primitive attribute to delete.

Raises:

ValueError – If the deleted attribute is associated with a colour map.

property colour_map: ObjectID[ColourMap] | None

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_key: AttributeKey | None

Returns the key of the attribute the colour map is associated with.

The key contains extra metadata beyond the name of the attribute.

Returns:

  • key – The key of the primitive attribute associated with the colour map.

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

property colour_map_attribute: str | None

Returns the name of 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.

Only one colour map can be associated with an object at a time. Attempting to associate another colour map will discard the currently associated colour map.

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

  • colour_map (ObjectID[ColourMap] | ColourMap) – 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

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

Changed in mapteksdk 1.5:

  • Prior to 1.5, this function included an implicit call to save()

  • Prior to 1.5, it was not defined which colour map (if any) would be kept if this was called for multiple different primitive types.

property primitive_count: int

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.

Parameters:

name (str) –

Return type:

type

get_key_by_name(name)

Get the AttributeKey for the attribute with the specified name.

Parameters:

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

Returns:

The key of the attribute with the specified name.

Return type:

AttributeKey

Raises:

KeyError – If no attribute with the specified name exists.

clear() None.  Remove all items from D.
get(k[, d]) D[k] if k in D, else d.  d defaults to None.
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() an object providing a view on D's values