mapteksdk.data.base module¶
The basic unit of data in a Project is an object (represented by the DataObject class).
Objects which are intended to be visualised, such as Surface, Polyline or Polygon, inherit from the Topology class.
For objects which contain other objects, see mapteksdk.data.containers.
-
exception
mapteksdk.data.base.
AlreadyClosedError
¶ Bases:
RuntimeError
Error raised when the user attempts to close a closed object.
-
class
mapteksdk.data.base.
Extent
(minimum, maximum)¶ Bases:
object
A multidimensional, axially-aligned “intervals” or “extents”.
This extent is bound to a volume in 3D space.
-
minimum
¶ Point representing minimum values in the form [x, y, z].
- Type
tuple
-
maximum
¶ Point representing maximum values in the form [x, y, z].
- Type
tuple
-
property
centre
¶ Returns the center of the extent.
- Returns
Point representing the center of the extent.
- Return type
point
-
property
length
¶ The length is the maximum of the X, Y or Z dimension.
- Returns
Maximum width of the extent.
- Return type
float
-
as_numpy
()¶ Returns the extent as a numpy array.
- Returns
The extent representing as a numpy array.
- Return type
np.array
-
-
class
mapteksdk.data.base.
DataObject
(object_id, lock_type)¶ Bases:
object
The basic unit of data in a Project.
Each object can be referenced (opened/loaded) from its ID, see ObjectID, Project.read() and Project.edit().
-
property
id
¶ Object ID that uniquely references this object in the project.
- Returns
The unique id of this object.
- Return type
-
property
lock_type
¶ Indicates whether operating in read-only or read-write mode.
- Returns
The type of lock.
- Return type
LockType
-
close
()¶ Closes the object. This should be called as soon as you are finished working with an object. To avoid needing to remember to call this function, open the object using a with block and project.read(), project.new() or project.edit(). Those functions automatically call this function at the end of the with block.
A closed object cannot be used for further reading or writing. The ID of a closed object may be queried and this can then be used to re-open the object.
- Raises
AlreadyClosedError – If the object has already been closed.
-
property
created_date
¶ The date and time (in UTC) of when this object was created.
- Returns
The date and time the object was created. 0:0:0 1/1/1970 if the operation failed.
- Return type
datetime.datetime
-
property
modified_date
¶ The date and time (in UTC) of when this object was last modified.
- Returns
The date and time this object was last modified. 0:0:0 1/1/1970 if the operation failed.
- Return type
datetime.datetime
-
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 to set the value for.
dtype (type) – The type of data to assign to the attribute. This should be a type from the ctypes module or datetime.datetime or datetime.date. Passing bool is equivalent to passing ctypes.c_bool. Passing str is equivalent to passing ctypes.c_char_p. Passing int is equivalent to passing ctypes.c_int16. Passing float is equivalent to passing ctypes.c_double.
data (any) – The value to assign to object attribute name. For dtype = datetime.datetime this can either be a datetime object or timestamp which will be passed directly to datetime.utcfromtimestamp(). For dtype = datetime.date this can either be a date object or a tuple of the form: (year, month, day).
- Raises
ValueError – If dtype is an unsupported type.
TypeError – If value is an inappropriate type for object attribute name.
RuntimeError – If a different error occurs.
Warning
This is performed directly on the Project - this means that any changes made by this function (assuming it does not raise an error) will be saved even if save() is not called (for example, due to an error being raised by another function).
Examples
Create an object attribute on an object at “target” and then read its value.
>>> import ctypes >>> from mapteksdk.project import Project >>> project = Project() >>> with project.edit("target") as edit_object: ... edit_object.set_attribute("count", ctypes.c_int16, 0) ... with project.read("target") as read_object: ... print(read_object.get_attribute("count")) 0
-
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))
-
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.
- Return type
any
- Raises
KeyError – If there is no object attribute called name.
-
get_attribute_type
(name)¶ Returns the type of the attribute with the specified name.
- Parameters
name (str) – Name of the attribute to return the type of.
- Returns
The type of the object attribute called name.
- Return type
type
- Raises
KeyError – If there is no object attribute called name.
-
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 nonexistent 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.
-
property
-
class
mapteksdk.data.base.
Topology
(object_id, lock_type)¶ Bases:
mapteksdk.data.base.DataObject
Base class for “geometric objects” in a Project.
- This object is best thought of as the union of the following:
An arrangement of topological “primitives” including their location in space (known as their geometry).
The connectivity relationships between them (known as their topology).
The properties applied to them.
A given geometric object may contain any number of any of the six basic primitives: points, edges, facets (triangles), tetras (4 sided polyhedra), cells (squares or rectangles) and blocks (cubes or rectangular boxes). However, derived classes typically enforce constraints on the type and number of each primitive allowed in objects of their type. For example an edge chain will have points and edges but not facets.
-
close
()¶ Closes the object and saves the changes to the DataEngine, preventing any further changes.
-
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.
-
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().
-
property
extent
¶ The axes aligned bounding extent of the object.
-
get_colour_map
()¶ Return the ID of the colour map object currently associated with this object.
- Returns
The ID of the colour map object or null object ID if there is no colour map.
- Return type
-
property
rasters
¶ A dictionary of raster indices and Object IDs of the raster images currently associated with this object.
The keys are the raster ids and the values are the Object IDs of the associated rasters. Note that all raster ids are integers however they may not be consecutive - for example, an object may have raster ids 0, 1, 5 and 200.
Notes
Rasters with higher indices appear on top of rasters with lower indices. The maximum possible raster id is 255.
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]