My question is simple, but the solution might be very tricky. I have a collection of triangles, and I want to find their union. The triangles are given in the standard way: by a list of coordinate points (2 coordinates for each point) and a list of connections, where each line is a triangle given by the indices of its vertices:
points:
[ 15.02716923 81.72425842]
[ 21.42242702 79.91459549]
[ 24.87068939 79.0222168 ]
[ 29.25767326 77.96657562]
[ 34.07667923 76.65890503]
triangles:
7 8 9
8 18 20
8 20 10
8 10 9
9 10 11
9 11 108
I can very efficiently find the union using cascaded_union
:
import shapely.geometry as geometry
from shapely.ops import cascaded_union, polygonize
polys = [geometry.Polygon([[points[point, 0], points[point, 1]] for point in triangle]) for triangle in triangles]
result = cascaded_union (polys)
The problem is, this gives the coordinates of the resulting polygon. Whereas, I would like the circumference of result
as indices in the initial points
array. So far I have not found a way to do this. One way may be to write my own combining function which spits out the point indices instead of the coordinates themselves.