Polylines

A polyline (also referred to simply as a line in some applications) is a open-ended line with one or more segments (edges) and two or more points. A Polyline object is composed by a sequence of ordered points, so you can manipulate the points array directly to adjust the line.

Basic creation and manipulation examples are provided below. For examples that work on colouring and attribute operations with edges, see EdgeNetwork for reference.

Polyline examples

Creating a polyline

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 will remove 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

This example will add 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 inserts a new point at the beginning of the points array to prepend it to the polyline above.

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))