Polyline
A Polyline
(also referred to as a line in some applications) is a open-ended line with one or more segments (edges) and two or more points. A Polyline
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
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 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: 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: last_point = zigzag.points[zigzag.point_count-1] # Add 30 in the Y direction from the last point ([[50, 10, 0]]) last_point = np.add(last_point, np.array([0, 30, 0])) # Append the new point zigzag.points = np.append(zigzag.points, [last_point], axis=0) else: print("Create a Polyline in '{}' first.".format(path))
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 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: 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))