Point

A point is a single location in space. The SDK represents a single point as an array containing three items — the X, Y and Z coordinates.

Accessing an Object’s Points

The points of any object are stored in its points property. Because most point-based objects contain multiple points, the points property is represented as a two-dimensional NumPy (a Python Library) array. A single point is stored in an array of three elements, representing the X, Y and Z ordinates, respectively. A points array is then an array of point arrays.

A PointSet is the most simple type of point-based spatial object.

from mapteksdk.project import Project
from mapteksdk.data import PointSet
 
project = Project()
 
with project.new("cad/points", PointSet) as new_points:
    new_points.points = [[-1, -1, 0], [1, -1, 0], [-1, 1, 0], [1, 1, 0]]

In the example above, we create a PointSet containing four points in a square shape in the XY plane.

As the Maptek Python SDK leverages the NumPy library, we can use numpy indexing to access points as illustrated below.

from mapteksdk.project import Project
from mapteksdk.data import PointSet
 
project = Project()
 
with project.new("cad/points", PointSet) as point_set:
    point_set.points = [[-1, -1, 0], [1, -1, 0], [-1, 1, 0], [1, 1, 0]]
 
    print("First point: ", point_set.points[0])
    print("Last point: ", point_set.points[-1])
    print("X of point 1: ", point_set.points[1, 0])
    print("Y of point 2: ", point_set.points[2, 1])
    print("Z of point 0: ", point_set.points[0, 2])
    print("X coordinates: ", point_set.points[:, 0])
    print("Y coordinates: ", point_set.points[:, 1])
    print("Z coordinates: ", point_set.point_z)
    # point_set.points[:, 2] will also give the z coordinates.

Manipulating an Object's Points

Use the following properties/methods to manipulate the points of an object:

Name Description
point_z Use this property to change the z-coordinate of a point.
point_colours

Use this property to change the colour of a point. The colour of each point is represented by an array containing four values [R, G, B, A] where:

  • R, G and B are each values between 0 and 255.

  • A is a value between 0 and 255 where 0 represents full transparency and 255 represents no transparency.

point_visibility Use this boolean property to make a point visible or invisible.
point_selection Use this property to select a group of points.
point_count Use this property to count the number of points in an object.
remove_points(point_indices, update_immediately) Use this method to remove a set of points from an object. This method takes two parameters: an array of point indices and a boolean value indicating whether the project updates immediately or not.
point_attributes Use this method to save or return custom point attributes in an object. To set a particular point attribute, you can use the notation point_attributes[attribute_name] = data.
save_point_attribute(attribute_name, data) Use this method to save a point attribute and allocate data to it.

There is one method that can be applied to any point-based object — the dataframe method. It returns the following values:

  • The X, Y and Z coordinates of each point

  • The R, G, B and A values of each point

  • The point visibility of each point

  • The point selection of each point

  • Point primitive attributes

Here is a code example:

from mapteksdk.project import Project
from mapteksdk.project import PointSet
project = Project() # Connect to default project
 
 
point_path = "scrapbook/my_points"
 
 
#1. Create points
with project.new(point_path, PointSet, overwrite=True) as points:
    points.points = [[0, 1, 0], [0.5, 1, 0.5], [1, 1, 0],
                     [0, 0.5, 0.5], [0.5, 0.5, 1], [1, 0.5, 0.5],
                     [0, 0, 0], [0.5, 0, 0.5], [1, 0, 0]]
    points:PointSet
    #2. Print frame values
    with points.dataframe(save_changes=False) as frame:
        print(frame)

If you run this code, you should be able to print the following information:

While facet-based and cell-based objects are also point-based, only PointSets are purely based on point primitive types. To learn more about PointSets, click here.

You can read more about the Point primitive class in the class references.