Polylines
A polyline (also referred to simply as a line in some applications) is an open-ended line consisting of one or more segments (edges) and at least two points. A Polyline object is composed of a sequence of ordered points, allowing direct manipulation of the points array to adjust the line.
Polyline examples
The following examples demonstrate how to create and manipulate polylines, including operations such as removing, appending, and prepending points to adjust the line’s shape. For examples involving colouring and attribute operations on edges, see Edge Networks.
Creating a polyline
The following example demonstrates how to create a new Polyline object from an array of points.
from mapteksdk.project import Project from mapteksdk.data import Polyline import numpy as np proj = Project() # Connect to default project with proj.new("/cad/zigzag line", Polyline, overwrite=True) as zigzag: # Create a green zigzag line zigzag.points = np.array([[0, 0, 0], [10, 10, 0], [20, 0, 0], [30, 10, 0], [40, 0, 0], [50, 10, 0]]) zigzag.point_colours = [0,255,0,255]
Removing points from a polyline
This example removes the second and third segment from the polyline created above. Since a Polyline object will automatically join the sequence of points together, removing the point at index 2 would result in the desired outcome.
from mapteksdk.project import Project project = Project() # Connect to default project path = "/cad/zigzag line" if project.find_object(path): with project.edit(path) as zigzag: zigzag.remove_points(2) else: print("Create a Polyline in '{}' first.".format(path))
Appending points to a polyline
The following example adds a point to the end of the line created above, offset 50 m north from the last point.
from mapteksdk.project import Project from mapteksdk.data import Polyline import numpy as np proj = Project() # Connect to default project path = "/cad/zigzag line" if proj.find_object(path): with proj.edit(path) as zigzag: # Append a point which is 30m in the y direction from the final point. zigzag.append_points(zigzag.points[-1] + [0, 30, 0]) else: print(f"Create a Polyline in '{path}' first.")
Prepending points to a polyline
This example demonstrates how to insert a new point at the beginning of an existing polyline's points array, effectively extending the line at the start.
from mapteksdk.project import Project import numpy as np project = Project() # Connect to default project path = "/cad/zigzag line" if project.find_object(path): with project.edit(path) as zigzag: first_point = zigzag.points[0] # Add 30 in the Y direction from the first point ([[50, 10, 0]]) first_point = np.add(first_point, np.array([0, 30, 0])) # Append the new point zigzag.points = np.append([first_point], zigzag.points, axis=0) else: print("Create a Polyline in '{}' first.".format(path))