Edge

An edge is a line segment between two points. As a result, all objects that contain edges also contain points. The SDK represents the edge as an array containing two items, with each item representing a point.

Accessing an Object’s Edges

The edges of any object are stored in its edges property. Because most edge-based objects contain multiple edges, the edges property is represented as a NumPy array. Each element of the array represents a single edge, which in turn is an array of the two point indices defining the edge.

An EdgeNetwork is the simplest edge-based spatial object. We can use it to illustrate how to store its edges with the example below.

from mapteksdk.project import Project
from mapteksdk.data import EdgeNetwork
import numpy
 
project = Project()
 
with project.new("cad/edge_network", EdgeNetwork) as network:
  network.points = [[-1, -1, 0], [1, -1, 0], [-1, 1, 0], [1, 1, 0],
                    [-1, 1.2, 0], [1, 1.2, 0]]
  network.edges = [[0, 1], [1, 2], [2, 3], [0, 3], [4, 5]]
  for i, edge in enumerate(network.edges):
    start = network.points[edge[0]]
    end = network.points[edge[1]]
    length = numpy.linalg.norm(end - start)
    print(f"Edge {i} goes from {start} to {end} and is {length} "
          "meters long")

In the example above, we create an EdgeNetwork with six points and five edges, and then print each edge out by accessing each point from the start of an edge to the end of an edge.

Manipulating an Object’s Edges

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

Name Description
edge_colours

Use this property to change the colour of an edge. The colour of each edge 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.

edge_count Use this property to get the total number of edges for an edge-based object. For example, you may want to preallocate NumPy arrays to the correct length. In this case, using edge_count is advised for performance reasons with very large objects.
edge_attributes Use this method to save or return custom edge attributes in an object. To set a particular edge attribute, you can use the notation edge_attributes[attribute_name] = data.
save_edge_attribute(attribute_name, data) Use this method to save an edge attribute and allocate data to it.
delete_edge_attribute(attribute_name) Use this method to delete an edge attribute.

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