mapteksdk.data.points module

This module contains data types where the distinguishing trait is the use of point primitives.

There is only one such data type at this time which is the PointSet.

class mapteksdk.data.points.PointSet(object_id=None, lock_type=<LockType.READWRITE: 2>)

Bases: mapteksdk.data.primitives.point_properties.PointProperties, mapteksdk.data.base.Topology

A pointset is a set of three dimensional points.

classmethod static_type()

Return the type of point set as stored in a Project.

This can be used for determining if the type of an object is a point set.

dataframe(save_changes=True, attributes=None)

Provides context managed representation of entire PointSet as a Pandas Dataframe.

Parameters
  • save_changes (bool) – If save_changes = False then any changes to the DataEngine will not be made to the point set. If save_changes = True (default) and the point set is opened for editing, all changes made to the dataframe will be made to the point set when the with block finishes. This is ignored if the point set is opened in read mode - in that case changes to the Dataframe will never be made to the point set.

  • attributes (iterable) – List of names of point properties to include as extra rows in the DataFrame. If None (default) all existing point properties are included in the Dataframe. For better performance, only include the point properties you want in the DataFrame.

Yields

pandas.DataFrame – DataFrame representing the PointSet. Columns include: [‘X’, ‘Y’, ‘Z’, ‘R’, ‘G’, ‘B’, ‘A’, ‘Visible’, ‘Selected’] Any primitive attributes included in the DataFrame are inserted after Selected.

Raises

KeyError – If attributes contains an attribute name which doesn’t exist.

Examples

Use pandas to hide all points with Z less than 15.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import PointSet
>>> project = Project()
>>> with project.new("cad/my_points", PointSet) as new_set:
...     new_set.points = [[1, 2, 3], [5, 5, 16], [-1, -6, -16]]
...     with new_set.dataframe() as frame:
...         frame.loc[frame.Z < 15, "Visible"] = False
>>>     print(new_set.point_visibility)
[False True False]

Calculate and print the mean ‘redness’ of points using pandas.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import PointSet
>>> project = Project()
>>> with project.new("cad/my_other_points", PointSet) as new_set:
...     new_set.points = [[1, 2, 3], [5, 5, 16], [-1, -6, -16]]
...     new_set.point_colours = [[100, 0, 0], [150, 0, 0], [200, 50, 50]]
>>> with project.read("cad/my_other_points") as read_set:
...     with read_set.dataframe() as frame:
...         print(frame.loc[:, 'R'].mean())
150.0

Populate a point property with if the x value of the point is negative or positive.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import PointSet
>>> project = Project()
>>> with project.new("cad/positive_points", PointSet) as new_set:
...     new_set.points = [[-1, 3, 9], [1, 4, -5], [-5, 2, 3]]
...     new_set.point_attributes['negative_x'] = [False] * 3
...     with new_set.dataframe() as frame:
...         frame.loc[frame.X < 0, 'negative_x'] = True
...         frame.loc[frame.X >= 0, 'negative_x'] = False
...     print(new_set.point_attributes['negative_x'])
[True False True]

When extracting the values of points as a pandas dataframe, you can set it to not save changes. This way you can make changes to the Dataframe without changing the original point set. In the below example, all points with red greater than or equal to 200 have their red set to zero in the dataframe and prints them. However when the with statement ends, the points are left unchanged - when the points colours are printed, they are the same as before the dataframe. Use this to work with a temporary copy of your data.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import PointSet
>>> project = Project()
>>> with project.new("cad/my_nice_points", PointSet) as new_set:
...     new_set.points = [[1, 2, 3], [5, 5, 16], [-1, -6, -16]]
...     new_set.point_colours = [[100, 0, 0], [150, 0, 0],
...                             [200, 50, 50], [255, 75, 5]]
...     with new_set.dataframe(save_changes=False) as frame:
...         frame.loc[frame.R >= 200, 'R'] = 0
...         print(frame.loc[:, 'R'])
...     print(new_set.point_colours)
0    100.0
1    150.0
2      0.0
Name: R, dtype: float64
[[100   0   0 255]
[150   0   0 255]
[200  50  50 255]]
save()

Saves the changes to the point primitives. This is called during save() of the inheriting object and should not be called manually.

Returns

True if successful.

Return type

bool

Raises

Exception – If in read-only mode.