mapteksdk.data.edges module
Edge data types.
Data types which are based on edge primitives. This includes:
EdgeNetwork which has discontinuous lines/polylines in single object.
Polyline which represents an open polygon.
Polygon which represents a closed polygon.
- class Edge(object_id, lock_type=LockType.READWRITE)
Bases:
EdgeProperties
,PointProperties
,PointDeletionProperties
,Topology
Base class for EdgeNetwork, Polygon and Polyline.
- append_points(*points)
Append points to the object.
Using this function is preferable to assigning to the points array directly because it allows points to be added to the object without any risk of changing existing points by accident. The return value can also be used to assign point properties for the new points.
- Parameters:
points (Point) – Points to append to the object.
- Returns:
Boolean array which can be used to assign properties for the newly added points.
- Return type:
BooleanArray
- Raises:
AppendPointsNotSupportedError – If the object does not support appending points. This is raised for GridSurfaces, and non-new Scans.
Examples
This function can be used to add a single point to an object:
>>> point_set: PointSet >>> point_set.append_points([1.5, -1.5, 2.25])
Passing multiple points can be used to append multiple points at once:
>>> point_set: PointSet >>> point_set.append_points([3.1, 1.1, 4.1], [2.2, 7.2, 1.2])
This function also accepts iterables of points, so the following is functionally identical to the previous example:
>>> point_set: PointSet >>> point_set.append_points([[3.1, 1.1, 4.1], [2.2, 7.2, 1.2]])
The return value of this function can be used to assign point properties to the newly added points:
>>> point_set: PointSet >>> new_point_indices = point_set.append_points( ... [3.1, 1.1, 4.1], [2.2, 7.2, 1.2]) >>> # Colour the two new points blue and magenta. >>> point_set.point_colours[new_point_indices] = [ ... [0, 0, 255, 255], [255, 0, 255, 255]]
- 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))
- cancel()
Cancel any pending changes to the object.
This undoes all changes made to the object since it was opened (including any changes saved by save()) and then closes the object.
After this is called, attempting to read or edit any of the properties on this object (other than the id) will raise an ObjectClosedError.
- Raises:
ReadOnlyError – If the object was open for read only (i.e not for editing). It is not necessary to call this for a read only object as there will be no pending changes.
ObjectClosedError – If called on a closed object.
- close()
Closes the object and saves the changes to the Project.
Attempting to read or edit properties of an object after closing it will raise a ReadOnlyError.
- property closed: bool
If this object has been closed.
Attempting to read or edit a closed object will raise an ObjectClosedError. Such an error typically indicates an error in the script and should not be caught.
Examples
If the object was opened with the Project.new(), Project.edit() or Project.read() in a “with” block, this will be True until the with block is closed and False afterwards.
>>> with self.project.new("cad/point_set", PointSet) as point_set: >>> point_set.points = [[1, 2, 3], [4, 5, 6]] >>> print("closed?", point_set.closed) >>> print("closed?", point_set.closed) closed? False closed? True
- property coordinate_system: CoordinateSystem | None
The coordinate system the points of this object are in.
If the object has no coordinate system, this will be None.
- Raises:
ReadOnlyError – If set on an object open for read-only.
Warning
Setting this property does not change the points. This is only a label stating the coordinate system the points are in.
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: datetime
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_edge_attribute(attribute_name)
Delete an edge attribute.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
- delete_point_attribute(attribute_name)
Delete a point attribute by name.
This is equivalent to: point_attributes.delete_attribute(attribute_name)
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
- dissociate_raster(raster)
Removes the raster from the object.
If an error occurs after dissociating a raster resulting in save() not being called, the dissociation of the raster can only be undone if the application’s API version is 1.6 or greater.
Prior to mapteksdk 1.6: Dissociating a raster will not be undone if an error occurs.
- Parameters:
raster (Raster | ObjectID[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.
ReadOnlyError – If this object is open for read-only.
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 edge_attributes: PrimitiveAttributes
Access to custom edge attributes.
These are arrays of values of the same type, with one value for each edge.
Use Object.edge_attributes[attribute_name] to access the edge attribute called attribute_name. See PrimitiveAttributes for valid operations on edge attributes.
- Returns:
Access to the edge attributes.
- Return type:
- Raises:
ValueError – If the type of the attribute is not supported.
Warning
For Surfaces if you have changed the points or facets in the object, you must call save() before accessing the edge attributes.
- property edge_colours: ColourArray
The colours of the edges.
The edge colours are represented as a numpy array of RGBA colours, with one colour for each edge.
- property edge_count: int
The count of edges in the object.
- property edge_selection: BooleanArray
A 1D ndarray representing which edges are selected.
edge_selection[i] = True indicates edge i is selected.
- property edges: EdgeArray
A 2D Numpy array of edges of the form: [[i0, j0], [i1, j1], …, [iN, jN]] where N is the number of edges and all iK and jK are valid indices in Object.points.
Warning
For Surfaces the edges are derived from the points and facets. If any changes are made to the points or facets, the corresponding changes to the edges will not be made until save() has been called.
Notes
Invalid edges are removed during save().
- 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:
ObjectAttributeTypes
- 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:
ObjectAttributeDataTypes
- Raises:
KeyError – If there is no object attribute called name.
- get_colour_map()
Return the ID of the colour map object associated with this object.
- Returns:
The ID of the colour map object or null object ID if there is no colour map.
- Return type:
- property id: ObjectID[DataObject]
Object ID that uniquely references this object in the project.
- Returns:
The unique id of this object.
- Return type:
- property is_read_only: bool
If this object is read-only.
This will return True if the object was open with Project.read() and False if it was open with Project.edit() or Project.new(). Attempting to edit a read-only object will raise an error.
- property lock_type: LockType
Indicates whether operating in read-only or read-write mode.
Use the is_read_only property instead for checking if an object is open for reading or editing.
- Returns:
The type of lock on this object. This will be LockType.ReadWrite if the object is open for editing and LockType.Read if the object is open for reading.
- Return type:
LockType
- property modified_date: datetime
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 point_attributes: PrimitiveAttributes
Access the custom point attributes.
These are arrays of values of the same type, with one value for each point.
Use Object.point_attributes[attribute_name] to access the point attribute called attribute_name. See PrimitiveAttributes for valid operations on point attributes.
- Returns:
Access to the point attributes.
- Return type:
- Raises:
ValueError – If the type of the attribute is not supported.
- property point_colours: ColourArray
The colour of each point in RGBA.
This is a numpy array of shape (N, 4) where N is the point count.
Examples
To get the colour of the ith point:
>>> point_i_colour = point_set.point_colours[i]
To get the red, green, blue and alpha components of the ith point:
>>> red, green, blue, alpha = point_set.point_colours[i]
- property point_count: int
The number of points in this object.
- property point_selection: BooleanArray
An array which indicates which points have been selected.
This is an array of booleans of shape (N,) where N is the point count. If the ith element in this array is True, then the ith point is selected. If the ith element in this array is False, then the ith point is not selected.
Examples
To get if the ith point is selected:
>>> point_i_selected = point_set.point_selection[i]
The point selection can be used to filter the arrays of other per-point properties down to only include the values of selected points. The following snippet demonstrates getting the colours of only the selected points in an object:
>>> selected_colours = point_set.point_colours[point_set.point_selection]
- property point_visibility: BooleanArray
An array which indicates which points are visible.
This is an array of booleans of shape (N,) where N is the point count. If the ith element in this array is True, then the ith point is visible. If the ith element in this array is False, then the ith point is invisible.
Examples
To get if the ith point is visible:
>>> point_i_visible = point_set.point_visibility[i]
The point visibility can be used to filter the arrays of other per-point properties down to only include the values of visible points. The following snippet demonstrates getting the colours of only the visible points in an object:
>>> visible_colours = point_set.point_colours[point_set.point_visibility]
- property point_z: FloatArray
The Z coordinates of the points.
- Raises:
ValueError – If set using a string which cannot be converted to a float.
ValueError – If set to a value which cannot be broadcast to the right shape.
TypeError – If set using a value which cannot be converted to a float.
- property points: PointArray
The three dimensional points in the object.
This is a numpy array of shape (N, 3) where N is the point count. This is of the form: [[x1, y1, z1], [x2, y2, z2], …, [xN, yN, zN]]
To get the ith point:
>>> point_i = point_set.points[i]
Similarly, to get the x, y and z coordinates of the ith point:
>>> x, y, z = point_set.points[i]
- Raises:
AttributeError – If attempting to set the points on an object which does not support setting points.
Examples
Create a new point set and set the points:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() ... with project.new("cad/test_points", PointSet) as new_points: ... new_points.points = [[0, 0, 0], [1, 0, 0], [1, 1, 0], ... [0, 1, 0], [0, 2, 2], [0, -1, 3]]
Print the second point from the point set defined above.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: ... print(read_points.points[2]) [1., 1., 0.]
Then set the 2nd point to [1, 2, 3]:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.edit("cad/test_points") as edit_points: ... edit_points.points[2] = [1, 2, 3]
Iterate over all of the points and print them.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: >>> for point in read_points.points: >>> print(point) [0., 0., 0.] [1., 0., 0.] [1., 2., 3.] [0., 1., 0.] [0., 2., 2.] [0., -1., 3.]
Print all points with y > 0 using numpy. Note that index has one element for each point which will be true if that point has y > 0 and false otherwise. This is then used to retrieve the points with y > 0.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: ... index = read_points.points[:, 1] > 0 ... print(read_points.points[index]) [[1. 2. 3.] [0. 1. 0.] [0. 2. 2.]]
To add a new point to a PointSet, the numpy row_stack function can be used. This is demonstrated by the following example which creates a point set and then opens it for editing and adds an extra point. The original points are coloured blue and the new point is coloured red.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... with Project() as project: ... with project.new("cad/append_single_example", PointSet ... ) as point_set: ... point_set.points = [ ... [-1, -1, 0], [1, -1, 0], [-1, 1, 0], [1, 1, 0] ... ] ... point_set.point_colours = [0, 0, 255, 255] ... with project.edit(point_set.id) as edit_set: ... edit_set.points = np.row_stack((edit_set.points, [0, 0, 1])) ... edit_set.point_colours[-1] = [255, 0, 0, 255]
The row stack function can also be used to add multiple points to an object at once, as demonstrated in the following example:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... original_points = [[-1, -1, 1], [1, -1, 1], [-1, 1, 1], [1, 1, 1]] ... new_points = [[-1, -1, 2], [1, -1, 2], [-1, 1, 2], [1, 1, 2]] ... with Project() as project: ... with project.new("cad/append_multiple_example", PointSet ... ) as point_set: ... point_set.points = original_points ... point_set.point_colours = [0, 0, 255, 255] ... with project.edit(point_set.id) as edit_set: ... original_point_count = edit_set.point_count ... edit_set.points = np.row_stack((edit_set.points, new_points)) ... new_point_count = edit_set.point_count ... edit_set.point_colours[ ... original_point_count:new_point_count] = [255, 0, 0, 255]
The row stack function can combine more than two point arrays if required by adding additional arrays to the tuple passed to the function. This is demonstrated by the following example, which creates a new point set containing the points from the point sets in the previous two examples plus a third set of points defined in the script. Make sure to run the previous two examples before running this one.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... extra_points = [[-2, -2, 3], [2, -2, 3], [-2, 2, 3], [2, 2, 3]] ... with Project() as project: ... with project.new("cad/triple_point_stack", PointSet) as new_set, \ ... project.read("cad/append_single_example") as single_set, \ ... project.read("cad/append_multiple_example") as multiple_set: ... new_set.points = np.row_stack(( ... extra_points, ... single_set.points, ... multiple_set.points ... ))
- property rasters: dict[int, ObjectID[Raster]]
The raster associated with this object.
This is 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]
- remove_coordinate_system()
Remove the coordinate system from the object.
This does not change the geometry of the object. It only clears the label which states what coordinate system the object is in.
This has no effect if the object does not have a coordinate system.
- remove_points(point_indices)
Remove one or more points from the object.
Calling this function is preferable to altering the points array because this function also removes the point properties associated with the removed points (e.g. point colours, point visibility, etc).
This operation is performed directly on the Project and will not be undone if an error occurs.
- Parameters:
point_indices (int | Sequence[int]) – The index of the point to remove or a list of indices of points to remove. Indices should only contain 32-bit unsigned integer (They should be greater than or equal to 0 and less than 2**32). Any index greater than or equal to the point count is ignored. Passing an index less than zero is not supported. It will not delete the last point.
- Returns:
If passed a single point index, True if the point was removed and False if it was not removed. If passed an iterable of point indices, True if the object supports removing points and False otherwise.
- Return type:
bool
- Raises:
ReadOnlyError – If called on an object not open for editing. This error indicates an issue with the script and should not be caught.
Warning
Any unsaved changes to the object when this function is called are discarded before any points are deleted. If you wish to keep these changes, call save() before calling this function.
Examples
Deleting a point through this function is preferable over removing the point from the points array because this function also deletes the properties associated with the deleted points. For example, all points will remain the same colour after the deletion operation, which points are visible will remain the same, etc. This is shown in the following script:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> red = [255, 0, 0, 255] >>> blue = [0, 0, 255, 255] >>> with project.new("cad/deletion_example", PointSet) as point_set: ... point_set.points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]] ... point_set.point_colours = [red, red, blue, blue] ... point_set.point_attributes["attribute"] = [0, 1, 2, 3] >>> with project.edit(point_set.id) as edit_set: ... edit_set.remove_points((1, 2)) ... print("points\n", edit_set.points) ... print("colours\n", edit_set.point_colours) ... print("attribute\n", edit_set.point_attributes["attribute"]) points [[0. 0. 0.] [1. 1. 0.]] colours [[255 0 0 255] [ 0 0 255 255]] attribute [0 3]
- 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().
- Returns:
The change reasons for the operation. This depends on what changes to the object were saved. If the api_version is less than 1.9, this always returns ChangeReasons.NO_CHANGE.
- Return type:
- save_edge_attribute(attribute_name, data)
Create and/or edit the values of the edge attribute attribute_name.
This is equivalent to Object.edge_attributes[attribute_name] = data
Saving an edge attribute using an AttributeKey allows for additional metadata to be specified.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
data (npt.ArrayLike) – An array_like of a base type data to store for the attribute per-primitive.
- 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.
- save_point_attribute(attribute_name, data)
Create and/or edit the values of the point attribute attribute_name.
This is equivalent to Object.point_attributes[attribute_name] = data.
Saving a point attribute using an AttributeKey allows for additional metadata to be specified.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
data (npt.ArrayLike) – An array_like of length point_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.
- 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[Union[NoneType, Type[NoneType], ctypes.c_bool, ctypes.c_byte, ctypes.c_ubyte, ctypes.c_short, ctypes.c_ushort, ctypes.c_long, ctypes.c_ulong, ctypes.c_longlong, ctypes.c_ulonglong, ctypes.c_float, ctypes.c_double, ctypes.c_char_p, datetime.datetime, datetime.date, bool, int, float, str]] | None) – 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.
ValueError – If name starts or ends with whitespace or is empty.
RuntimeError – If a different error occurs.
Notes
If an error occurs after adding a new object attribute or editing an existing object attribute resulting in save() not being called, the changes to the object attributes can only be undone if the application’s API version is 1.6 or greater.
Prior to mapteksdk 1.6: Adding new object attributes, or editing the values of object attributes, will not be undone if an error occurs.
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
- classmethod static_type()
Return the type of a topology as stored in a Project.
This can be used for determining if the type of an object is topology.
- class EdgeNetwork(object_id=None, lock_type=LockType.READWRITE)
Bases:
Edge
A network of potentially disconnected lines and polylines.
An edge network can contain multiple discontinuous lines/polylines in a single object. Unlike Polyline and Polygon, the user must explicitly set the edges.
See also
- edge-network
Help page for this class.
Examples
Creating an edge network with an edge between points 0 and point 1 and a second edge edge between points 2 and 3.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import EdgeNetwork >>> project = Project() >>> with project.new("cad/edges", EdgeNetwork) as new_network: >>> new_network.points = [[0, 0, 0], [1, 2, 3], [0, 0, 1], [0, 0, 2]] >>> new_network.edges = [[0, 1], [2, 3]]
- property id: ObjectID[EdgeNetwork]
Object ID that uniquely references this object in the project.
- Returns:
The unique id of this object.
- Return type:
- property edges: EdgeArray
A 2D Numpy array of edges of the form: [[i0, j0], [i1, j1], …, [iN, jN]] where N is the number of edges and all iK and jK are valid indices in Object.points.
Warning
For Surfaces the edges are derived from the points and facets. If any changes are made to the points or facets, the corresponding changes to the edges will not be made until save() has been called.
Notes
Invalid edges are removed during save().
- append_edges(*edges)
Append new edges to the end of the edges array.
Using this function is preferable to assigning to the edges array directly because it allows edges to be added to the object without any risk of changing existing edges by accident. The return value can also be used to assign edge properties for the new edges.
- Parameters:
edges – New edges to append to the array.
- Returns:
Boolean array which can be used to assign properties for the newly added edges.
- Return type:
BooleanArray
Examples
This function can be used to add a single edge to an object:
>>> edge_network: EdgeNetwork >>> # Add an edge between points 1 and 2. >>> edge_network.append_edges([1, 2])
Passing multiple edges can be used to append multiple edges at once:
>>> edge_network: EdgeNetwork >>> # Add an edge between points 0 and 2, another edge between points >>> # 1 and 2 and a third between points 2 and 3. >>> edge_network.append_edges([0, 2], [1, 2], [2, 3])
This function also accepts iterables of edges, which is useful for copying edges between objects. For example, the following function will copy all of the points and edges from one object into an EdgeNetwork.
>>> def concatenate_edge_networks( ... source_network: EdgeNetwork | Polygon | Polyline | Surface, ... destination_network: EdgeNetwork): ... '''Concatenate the points and edges of two edge networks. ... ... Parameters ... ---------- ... source_network ... Open object to read points and edges from. This can be ... any object with appropriately shaped points and edges. ... destination_network ... Edge network open for editing to add points and edges from ... source network to. ... ''' ... # Offset to add to edges to handle the new points having different ... # indices in the destination network. ... offset = destination_network.point_count ... destination_network.append_points(source_network.points) ... destination_network.append_edges( ... source_network.edges + offset ... )
The return value of this function can be used to assign edge properties to the newly added edges:
>>> edge_network: EdgeNetwork >>> # Add an edge between points 0 and 2, another edge between points >>> # 1 and 2 and a third between points 2 and 3. >>> new_edge_indices = edge_network.append_edges([0, 2], [1, 2], [2, 3]) >>> # Colour the three new edges blue, magenta and red. >>> edge_network.edge_colours[new_edge_indices] = [ ... [0, 0, 255, 255], [255, 0, 255, 255], [255, 0, 255]]
- remove_edges(edge_indices)
Remove one or more edges from the object.
Calling this function is preferable to altering the edges array because this function also removes the edge properties associated with the removed edges (e.g. edge colours, edge visibility, etc). Additionally, if after the removal of edges if any point is not part of any edge it will be removed as well.
This operation is performed directly on the Project and will not be undone if an error occurs.
- Parameters:
edge_indices (array_like or int) – The index of the edge to remove or a list of indices of edges to remove. Indices should only contain 32-bit unsigned integer (They should be greater than or equal to 0 and less than 2**32). Any index greater than or equal to the edge count is ignored. Passing an index less than zero is not supported. It will not delete the last edge.
- Returns:
If passed a single edge index, True if the edge was removed and False if it was not removed. If passed an iterable of edge indices, True if the object supports removing edges and False otherwise.
- Return type:
bool
- Raises:
ReadOnlyError – If called on an object not open for editing. This error indicates an issue with the script and should not be caught.
Warning
Any unsaved changes to the object when this function is called are discarded before any edges are deleted. If you wish to keep these changes, call save() before calling this function.
- classmethod static_type()
Return the type of edge network as stored in a Project.
This can be used for determining if the type of an object is an edge network.
- append_points(*points)
Append points to the object.
Using this function is preferable to assigning to the points array directly because it allows points to be added to the object without any risk of changing existing points by accident. The return value can also be used to assign point properties for the new points.
- Parameters:
points (Point) – Points to append to the object.
- Returns:
Boolean array which can be used to assign properties for the newly added points.
- Return type:
BooleanArray
- Raises:
AppendPointsNotSupportedError – If the object does not support appending points. This is raised for GridSurfaces, and non-new Scans.
Examples
This function can be used to add a single point to an object:
>>> point_set: PointSet >>> point_set.append_points([1.5, -1.5, 2.25])
Passing multiple points can be used to append multiple points at once:
>>> point_set: PointSet >>> point_set.append_points([3.1, 1.1, 4.1], [2.2, 7.2, 1.2])
This function also accepts iterables of points, so the following is functionally identical to the previous example:
>>> point_set: PointSet >>> point_set.append_points([[3.1, 1.1, 4.1], [2.2, 7.2, 1.2]])
The return value of this function can be used to assign point properties to the newly added points:
>>> point_set: PointSet >>> new_point_indices = point_set.append_points( ... [3.1, 1.1, 4.1], [2.2, 7.2, 1.2]) >>> # Colour the two new points blue and magenta. >>> point_set.point_colours[new_point_indices] = [ ... [0, 0, 255, 255], [255, 0, 255, 255]]
- 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))
- cancel()
Cancel any pending changes to the object.
This undoes all changes made to the object since it was opened (including any changes saved by save()) and then closes the object.
After this is called, attempting to read or edit any of the properties on this object (other than the id) will raise an ObjectClosedError.
- Raises:
ReadOnlyError – If the object was open for read only (i.e not for editing). It is not necessary to call this for a read only object as there will be no pending changes.
ObjectClosedError – If called on a closed object.
- close()
Closes the object and saves the changes to the Project.
Attempting to read or edit properties of an object after closing it will raise a ReadOnlyError.
- property closed: bool
If this object has been closed.
Attempting to read or edit a closed object will raise an ObjectClosedError. Such an error typically indicates an error in the script and should not be caught.
Examples
If the object was opened with the Project.new(), Project.edit() or Project.read() in a “with” block, this will be True until the with block is closed and False afterwards.
>>> with self.project.new("cad/point_set", PointSet) as point_set: >>> point_set.points = [[1, 2, 3], [4, 5, 6]] >>> print("closed?", point_set.closed) >>> print("closed?", point_set.closed) closed? False closed? True
- property coordinate_system: CoordinateSystem | None
The coordinate system the points of this object are in.
If the object has no coordinate system, this will be None.
- Raises:
ReadOnlyError – If set on an object open for read-only.
Warning
Setting this property does not change the points. This is only a label stating the coordinate system the points are in.
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: datetime
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_edge_attribute(attribute_name)
Delete an edge attribute.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
- delete_point_attribute(attribute_name)
Delete a point attribute by name.
This is equivalent to: point_attributes.delete_attribute(attribute_name)
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
- dissociate_raster(raster)
Removes the raster from the object.
If an error occurs after dissociating a raster resulting in save() not being called, the dissociation of the raster can only be undone if the application’s API version is 1.6 or greater.
Prior to mapteksdk 1.6: Dissociating a raster will not be undone if an error occurs.
- Parameters:
raster (Raster | ObjectID[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.
ReadOnlyError – If this object is open for read-only.
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 edge_attributes: PrimitiveAttributes
Access to custom edge attributes.
These are arrays of values of the same type, with one value for each edge.
Use Object.edge_attributes[attribute_name] to access the edge attribute called attribute_name. See PrimitiveAttributes for valid operations on edge attributes.
- Returns:
Access to the edge attributes.
- Return type:
- Raises:
ValueError – If the type of the attribute is not supported.
Warning
For Surfaces if you have changed the points or facets in the object, you must call save() before accessing the edge attributes.
- property edge_colours: ColourArray
The colours of the edges.
The edge colours are represented as a numpy array of RGBA colours, with one colour for each edge.
- property edge_count: int
The count of edges in the object.
- property edge_selection: BooleanArray
A 1D ndarray representing which edges are selected.
edge_selection[i] = True indicates edge i is selected.
- 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:
ObjectAttributeTypes
- 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:
ObjectAttributeDataTypes
- Raises:
KeyError – If there is no object attribute called name.
- get_colour_map()
Return the ID of the colour map object associated with this object.
- Returns:
The ID of the colour map object or null object ID if there is no colour map.
- Return type:
- property is_read_only: bool
If this object is read-only.
This will return True if the object was open with Project.read() and False if it was open with Project.edit() or Project.new(). Attempting to edit a read-only object will raise an error.
- property lock_type: LockType
Indicates whether operating in read-only or read-write mode.
Use the is_read_only property instead for checking if an object is open for reading or editing.
- Returns:
The type of lock on this object. This will be LockType.ReadWrite if the object is open for editing and LockType.Read if the object is open for reading.
- Return type:
LockType
- property modified_date: datetime
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 point_attributes: PrimitiveAttributes
Access the custom point attributes.
These are arrays of values of the same type, with one value for each point.
Use Object.point_attributes[attribute_name] to access the point attribute called attribute_name. See PrimitiveAttributes for valid operations on point attributes.
- Returns:
Access to the point attributes.
- Return type:
- Raises:
ValueError – If the type of the attribute is not supported.
- property point_colours: ColourArray
The colour of each point in RGBA.
This is a numpy array of shape (N, 4) where N is the point count.
Examples
To get the colour of the ith point:
>>> point_i_colour = point_set.point_colours[i]
To get the red, green, blue and alpha components of the ith point:
>>> red, green, blue, alpha = point_set.point_colours[i]
- property point_count: int
The number of points in this object.
- property point_selection: BooleanArray
An array which indicates which points have been selected.
This is an array of booleans of shape (N,) where N is the point count. If the ith element in this array is True, then the ith point is selected. If the ith element in this array is False, then the ith point is not selected.
Examples
To get if the ith point is selected:
>>> point_i_selected = point_set.point_selection[i]
The point selection can be used to filter the arrays of other per-point properties down to only include the values of selected points. The following snippet demonstrates getting the colours of only the selected points in an object:
>>> selected_colours = point_set.point_colours[point_set.point_selection]
- property point_visibility: BooleanArray
An array which indicates which points are visible.
This is an array of booleans of shape (N,) where N is the point count. If the ith element in this array is True, then the ith point is visible. If the ith element in this array is False, then the ith point is invisible.
Examples
To get if the ith point is visible:
>>> point_i_visible = point_set.point_visibility[i]
The point visibility can be used to filter the arrays of other per-point properties down to only include the values of visible points. The following snippet demonstrates getting the colours of only the visible points in an object:
>>> visible_colours = point_set.point_colours[point_set.point_visibility]
- property point_z: FloatArray
The Z coordinates of the points.
- Raises:
ValueError – If set using a string which cannot be converted to a float.
ValueError – If set to a value which cannot be broadcast to the right shape.
TypeError – If set using a value which cannot be converted to a float.
- property points: PointArray
The three dimensional points in the object.
This is a numpy array of shape (N, 3) where N is the point count. This is of the form: [[x1, y1, z1], [x2, y2, z2], …, [xN, yN, zN]]
To get the ith point:
>>> point_i = point_set.points[i]
Similarly, to get the x, y and z coordinates of the ith point:
>>> x, y, z = point_set.points[i]
- Raises:
AttributeError – If attempting to set the points on an object which does not support setting points.
Examples
Create a new point set and set the points:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() ... with project.new("cad/test_points", PointSet) as new_points: ... new_points.points = [[0, 0, 0], [1, 0, 0], [1, 1, 0], ... [0, 1, 0], [0, 2, 2], [0, -1, 3]]
Print the second point from the point set defined above.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: ... print(read_points.points[2]) [1., 1., 0.]
Then set the 2nd point to [1, 2, 3]:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.edit("cad/test_points") as edit_points: ... edit_points.points[2] = [1, 2, 3]
Iterate over all of the points and print them.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: >>> for point in read_points.points: >>> print(point) [0., 0., 0.] [1., 0., 0.] [1., 2., 3.] [0., 1., 0.] [0., 2., 2.] [0., -1., 3.]
Print all points with y > 0 using numpy. Note that index has one element for each point which will be true if that point has y > 0 and false otherwise. This is then used to retrieve the points with y > 0.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: ... index = read_points.points[:, 1] > 0 ... print(read_points.points[index]) [[1. 2. 3.] [0. 1. 0.] [0. 2. 2.]]
To add a new point to a PointSet, the numpy row_stack function can be used. This is demonstrated by the following example which creates a point set and then opens it for editing and adds an extra point. The original points are coloured blue and the new point is coloured red.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... with Project() as project: ... with project.new("cad/append_single_example", PointSet ... ) as point_set: ... point_set.points = [ ... [-1, -1, 0], [1, -1, 0], [-1, 1, 0], [1, 1, 0] ... ] ... point_set.point_colours = [0, 0, 255, 255] ... with project.edit(point_set.id) as edit_set: ... edit_set.points = np.row_stack((edit_set.points, [0, 0, 1])) ... edit_set.point_colours[-1] = [255, 0, 0, 255]
The row stack function can also be used to add multiple points to an object at once, as demonstrated in the following example:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... original_points = [[-1, -1, 1], [1, -1, 1], [-1, 1, 1], [1, 1, 1]] ... new_points = [[-1, -1, 2], [1, -1, 2], [-1, 1, 2], [1, 1, 2]] ... with Project() as project: ... with project.new("cad/append_multiple_example", PointSet ... ) as point_set: ... point_set.points = original_points ... point_set.point_colours = [0, 0, 255, 255] ... with project.edit(point_set.id) as edit_set: ... original_point_count = edit_set.point_count ... edit_set.points = np.row_stack((edit_set.points, new_points)) ... new_point_count = edit_set.point_count ... edit_set.point_colours[ ... original_point_count:new_point_count] = [255, 0, 0, 255]
The row stack function can combine more than two point arrays if required by adding additional arrays to the tuple passed to the function. This is demonstrated by the following example, which creates a new point set containing the points from the point sets in the previous two examples plus a third set of points defined in the script. Make sure to run the previous two examples before running this one.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... extra_points = [[-2, -2, 3], [2, -2, 3], [-2, 2, 3], [2, 2, 3]] ... with Project() as project: ... with project.new("cad/triple_point_stack", PointSet) as new_set, \ ... project.read("cad/append_single_example") as single_set, \ ... project.read("cad/append_multiple_example") as multiple_set: ... new_set.points = np.row_stack(( ... extra_points, ... single_set.points, ... multiple_set.points ... ))
- property rasters: dict[int, ObjectID[Raster]]
The raster associated with this object.
This is 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]
- remove_coordinate_system()
Remove the coordinate system from the object.
This does not change the geometry of the object. It only clears the label which states what coordinate system the object is in.
This has no effect if the object does not have a coordinate system.
- remove_points(point_indices)
Remove one or more points from the object.
Calling this function is preferable to altering the points array because this function also removes the point properties associated with the removed points (e.g. point colours, point visibility, etc).
This operation is performed directly on the Project and will not be undone if an error occurs.
- Parameters:
point_indices (int | Sequence[int]) – The index of the point to remove or a list of indices of points to remove. Indices should only contain 32-bit unsigned integer (They should be greater than or equal to 0 and less than 2**32). Any index greater than or equal to the point count is ignored. Passing an index less than zero is not supported. It will not delete the last point.
- Returns:
If passed a single point index, True if the point was removed and False if it was not removed. If passed an iterable of point indices, True if the object supports removing points and False otherwise.
- Return type:
bool
- Raises:
ReadOnlyError – If called on an object not open for editing. This error indicates an issue with the script and should not be caught.
Warning
Any unsaved changes to the object when this function is called are discarded before any points are deleted. If you wish to keep these changes, call save() before calling this function.
Examples
Deleting a point through this function is preferable over removing the point from the points array because this function also deletes the properties associated with the deleted points. For example, all points will remain the same colour after the deletion operation, which points are visible will remain the same, etc. This is shown in the following script:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> red = [255, 0, 0, 255] >>> blue = [0, 0, 255, 255] >>> with project.new("cad/deletion_example", PointSet) as point_set: ... point_set.points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]] ... point_set.point_colours = [red, red, blue, blue] ... point_set.point_attributes["attribute"] = [0, 1, 2, 3] >>> with project.edit(point_set.id) as edit_set: ... edit_set.remove_points((1, 2)) ... print("points\n", edit_set.points) ... print("colours\n", edit_set.point_colours) ... print("attribute\n", edit_set.point_attributes["attribute"]) points [[0. 0. 0.] [1. 1. 0.]] colours [[255 0 0 255] [ 0 0 255 255]] attribute [0 3]
- 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().
- Returns:
The change reasons for the operation. This depends on what changes to the object were saved. If the api_version is less than 1.9, this always returns ChangeReasons.NO_CHANGE.
- Return type:
- save_edge_attribute(attribute_name, data)
Create and/or edit the values of the edge attribute attribute_name.
This is equivalent to Object.edge_attributes[attribute_name] = data
Saving an edge attribute using an AttributeKey allows for additional metadata to be specified.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
data (npt.ArrayLike) – An array_like of a base type data to store for the attribute per-primitive.
- 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.
- save_point_attribute(attribute_name, data)
Create and/or edit the values of the point attribute attribute_name.
This is equivalent to Object.point_attributes[attribute_name] = data.
Saving a point attribute using an AttributeKey allows for additional metadata to be specified.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
data (npt.ArrayLike) – An array_like of length point_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.
- 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[Union[NoneType, Type[NoneType], ctypes.c_bool, ctypes.c_byte, ctypes.c_ubyte, ctypes.c_short, ctypes.c_ushort, ctypes.c_long, ctypes.c_ulong, ctypes.c_longlong, ctypes.c_ulonglong, ctypes.c_float, ctypes.c_double, ctypes.c_char_p, datetime.datetime, datetime.date, bool, int, float, str]] | None) – 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.
ValueError – If name starts or ends with whitespace or is empty.
RuntimeError – If a different error occurs.
Notes
If an error occurs after adding a new object attribute or editing an existing object attribute resulting in save() not being called, the changes to the object attributes can only be undone if the application’s API version is 1.6 or greater.
Prior to mapteksdk 1.6: Adding new object attributes, or editing the values of object attributes, will not be undone if an error occurs.
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
- class Polyline(object_id=None, lock_type=LockType.READWRITE)
Bases:
Edge
An ordered sequence of points connected by edges.
A polyline is formed from an ordered sequence of points, where edges are between consecutive points. For example, the first edge is from point 0 to point 1. The second edge is from point 1 to point 2 and so on.
This type is also known as a continuous unclosed line, edge chain or string.
- Raises:
DegenerateTopologyError – If the Polyline contains fewer than two points when save() is called.
See also
- polyline
Help page for this class.
Notes
The edges of a polyline object are implicitly defined by the points. The first edge is between point 0 and point 1, the second edge is between point 1 and point 2 and so on. Because the edges are derived in this way, editing the edges of a polyline is ambiguous and not supported. To change the edges, edit the points instead. If you need to edit or remove edges from a polyline, consider using an EdgeNetwork instead.
Examples
Create a c shape.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Polyline >>> project = Project() >>> with project.new("cad/c_shape", Polyline) as new_line: >>> new_line.points = [[1, 1, 0], [0, 1, 0], [0, 0, 0], [1, 0, 0]]
Create a square. Note that a Polygon would be more appropriate for creating a square as it would not require the last point.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Polyline >>> project = Project() >>> with project.new("cad/square", Polyline) as new_line: >>> new_line.points = [[0, 0, 0], [1, 0, 0], [1, 1, 0], >>> [0, 1, 0], [0, 0, 0]]
- property id: ObjectID[Polyline]
Object ID that uniquely references this object in the project.
- Returns:
The unique id of this object.
- Return type:
- property edges
A 2D Numpy array of edges of the form: [[i0, j0], [i1, j1], …, [iN, jN]] where N is the number of edges and all iK and jK are valid indices in Object.points.
Warning
For Surfaces the edges are derived from the points and facets. If any changes are made to the points or facets, the corresponding changes to the edges will not be made until save() has been called.
Notes
Invalid edges are removed during save().
- property edge_count
The count of edges in the object.
- classmethod static_type()
Return the type of polyline as stored in a Project.
This can be used for determining if the type of an object is a polyline.
- append_points(*points)
Append points to the object.
Using this function is preferable to assigning to the points array directly because it allows points to be added to the object without any risk of changing existing points by accident. The return value can also be used to assign point properties for the new points.
- Parameters:
points (Point) – Points to append to the object.
- Returns:
Boolean array which can be used to assign properties for the newly added points.
- Return type:
BooleanArray
- Raises:
AppendPointsNotSupportedError – If the object does not support appending points. This is raised for GridSurfaces, and non-new Scans.
Examples
This function can be used to add a single point to an object:
>>> point_set: PointSet >>> point_set.append_points([1.5, -1.5, 2.25])
Passing multiple points can be used to append multiple points at once:
>>> point_set: PointSet >>> point_set.append_points([3.1, 1.1, 4.1], [2.2, 7.2, 1.2])
This function also accepts iterables of points, so the following is functionally identical to the previous example:
>>> point_set: PointSet >>> point_set.append_points([[3.1, 1.1, 4.1], [2.2, 7.2, 1.2]])
The return value of this function can be used to assign point properties to the newly added points:
>>> point_set: PointSet >>> new_point_indices = point_set.append_points( ... [3.1, 1.1, 4.1], [2.2, 7.2, 1.2]) >>> # Colour the two new points blue and magenta. >>> point_set.point_colours[new_point_indices] = [ ... [0, 0, 255, 255], [255, 0, 255, 255]]
- 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))
- cancel()
Cancel any pending changes to the object.
This undoes all changes made to the object since it was opened (including any changes saved by save()) and then closes the object.
After this is called, attempting to read or edit any of the properties on this object (other than the id) will raise an ObjectClosedError.
- Raises:
ReadOnlyError – If the object was open for read only (i.e not for editing). It is not necessary to call this for a read only object as there will be no pending changes.
ObjectClosedError – If called on a closed object.
- close()
Closes the object and saves the changes to the Project.
Attempting to read or edit properties of an object after closing it will raise a ReadOnlyError.
- property closed: bool
If this object has been closed.
Attempting to read or edit a closed object will raise an ObjectClosedError. Such an error typically indicates an error in the script and should not be caught.
Examples
If the object was opened with the Project.new(), Project.edit() or Project.read() in a “with” block, this will be True until the with block is closed and False afterwards.
>>> with self.project.new("cad/point_set", PointSet) as point_set: >>> point_set.points = [[1, 2, 3], [4, 5, 6]] >>> print("closed?", point_set.closed) >>> print("closed?", point_set.closed) closed? False closed? True
- property coordinate_system: CoordinateSystem | None
The coordinate system the points of this object are in.
If the object has no coordinate system, this will be None.
- Raises:
ReadOnlyError – If set on an object open for read-only.
Warning
Setting this property does not change the points. This is only a label stating the coordinate system the points are in.
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: datetime
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_edge_attribute(attribute_name)
Delete an edge attribute.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
- delete_point_attribute(attribute_name)
Delete a point attribute by name.
This is equivalent to: point_attributes.delete_attribute(attribute_name)
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
- dissociate_raster(raster)
Removes the raster from the object.
If an error occurs after dissociating a raster resulting in save() not being called, the dissociation of the raster can only be undone if the application’s API version is 1.6 or greater.
Prior to mapteksdk 1.6: Dissociating a raster will not be undone if an error occurs.
- Parameters:
raster (Raster | ObjectID[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.
ReadOnlyError – If this object is open for read-only.
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 edge_attributes: PrimitiveAttributes
Access to custom edge attributes.
These are arrays of values of the same type, with one value for each edge.
Use Object.edge_attributes[attribute_name] to access the edge attribute called attribute_name. See PrimitiveAttributes for valid operations on edge attributes.
- Returns:
Access to the edge attributes.
- Return type:
- Raises:
ValueError – If the type of the attribute is not supported.
Warning
For Surfaces if you have changed the points or facets in the object, you must call save() before accessing the edge attributes.
- property edge_colours: ColourArray
The colours of the edges.
The edge colours are represented as a numpy array of RGBA colours, with one colour for each edge.
- property edge_selection: BooleanArray
A 1D ndarray representing which edges are selected.
edge_selection[i] = True indicates edge i is selected.
- 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:
ObjectAttributeTypes
- 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:
ObjectAttributeDataTypes
- Raises:
KeyError – If there is no object attribute called name.
- get_colour_map()
Return the ID of the colour map object associated with this object.
- Returns:
The ID of the colour map object or null object ID if there is no colour map.
- Return type:
- property is_read_only: bool
If this object is read-only.
This will return True if the object was open with Project.read() and False if it was open with Project.edit() or Project.new(). Attempting to edit a read-only object will raise an error.
- property lock_type: LockType
Indicates whether operating in read-only or read-write mode.
Use the is_read_only property instead for checking if an object is open for reading or editing.
- Returns:
The type of lock on this object. This will be LockType.ReadWrite if the object is open for editing and LockType.Read if the object is open for reading.
- Return type:
LockType
- property modified_date: datetime
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 point_attributes: PrimitiveAttributes
Access the custom point attributes.
These are arrays of values of the same type, with one value for each point.
Use Object.point_attributes[attribute_name] to access the point attribute called attribute_name. See PrimitiveAttributes for valid operations on point attributes.
- Returns:
Access to the point attributes.
- Return type:
- Raises:
ValueError – If the type of the attribute is not supported.
- property point_colours: ColourArray
The colour of each point in RGBA.
This is a numpy array of shape (N, 4) where N is the point count.
Examples
To get the colour of the ith point:
>>> point_i_colour = point_set.point_colours[i]
To get the red, green, blue and alpha components of the ith point:
>>> red, green, blue, alpha = point_set.point_colours[i]
- property point_count: int
The number of points in this object.
- property point_selection: BooleanArray
An array which indicates which points have been selected.
This is an array of booleans of shape (N,) where N is the point count. If the ith element in this array is True, then the ith point is selected. If the ith element in this array is False, then the ith point is not selected.
Examples
To get if the ith point is selected:
>>> point_i_selected = point_set.point_selection[i]
The point selection can be used to filter the arrays of other per-point properties down to only include the values of selected points. The following snippet demonstrates getting the colours of only the selected points in an object:
>>> selected_colours = point_set.point_colours[point_set.point_selection]
- property point_visibility: BooleanArray
An array which indicates which points are visible.
This is an array of booleans of shape (N,) where N is the point count. If the ith element in this array is True, then the ith point is visible. If the ith element in this array is False, then the ith point is invisible.
Examples
To get if the ith point is visible:
>>> point_i_visible = point_set.point_visibility[i]
The point visibility can be used to filter the arrays of other per-point properties down to only include the values of visible points. The following snippet demonstrates getting the colours of only the visible points in an object:
>>> visible_colours = point_set.point_colours[point_set.point_visibility]
- property point_z: FloatArray
The Z coordinates of the points.
- Raises:
ValueError – If set using a string which cannot be converted to a float.
ValueError – If set to a value which cannot be broadcast to the right shape.
TypeError – If set using a value which cannot be converted to a float.
- property points: PointArray
The three dimensional points in the object.
This is a numpy array of shape (N, 3) where N is the point count. This is of the form: [[x1, y1, z1], [x2, y2, z2], …, [xN, yN, zN]]
To get the ith point:
>>> point_i = point_set.points[i]
Similarly, to get the x, y and z coordinates of the ith point:
>>> x, y, z = point_set.points[i]
- Raises:
AttributeError – If attempting to set the points on an object which does not support setting points.
Examples
Create a new point set and set the points:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() ... with project.new("cad/test_points", PointSet) as new_points: ... new_points.points = [[0, 0, 0], [1, 0, 0], [1, 1, 0], ... [0, 1, 0], [0, 2, 2], [0, -1, 3]]
Print the second point from the point set defined above.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: ... print(read_points.points[2]) [1., 1., 0.]
Then set the 2nd point to [1, 2, 3]:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.edit("cad/test_points") as edit_points: ... edit_points.points[2] = [1, 2, 3]
Iterate over all of the points and print them.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: >>> for point in read_points.points: >>> print(point) [0., 0., 0.] [1., 0., 0.] [1., 2., 3.] [0., 1., 0.] [0., 2., 2.] [0., -1., 3.]
Print all points with y > 0 using numpy. Note that index has one element for each point which will be true if that point has y > 0 and false otherwise. This is then used to retrieve the points with y > 0.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: ... index = read_points.points[:, 1] > 0 ... print(read_points.points[index]) [[1. 2. 3.] [0. 1. 0.] [0. 2. 2.]]
To add a new point to a PointSet, the numpy row_stack function can be used. This is demonstrated by the following example which creates a point set and then opens it for editing and adds an extra point. The original points are coloured blue and the new point is coloured red.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... with Project() as project: ... with project.new("cad/append_single_example", PointSet ... ) as point_set: ... point_set.points = [ ... [-1, -1, 0], [1, -1, 0], [-1, 1, 0], [1, 1, 0] ... ] ... point_set.point_colours = [0, 0, 255, 255] ... with project.edit(point_set.id) as edit_set: ... edit_set.points = np.row_stack((edit_set.points, [0, 0, 1])) ... edit_set.point_colours[-1] = [255, 0, 0, 255]
The row stack function can also be used to add multiple points to an object at once, as demonstrated in the following example:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... original_points = [[-1, -1, 1], [1, -1, 1], [-1, 1, 1], [1, 1, 1]] ... new_points = [[-1, -1, 2], [1, -1, 2], [-1, 1, 2], [1, 1, 2]] ... with Project() as project: ... with project.new("cad/append_multiple_example", PointSet ... ) as point_set: ... point_set.points = original_points ... point_set.point_colours = [0, 0, 255, 255] ... with project.edit(point_set.id) as edit_set: ... original_point_count = edit_set.point_count ... edit_set.points = np.row_stack((edit_set.points, new_points)) ... new_point_count = edit_set.point_count ... edit_set.point_colours[ ... original_point_count:new_point_count] = [255, 0, 0, 255]
The row stack function can combine more than two point arrays if required by adding additional arrays to the tuple passed to the function. This is demonstrated by the following example, which creates a new point set containing the points from the point sets in the previous two examples plus a third set of points defined in the script. Make sure to run the previous two examples before running this one.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... extra_points = [[-2, -2, 3], [2, -2, 3], [-2, 2, 3], [2, 2, 3]] ... with Project() as project: ... with project.new("cad/triple_point_stack", PointSet) as new_set, \ ... project.read("cad/append_single_example") as single_set, \ ... project.read("cad/append_multiple_example") as multiple_set: ... new_set.points = np.row_stack(( ... extra_points, ... single_set.points, ... multiple_set.points ... ))
- property rasters: dict[int, ObjectID[Raster]]
The raster associated with this object.
This is 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]
- remove_coordinate_system()
Remove the coordinate system from the object.
This does not change the geometry of the object. It only clears the label which states what coordinate system the object is in.
This has no effect if the object does not have a coordinate system.
- remove_points(point_indices)
Remove one or more points from the object.
Calling this function is preferable to altering the points array because this function also removes the point properties associated with the removed points (e.g. point colours, point visibility, etc).
This operation is performed directly on the Project and will not be undone if an error occurs.
- Parameters:
point_indices (int | Sequence[int]) – The index of the point to remove or a list of indices of points to remove. Indices should only contain 32-bit unsigned integer (They should be greater than or equal to 0 and less than 2**32). Any index greater than or equal to the point count is ignored. Passing an index less than zero is not supported. It will not delete the last point.
- Returns:
If passed a single point index, True if the point was removed and False if it was not removed. If passed an iterable of point indices, True if the object supports removing points and False otherwise.
- Return type:
bool
- Raises:
ReadOnlyError – If called on an object not open for editing. This error indicates an issue with the script and should not be caught.
Warning
Any unsaved changes to the object when this function is called are discarded before any points are deleted. If you wish to keep these changes, call save() before calling this function.
Examples
Deleting a point through this function is preferable over removing the point from the points array because this function also deletes the properties associated with the deleted points. For example, all points will remain the same colour after the deletion operation, which points are visible will remain the same, etc. This is shown in the following script:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> red = [255, 0, 0, 255] >>> blue = [0, 0, 255, 255] >>> with project.new("cad/deletion_example", PointSet) as point_set: ... point_set.points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]] ... point_set.point_colours = [red, red, blue, blue] ... point_set.point_attributes["attribute"] = [0, 1, 2, 3] >>> with project.edit(point_set.id) as edit_set: ... edit_set.remove_points((1, 2)) ... print("points\n", edit_set.points) ... print("colours\n", edit_set.point_colours) ... print("attribute\n", edit_set.point_attributes["attribute"]) points [[0. 0. 0.] [1. 1. 0.]] colours [[255 0 0 255] [ 0 0 255 255]] attribute [0 3]
- 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().
- Returns:
The change reasons for the operation. This depends on what changes to the object were saved. If the api_version is less than 1.9, this always returns ChangeReasons.NO_CHANGE.
- Return type:
- save_edge_attribute(attribute_name, data)
Create and/or edit the values of the edge attribute attribute_name.
This is equivalent to Object.edge_attributes[attribute_name] = data
Saving an edge attribute using an AttributeKey allows for additional metadata to be specified.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
data (npt.ArrayLike) – An array_like of a base type data to store for the attribute per-primitive.
- 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.
- save_point_attribute(attribute_name, data)
Create and/or edit the values of the point attribute attribute_name.
This is equivalent to Object.point_attributes[attribute_name] = data.
Saving a point attribute using an AttributeKey allows for additional metadata to be specified.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
data (npt.ArrayLike) – An array_like of length point_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.
- 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[Union[NoneType, Type[NoneType], ctypes.c_bool, ctypes.c_byte, ctypes.c_ubyte, ctypes.c_short, ctypes.c_ushort, ctypes.c_long, ctypes.c_ulong, ctypes.c_longlong, ctypes.c_ulonglong, ctypes.c_float, ctypes.c_double, ctypes.c_char_p, datetime.datetime, datetime.date, bool, int, float, str]] | None) – 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.
ValueError – If name starts or ends with whitespace or is empty.
RuntimeError – If a different error occurs.
Notes
If an error occurs after adding a new object attribute or editing an existing object attribute resulting in save() not being called, the changes to the object attributes can only be undone if the application’s API version is 1.6 or greater.
Prior to mapteksdk 1.6: Adding new object attributes, or editing the values of object attributes, will not be undone if an error occurs.
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
- class Polygon(object_id=None, lock_type=LockType.READWRITE)
Bases:
Edge
An ordered and closed sequence of points connected by edges.
A polygon is formed from an ordered sequence of points, with edges between consecutive points. For example, the first edge is between point 0 and point 1, the second edge is between point 1 and point 2 and the final edge is between point N - 1 and point 0 (where N is the number of points). Unlike an Polyline, a Polygon is a closed loop of edges.
Also known as a closed line or edge loop.
See also
Edge
Parent class of Polygon
EdgeNetwork
Class which supports editing edges.
- polygon
Help page for this class.
Notes
The edges of a polygon are implicitly defined by the points. For a polygon with n edges, the first edge is between points 0 and 1, the second edge is between points 1 and 2, and the final edge is between points n - 1 and 0. Because the edges are derived from the points, editing the edges is not supported - you should edit the points instead. If you need to edit or remove edges without changing points consider using an EdgeNetwork instead.
- Raises:
DegenerateTopologyError – If the Polygon contains fewer than three points when save() is called.
Examples
Create a diamond
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Polygon >>> project = Project() >>> with project.new("cad/polygon_diamond", Polygon) as new_diamond: >>> new_diamond.points = [[1, 0, 0], [0, 1, 0], [1, 2, 0], [2, 1, 0]]
- property id: ObjectID[Polygon]
Object ID that uniquely references this object in the project.
- Returns:
The unique id of this object.
- Return type:
- property edges
A 2D Numpy array of edges of the form: [[i0, j0], [i1, j1], …, [iN, jN]] where N is the number of edges and all iK and jK are valid indices in Object.points.
Warning
For Surfaces the edges are derived from the points and facets. If any changes are made to the points or facets, the corresponding changes to the edges will not be made until save() has been called.
Notes
Invalid edges are removed during save().
- property edge_count
The count of edges in the object.
- classmethod static_type()
Return the type of polygon as stored in a Project.
This can be used for determining if the type of an object is a polygon.
- append_points(*points)
Append points to the object.
Using this function is preferable to assigning to the points array directly because it allows points to be added to the object without any risk of changing existing points by accident. The return value can also be used to assign point properties for the new points.
- Parameters:
points (Point) – Points to append to the object.
- Returns:
Boolean array which can be used to assign properties for the newly added points.
- Return type:
BooleanArray
- Raises:
AppendPointsNotSupportedError – If the object does not support appending points. This is raised for GridSurfaces, and non-new Scans.
Examples
This function can be used to add a single point to an object:
>>> point_set: PointSet >>> point_set.append_points([1.5, -1.5, 2.25])
Passing multiple points can be used to append multiple points at once:
>>> point_set: PointSet >>> point_set.append_points([3.1, 1.1, 4.1], [2.2, 7.2, 1.2])
This function also accepts iterables of points, so the following is functionally identical to the previous example:
>>> point_set: PointSet >>> point_set.append_points([[3.1, 1.1, 4.1], [2.2, 7.2, 1.2]])
The return value of this function can be used to assign point properties to the newly added points:
>>> point_set: PointSet >>> new_point_indices = point_set.append_points( ... [3.1, 1.1, 4.1], [2.2, 7.2, 1.2]) >>> # Colour the two new points blue and magenta. >>> point_set.point_colours[new_point_indices] = [ ... [0, 0, 255, 255], [255, 0, 255, 255]]
- 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))
- cancel()
Cancel any pending changes to the object.
This undoes all changes made to the object since it was opened (including any changes saved by save()) and then closes the object.
After this is called, attempting to read or edit any of the properties on this object (other than the id) will raise an ObjectClosedError.
- Raises:
ReadOnlyError – If the object was open for read only (i.e not for editing). It is not necessary to call this for a read only object as there will be no pending changes.
ObjectClosedError – If called on a closed object.
- close()
Closes the object and saves the changes to the Project.
Attempting to read or edit properties of an object after closing it will raise a ReadOnlyError.
- property closed: bool
If this object has been closed.
Attempting to read or edit a closed object will raise an ObjectClosedError. Such an error typically indicates an error in the script and should not be caught.
Examples
If the object was opened with the Project.new(), Project.edit() or Project.read() in a “with” block, this will be True until the with block is closed and False afterwards.
>>> with self.project.new("cad/point_set", PointSet) as point_set: >>> point_set.points = [[1, 2, 3], [4, 5, 6]] >>> print("closed?", point_set.closed) >>> print("closed?", point_set.closed) closed? False closed? True
- property coordinate_system: CoordinateSystem | None
The coordinate system the points of this object are in.
If the object has no coordinate system, this will be None.
- Raises:
ReadOnlyError – If set on an object open for read-only.
Warning
Setting this property does not change the points. This is only a label stating the coordinate system the points are in.
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: datetime
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_edge_attribute(attribute_name)
Delete an edge attribute.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
- delete_point_attribute(attribute_name)
Delete a point attribute by name.
This is equivalent to: point_attributes.delete_attribute(attribute_name)
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
- dissociate_raster(raster)
Removes the raster from the object.
If an error occurs after dissociating a raster resulting in save() not being called, the dissociation of the raster can only be undone if the application’s API version is 1.6 or greater.
Prior to mapteksdk 1.6: Dissociating a raster will not be undone if an error occurs.
- Parameters:
raster (Raster | ObjectID[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.
ReadOnlyError – If this object is open for read-only.
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 edge_attributes: PrimitiveAttributes
Access to custom edge attributes.
These are arrays of values of the same type, with one value for each edge.
Use Object.edge_attributes[attribute_name] to access the edge attribute called attribute_name. See PrimitiveAttributes for valid operations on edge attributes.
- Returns:
Access to the edge attributes.
- Return type:
- Raises:
ValueError – If the type of the attribute is not supported.
Warning
For Surfaces if you have changed the points or facets in the object, you must call save() before accessing the edge attributes.
- property edge_colours: ColourArray
The colours of the edges.
The edge colours are represented as a numpy array of RGBA colours, with one colour for each edge.
- property edge_selection: BooleanArray
A 1D ndarray representing which edges are selected.
edge_selection[i] = True indicates edge i is selected.
- 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:
ObjectAttributeTypes
- 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:
ObjectAttributeDataTypes
- Raises:
KeyError – If there is no object attribute called name.
- get_colour_map()
Return the ID of the colour map object associated with this object.
- Returns:
The ID of the colour map object or null object ID if there is no colour map.
- Return type:
- property is_read_only: bool
If this object is read-only.
This will return True if the object was open with Project.read() and False if it was open with Project.edit() or Project.new(). Attempting to edit a read-only object will raise an error.
- property lock_type: LockType
Indicates whether operating in read-only or read-write mode.
Use the is_read_only property instead for checking if an object is open for reading or editing.
- Returns:
The type of lock on this object. This will be LockType.ReadWrite if the object is open for editing and LockType.Read if the object is open for reading.
- Return type:
LockType
- property modified_date: datetime
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 point_attributes: PrimitiveAttributes
Access the custom point attributes.
These are arrays of values of the same type, with one value for each point.
Use Object.point_attributes[attribute_name] to access the point attribute called attribute_name. See PrimitiveAttributes for valid operations on point attributes.
- Returns:
Access to the point attributes.
- Return type:
- Raises:
ValueError – If the type of the attribute is not supported.
- property point_colours: ColourArray
The colour of each point in RGBA.
This is a numpy array of shape (N, 4) where N is the point count.
Examples
To get the colour of the ith point:
>>> point_i_colour = point_set.point_colours[i]
To get the red, green, blue and alpha components of the ith point:
>>> red, green, blue, alpha = point_set.point_colours[i]
- property point_count: int
The number of points in this object.
- property point_selection: BooleanArray
An array which indicates which points have been selected.
This is an array of booleans of shape (N,) where N is the point count. If the ith element in this array is True, then the ith point is selected. If the ith element in this array is False, then the ith point is not selected.
Examples
To get if the ith point is selected:
>>> point_i_selected = point_set.point_selection[i]
The point selection can be used to filter the arrays of other per-point properties down to only include the values of selected points. The following snippet demonstrates getting the colours of only the selected points in an object:
>>> selected_colours = point_set.point_colours[point_set.point_selection]
- property point_visibility: BooleanArray
An array which indicates which points are visible.
This is an array of booleans of shape (N,) where N is the point count. If the ith element in this array is True, then the ith point is visible. If the ith element in this array is False, then the ith point is invisible.
Examples
To get if the ith point is visible:
>>> point_i_visible = point_set.point_visibility[i]
The point visibility can be used to filter the arrays of other per-point properties down to only include the values of visible points. The following snippet demonstrates getting the colours of only the visible points in an object:
>>> visible_colours = point_set.point_colours[point_set.point_visibility]
- property point_z: FloatArray
The Z coordinates of the points.
- Raises:
ValueError – If set using a string which cannot be converted to a float.
ValueError – If set to a value which cannot be broadcast to the right shape.
TypeError – If set using a value which cannot be converted to a float.
- property points: PointArray
The three dimensional points in the object.
This is a numpy array of shape (N, 3) where N is the point count. This is of the form: [[x1, y1, z1], [x2, y2, z2], …, [xN, yN, zN]]
To get the ith point:
>>> point_i = point_set.points[i]
Similarly, to get the x, y and z coordinates of the ith point:
>>> x, y, z = point_set.points[i]
- Raises:
AttributeError – If attempting to set the points on an object which does not support setting points.
Examples
Create a new point set and set the points:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() ... with project.new("cad/test_points", PointSet) as new_points: ... new_points.points = [[0, 0, 0], [1, 0, 0], [1, 1, 0], ... [0, 1, 0], [0, 2, 2], [0, -1, 3]]
Print the second point from the point set defined above.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: ... print(read_points.points[2]) [1., 1., 0.]
Then set the 2nd point to [1, 2, 3]:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.edit("cad/test_points") as edit_points: ... edit_points.points[2] = [1, 2, 3]
Iterate over all of the points and print them.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: >>> for point in read_points.points: >>> print(point) [0., 0., 0.] [1., 0., 0.] [1., 2., 3.] [0., 1., 0.] [0., 2., 2.] [0., -1., 3.]
Print all points with y > 0 using numpy. Note that index has one element for each point which will be true if that point has y > 0 and false otherwise. This is then used to retrieve the points with y > 0.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> with project.read("cad/test_points") as read_points: ... index = read_points.points[:, 1] > 0 ... print(read_points.points[index]) [[1. 2. 3.] [0. 1. 0.] [0. 2. 2.]]
To add a new point to a PointSet, the numpy row_stack function can be used. This is demonstrated by the following example which creates a point set and then opens it for editing and adds an extra point. The original points are coloured blue and the new point is coloured red.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... with Project() as project: ... with project.new("cad/append_single_example", PointSet ... ) as point_set: ... point_set.points = [ ... [-1, -1, 0], [1, -1, 0], [-1, 1, 0], [1, 1, 0] ... ] ... point_set.point_colours = [0, 0, 255, 255] ... with project.edit(point_set.id) as edit_set: ... edit_set.points = np.row_stack((edit_set.points, [0, 0, 1])) ... edit_set.point_colours[-1] = [255, 0, 0, 255]
The row stack function can also be used to add multiple points to an object at once, as demonstrated in the following example:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... original_points = [[-1, -1, 1], [1, -1, 1], [-1, 1, 1], [1, 1, 1]] ... new_points = [[-1, -1, 2], [1, -1, 2], [-1, 1, 2], [1, 1, 2]] ... with Project() as project: ... with project.new("cad/append_multiple_example", PointSet ... ) as point_set: ... point_set.points = original_points ... point_set.point_colours = [0, 0, 255, 255] ... with project.edit(point_set.id) as edit_set: ... original_point_count = edit_set.point_count ... edit_set.points = np.row_stack((edit_set.points, new_points)) ... new_point_count = edit_set.point_count ... edit_set.point_colours[ ... original_point_count:new_point_count] = [255, 0, 0, 255]
The row stack function can combine more than two point arrays if required by adding additional arrays to the tuple passed to the function. This is demonstrated by the following example, which creates a new point set containing the points from the point sets in the previous two examples plus a third set of points defined in the script. Make sure to run the previous two examples before running this one.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> import numpy as np >>> if __name__ == "__main__": ... extra_points = [[-2, -2, 3], [2, -2, 3], [-2, 2, 3], [2, 2, 3]] ... with Project() as project: ... with project.new("cad/triple_point_stack", PointSet) as new_set, \ ... project.read("cad/append_single_example") as single_set, \ ... project.read("cad/append_multiple_example") as multiple_set: ... new_set.points = np.row_stack(( ... extra_points, ... single_set.points, ... multiple_set.points ... ))
- property rasters: dict[int, ObjectID[Raster]]
The raster associated with this object.
This is 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]
- remove_coordinate_system()
Remove the coordinate system from the object.
This does not change the geometry of the object. It only clears the label which states what coordinate system the object is in.
This has no effect if the object does not have a coordinate system.
- remove_points(point_indices)
Remove one or more points from the object.
Calling this function is preferable to altering the points array because this function also removes the point properties associated with the removed points (e.g. point colours, point visibility, etc).
This operation is performed directly on the Project and will not be undone if an error occurs.
- Parameters:
point_indices (int | Sequence[int]) – The index of the point to remove or a list of indices of points to remove. Indices should only contain 32-bit unsigned integer (They should be greater than or equal to 0 and less than 2**32). Any index greater than or equal to the point count is ignored. Passing an index less than zero is not supported. It will not delete the last point.
- Returns:
If passed a single point index, True if the point was removed and False if it was not removed. If passed an iterable of point indices, True if the object supports removing points and False otherwise.
- Return type:
bool
- Raises:
ReadOnlyError – If called on an object not open for editing. This error indicates an issue with the script and should not be caught.
Warning
Any unsaved changes to the object when this function is called are discarded before any points are deleted. If you wish to keep these changes, call save() before calling this function.
Examples
Deleting a point through this function is preferable over removing the point from the points array because this function also deletes the properties associated with the deleted points. For example, all points will remain the same colour after the deletion operation, which points are visible will remain the same, etc. This is shown in the following script:
>>> from mapteksdk.project import Project >>> from mapteksdk.data import PointSet >>> project = Project() >>> red = [255, 0, 0, 255] >>> blue = [0, 0, 255, 255] >>> with project.new("cad/deletion_example", PointSet) as point_set: ... point_set.points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]] ... point_set.point_colours = [red, red, blue, blue] ... point_set.point_attributes["attribute"] = [0, 1, 2, 3] >>> with project.edit(point_set.id) as edit_set: ... edit_set.remove_points((1, 2)) ... print("points\n", edit_set.points) ... print("colours\n", edit_set.point_colours) ... print("attribute\n", edit_set.point_attributes["attribute"]) points [[0. 0. 0.] [1. 1. 0.]] colours [[255 0 0 255] [ 0 0 255 255]] attribute [0 3]
- 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().
- Returns:
The change reasons for the operation. This depends on what changes to the object were saved. If the api_version is less than 1.9, this always returns ChangeReasons.NO_CHANGE.
- Return type:
- save_edge_attribute(attribute_name, data)
Create and/or edit the values of the edge attribute attribute_name.
This is equivalent to Object.edge_attributes[attribute_name] = data
Saving an edge attribute using an AttributeKey allows for additional metadata to be specified.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
data (npt.ArrayLike) – An array_like of a base type data to store for the attribute per-primitive.
- 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.
- save_point_attribute(attribute_name, data)
Create and/or edit the values of the point attribute attribute_name.
This is equivalent to Object.point_attributes[attribute_name] = data.
Saving a point attribute using an AttributeKey allows for additional metadata to be specified.
- Parameters:
attribute_name (str | AttributeKey) – The name or key of the attribute.
data (npt.ArrayLike) – An array_like of length point_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.
- 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[Union[NoneType, Type[NoneType], ctypes.c_bool, ctypes.c_byte, ctypes.c_ubyte, ctypes.c_short, ctypes.c_ushort, ctypes.c_long, ctypes.c_ulong, ctypes.c_longlong, ctypes.c_ulonglong, ctypes.c_float, ctypes.c_double, ctypes.c_char_p, datetime.datetime, datetime.date, bool, int, float, str]] | None) – 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.
ValueError – If name starts or ends with whitespace or is empty.
RuntimeError – If a different error occurs.
Notes
If an error occurs after adding a new object attribute or editing an existing object attribute resulting in save() not being called, the changes to the object attributes can only be undone if the application’s API version is 1.6 or greater.
Prior to mapteksdk 1.6: Adding new object attributes, or editing the values of object attributes, will not be undone if an error occurs.
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