Curriculum
Course: SCIPY
Login
Text lesson

SciPy Spatial Data

Working with Spatial Data

Spatial data refers to data represented in a geometric space, such as points on a coordinate system. We encounter spatial data problems in various tasks, such as determining whether a point lies inside a boundary. SciPy offers the scipy.spatial module, which includes functions for working with spatial data.

Triangulation

A triangulation of a polygon involves dividing the polygon into multiple triangles, allowing us to compute the polygon’s area. Triangulation with points refers to creating a surface of triangles where each given point is a vertex of at least one triangle. One method for generating such triangulations using points is the Delaunay() Triangulation.

Example

Generate a triangulation from the following points:

import numpy as np
from scipy.spatial import Delaunay
import matplotlib.pyplot as plt

points = np.array([
  [24],
  [34],
  [30],
  [22],
  [41]
])

simplices = Delaunay(points).simplices

plt.triplot(points[:, 0], points[:, 1], simplices)
plt.scatter(points[:, 0], points[:, 1], color=‘r’)

plt.show()

Result:

scipy_spatial_delaunay

Note: The simplices property generalizes the concept of a triangle notation.