mapteksdk.workflows.workflow_selection module¶
Module containing ConnectorType subclasses which are dependent on the data module of the Python SDK.
- class mapteksdk.workflows.workflow_selection.WorkflowSelection(selection_string)¶
Bases:
mapteksdk.workflows.connector_type.ConnectorType
Class representing a read-only list of ObjectIDs. Pass this to WorkflowArgumentParser.declare_input_connector() or WorkflowArgumentParser.declare_output_connector() for input or output connectors expecting a ‘Maptek Database Object’.
Iterating over this object will iterate over the ObjectIDs in the selection.
You should not access the contents of this object until after Project() has been called.
- Parameters
selection_string (str) – String representing the selection.
- Raises
OSError – If the contents are accessed before Project() has been called.
ValueError – If part of the selection cannot be converted to an ObjectID.
Warning
Ensure the ObjectIDs passed to this class are from the same project as is opened with Project() otherwise the ObjectIDs may refer to a completely different object.
Notes
This class does not support object paths which contain quotation marks or commas.
Examples
Script which takes a selection of objects and returns their centroid via a list output connector. This script would have one input connector “Selection” which accepts a selection. There is also one output connector “Centroid” which will be set to the centroid of all of the points in the objects in the selection. Note that this script does not honour point selection.
>>> from mapteksdk.project import Project >>> from mapteksdk.workflows import (WorkflowArgumentParser, ... WorkflowSelection, ... Point3DConnectorType) >>> import numpy as np >>> parser = WorkflowArgumentParser( ... description="Get the centroid of objects with points") >>> parser.declare_input_connector( ... "selection", ... WorkflowSelection, ... description="Objects to find the centroid of.") >>> parser.declare_output_connector( ... "Centroid", ... Point3DConnectorType, ... description="The centroid of the points in the objects.") >>> parser.parse_arguments() # Must call before Project(). >>> project = Project() # Must call before get_ids(). >>> sums = np.zeros(3) >>> count = 0 >>> for oid in parser["selection"]: ... with project.read(oid) as read_object: ... if not hasattr(read_object, "points"): continue ... sums += np.sum(read_object.points, axis=0) ... count += read_object.point_count >>> result = sums / count >>> parser.set_output("Centroid", result) >>> parser.flush_output()
- classmethod type_string()¶
The string representation of the type to report to the Workflow as the type for the Connector.
- Returns
String representation of the type to report to the workflow.
- Return type
str
- classmethod from_string(string_value)¶
Convert a string value from an input connector to the corresponding python type and returns it.
- Returns
The python representation of the string value.
- Return type
any
- Raises
TypeError – If string_value is not a supported type.
ValueError – If string_value is the correct type but an invalid value.
- classmethod to_json(value)¶
Converts the value to a json-serializable value.
This is used to convert python values to json values to be passed to the workflow for output connectors.
- Returns
Json serializable representation of value.
- Return type
json-serializable
- Raises
TypeError – If value is not a supported type.
ValueError – If value is the correct type but an invalid value.
- property ids¶
Return the IDs in the selection as a list. This must be called after Project() has been called. Object IDs only have meaning within a Project.
- Returns
ObjectIDs in the selection.
- Return type
list of ObjectID
- Raises
ValueError – If any string cannot be converted to an ObjectID.
OSError – If called before Project() is called.