Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge 2 Shapely objects?

I try to merge two Shapely Objects in my Python Project. There is a sort of kind of manual that describes some features of Shapely such as cascaded_union() but I that only works for Polygons. The shapely.ops.unary_union() method should work for other geometries as well but I can't get it to work.

In a nutshell: how do I merge 2 LinearRing Objects?

like image 776
Martin Fake Avatar asked Nov 29 '12 17:11

Martin Fake


1 Answers

I actually solved the problem myself.

p1 = Polygon(ring.coords) 
p2 = Polygon(ring2.coords)

to make polygons from my rings. then I create an array with those polygons. merge them with cascaded_union and create a LinearRing from the new polygon.

pols = [p1, p2] 
new_pol = ops.cascaded_union(pols) 
new_ring = LinearRing(new_pol.exterior.coords)
like image 100
Martin Fake Avatar answered Sep 21 '22 13:09

Martin Fake