mapteksdk.data.annotations module¶
This module contains annotation data types.
Currently this includes:
Text2D: Represents 2D text which always faces the view.
Text3D: Represents 3D text.
Marker: Can be used to represent a place, route or sign.
-
class
mapteksdk.data.annotations.
HorizontalAlignment
(value)¶ Bases:
enum.Enum
Enum used to represent the horizontal alignment options for 2D and 3D Text.
-
LEFT
= 0¶
-
CENTRED
= 1¶
-
RIGHT
= 2¶
-
-
class
mapteksdk.data.annotations.
VerticalAlignment
(value)¶ Bases:
enum.Enum
Enum used to represent the vertical alignment options for 2D and 3D text.
-
TOP
= 3¶
-
CENTRED
= 6¶
-
BOTTOM
= 4¶
-
-
class
mapteksdk.data.annotations.
FontStyle
(value)¶ Bases:
enum.Flag
Enum representing the possible font styles. This is a flag enum so the values can be combined via bitwise operators.
-
REGULAR
= 0¶ The Regular font style.
-
BOLD
= 1¶ The Bold font style.
-
ITALIC
= 2¶ The Italic font style.
-
-
class
mapteksdk.data.annotations.
Text
(object_id=None, lock_type=<LockType.READWRITE: 2>)¶ Bases:
mapteksdk.data.base.Topology
The abstract base class representing text at a fixed location in space. This class cannot be instantiated directly - use Text2D or Text3D instead.
- Parameters
object_id (ObjectID) – Object ID to use for this object. Default is None, indicating a new text object should be created.
lock_type (LockType) – The type of lock to place on the object once it has been created. Default is LockType.READWRITE which allows read and write access to the text.
-
property
text
¶ The text displayed by this object.
- Raises
TypeError – If you attempt to set the text to a non-string value.
-
property
size
¶ The size of the text. The default size is 16.
-
property
location
¶ Location of the text as point ([x,y,z]).
-
property
colour
¶ The colour of the text represented as an RGBA colour.
You can set the colour to be a RGB or greyscale colour - it will automatically be converted to RGBA.
-
property
vertical_alignment
¶ The vertical alignment of the text.
See the VerticalAlignment enum for valid values.
- Raises
TypeError – If attempting to set to a value which is not from the VerticalAlignment enum.
ValueError – If an unsupported vertical alignment is read from the DataEngine.
Examples
Setting 3D text to be center aligned.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Text3D, VerticalAlignment >>> project = Project() >>> with project.new("cad/centre", Text3D) as new_text_3d: ... new_text_3d.text = "Centre" ... new_text_3d.vertical_alignment = VerticalAlignment.CENTRED
-
property
horizontal_alignment
¶ The horizontal alignment of the text.
See the HorizontalAlignment enum for valid values.
- Raises
TypeError – If attempting to set to a value which is not from the HorizontalAlignment enum.
ValueError – If an unsupported horizontal alignment is read from the DataEngine.
Examples
Setting 3D text to be left aligned.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Text3D, HorizontalAlignment >>> project = Project() >>> with project.new("cad/left", Text3D) as new_text_3d: ... new_text_3d.text = "Left" ... new_text_3d.horizontal_alignment = HorizontalAlignment.LEFT
-
property
font_style
¶ The font style of the text.
See FontStyles enum for the possible values. Note that this is a flag enum and flags can be combined using the | operator.
- Raises
TypeError – If set to a value which is not a part of FontStyles.
Examples
Set text to be italic.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Text3D, FontStyle >>> project = Project() >>> with project.new("cad/italic", Text3D) as new_text: ... new_text.text = "This text is italic" ... new_text.font_style = FontStyle.ITALIC
Set text to be bold and italic.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Text3D, FontStyle >>> project = Project() >>> with project.new("cad/bolditalic", Text3D) as new_text: ... new_text.text = "This text is bold and italic" ... new_text.font_style = FontStyle.BOLD | FontStyle.ITALIC
Print if the text created in the above example is bold.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Text3D, FontStyle >>> project = Project() >>> with project.read("cad/bolditalic") as read_text: ... if read_text.font_style & FontStyle.BOLD: ... print("This text is bold.") This text is bold.
-
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().
-
class
mapteksdk.data.annotations.
Text2D
(object_id=None, lock_type=<LockType.READWRITE: 2>)¶ Bases:
mapteksdk.data.annotations.Text
Allows creation of text at a fixed location in space.
Examples
Creating a new 2D text object at the origin.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Text2D >>> project = Project() >>> with project.new("cad/text", Text2D) as new_text: >>> new_text.location = [0, 0, 0] >>> new_text.text = "Hello World"
Editing an existing 2D text object to be size 16 and magenta.
>>> from mapteksdk.project import Project >>> project = Project() >>> with project.edit("cad/text") as text: >>> text.colour = [255, 0, 255] >>> text.size = 16
-
classmethod
static_type
()¶ Return the type of 2D text as stored in a Project.
This can be used for determining if the type of an object is a 2D text.
-
classmethod
-
class
mapteksdk.data.annotations.
Text3D
(object_id=None, lock_type=<LockType.READWRITE: 2>)¶ Bases:
mapteksdk.data.annotations.Text
Allows creation of three dimensional text at a fixed location and size in space.
-
class
Facing
(value)¶ Bases:
enum.Enum
Enum representing the possible facing values for 3D text.
-
NO_FACING
= 0¶ The text will not be camera or viewer facing. Depending on the angle it is viewed from, it may be upsidedown, back-to-front or both.
-
CAMERA_FACING
= 1¶ The text will rotate to always face towards the camera. Regardless of the angle it is viewed at, the text will never be upsidedown or back-to-front.
This causes direction and up direction of the text to be ignored.
-
VIEWER_FACING
= 2¶ The text will automatically flip so that it never appears upsidedown. Viewer facing text can still be back-to-front.
-
-
classmethod
static_type
()¶ Return the type of 3D text as stored in a Project.
This can be used for determining if the type of an object is a 3D text.
-
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
direction
¶ The 3D direction vector of the text.
This is the direction vector from the start of the first character to the end of the last character.
-
property
up_direction
¶ The 3D direction vector of the text.
This is the direction vector from the bottom of the text to the top.
-
property
always_visible
¶ If the text will be visible through other objects.
If set to true, the 3D text will be visible with a faded out appearance when there are objects between the text and the view. This is False by default.
- Raises
TypeError – If set to a value which is not a bool.
-
property
facing
¶ Where the text will face.
By default this is Text3D.Facing.VIEWER_FACING which causes the text to never appear upside down, even when viewed from the back.
See the values of the Text3D.Facing enum for possible options.
- Raises
TypeError – If set to a value which is not Text3D.Facing.
Examples
Set text containing a smiley face to be always camera facing so that it will always be smiling even when viewed from the back.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Text3D >>> project = Project() >>> with project.new("cad/smile", Text3D) as new_text: ... new_text.text = ":)" ... new_text.facing = Text3D.Facing.CAMERA_FACING
-
class
-
class
mapteksdk.data.annotations.
Marker
(object_id=None, lock_type=<LockType.READWRITE: 2>)¶ Bases:
mapteksdk.data.base.Topology
Provides a visual representation for a sign. This can be used to mark locations.
- Parameters
object_id (ObjectID) – Object id to use for this object. Default is None, indicating a new 2D text object should be created.
lock_type (LockType) – The type of lock to place on the object once it has been created. Default is LockType.READWRITE which allows read and write access to the 2D text.
Examples
Create a red diamond-shaped Marker with white text at [1, 2, 3].
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Marker >>> project = Project() >>> with project.new("cad/diamond", Marker) as new_marker: >>> new_marker.text = "White" >>> new_marker.marker_colour = [255, 0, 0] >>> new_marker.text_colour = [255, 255, 255] >>> new_marker.shape = Marker.Shape.DIAMOND >>> new_marker.location = [1, 2, 3]
Rotate an existing marker by 45 degrees.
>>> import math >>> from mapteksdk.project import Project >>> project = Project() >>> with project.edit("cad/diamond") as marker: >>> marker.rotate_2d(math.radians(45))
-
class
Shape
(value)¶ Bases:
enum.IntEnum
Different shapes or styles that a marker can be.
A marker can have a custom shape where a Surface provides the shape.
-
A_FRAME_OPEN
= 0¶ This shape is similar to a crime scene evidence marker or a cleaning in progress sign with the name of the marker on both surfaces.
-
DIAMOND
= 1¶ An 8 facet diamond with the name appearing on all surfaces.
-
CUBE
= 2¶ A cube with name on all the sides excluding top and bottom.
-
VERTICAL_SIGN
= 3¶ A simple vertical billboard.
-
A_FRAME_SIGN
= 4¶ A triangular prism billboard similar to A_FRAME_OPEN but solid and placed on a pole.
-
THREE_SIDED_SIGN
= 5¶ A triangular prism billboard with the triangle in the XY plane
-
HORIZONTAL_SIGN
= 6¶ A billboard aligned with the XY plane.
-
ZEBRA_SCALE
= 7¶ A striped scale bar.
-
CHECKERED_SCALE
= 8¶ A scale bar in checkerboard pattern.
-
U_SCALE
= 9¶ A U-Shaped scale bar in uniform colour.
-
PRONE_HUMAN
= 10¶ A prone human shaped marker.
-
UPRIGHT_HUMAN
= 11¶ An upright human shaped marker with a pedestal.
-
COMPASS_ROSE
= 12¶ A 3D compass rose marker.
-
CUSTOM
= 255¶ The marker can be a custom shape set by providing a Surface to Marker.SetCustomShape().
-
-
classmethod
static_type
()¶ Return the type of marker as stored in a Project.
This can be used for determining if the type of an object is a marker.
-
get_properties
()¶ Load properties from the Project. This resets all properties back to their state when save() was last called, undoing any changes which have been made.
-
property
shape
¶ What shape the marker takes in a view. Must be from the Marker.Shape enum.
-
property
custom_shape_object
¶ The Surface to use for a custom marker shape.
-
property
text_colour
¶ The colour of the text on the marker, represented as an RGBA colour. Colour may be set to a RGB, RGBA or greyscale colour.
See also
marker_colour
The colour of the marker itself.
-
property
marker_colour
¶ The colour of the marker, represented as an RGBA colour (However when setting the colour you may use a greyscale or RGB colour).
See also
text_colour
The colour of the text on the marker.
Notes
marker.marker_colour = None will set the marker colour to the default yellow ([255, 255, 0, 255]).
Marker colour is currently ignored by markers with custom shapes, however it is intended to be implemented in the future.
The alpha value of the marker colour is currently ignored, though may be supported in the future. It is recommended to either set marker colour to be an RGB colour or to set the alpha value to 255.
-
property
location
¶ Position of the marker as a point ([x,y,z]).
-
property
rotation
¶ Returns the magnitude of the rotation of the Marker in radians.
This value is the total rotation of the Marker relative to its original position.
Notes
If the marker has been rotated in multiple axes, this will not be the sum of the rotations performed. For example, a rotation of 90 degrees around the X axis, followed by a rotation of 90 degrees around the Y axis corresponds to a single rotation of 120 degrees so this function would return (2 * pi) / 3 radians.
Use math.degrees(marker.rotation) to convert this to degrees.
-
rotate
(angle, axis)¶ Rotates the marker on the specified axis by the specified angle.
- Parameters
angle (float) – Angle in radians to rotate the marker by. Positive is clockwise, negative is anticlockwise (When looking in the direction of axis).
axis (Axis) – Enum representing which Axis to rotate around.
See also
rotate_2d
Simple 2D rotation. Use this for simple rotations.
Notes
To specify the angle in degrees, call the function like so: marker.rotate(math.radians(angle_in_degrees), axis)
-
set_rotation
(angle, axis)¶ Overwrites the existing rotation to be the specified rotation about the specified axis.
- Parameters
angle (float) – Angle in radians to rotate the marker by. Positive is clockwise, negative is anticlockwise.
axis (Axis) – Enum representing which Axis to rotate around.
Notes
To specify the angle in degrees, call the function like so: marker.set_rotation(math.radians(angle_in_degrees), axis)
-
rotate_2d
(angle)¶ Rotates the marker by angle radians in 2D.
- Parameters
angle (float) – Angle in radians to rotate the marker by. Positive is clockwise, negative is anticlockwise.
Notes
A 2D rotation of angle theta is equivalent to: rotate(theta, axis=Axis.Z).
To specify the angle in degrees, call the function like so: marker.rotate_2d(math.radians(angle_in_degrees))
-
set_rotation_2d
(angle)¶ Sets the rotation to be a simple 2D rotation.
Overrides the existing rotation with a 2D rotation. This is equivalent to the rotation which can be performed when creating or editing a marker in an application.
- Parameters
angle (float) – The angle to rotate the Marker to in radians. Positive is clockwise, negative is anticlockwise.
Notes
To specify the angle in degrees, call the function like so: marker.set_rotation_2d(math.radians(angle_in_degrees))
-
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().