Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. from shapely.geometry import LineString
  2. line1 = LineString([(0, 0), (2, 2),(3,1)])
  3. line2 = LineString([(2, 0), (2, 1),(1,2)])
  4. print line1.intersection(line2)
  5. POINT (1.5 1.5)
  6. for line in line1.union(line2):
  7. print line
  8. LINESTRING (0 0, 1.5 1.5)
  9. LINESTRING (1.5 1.5, 2 2, 3 1)
  10. LINESTRING (2 0, 2 1, 1.5 1.5)
  11. LINESTRING (1.5 1.5, 1 2)
  12.  
  13. # or
  14. from shapely.ops import unary_union
  15. for line in unary_union([line1,line2]):
  16. print line
  17. LINESTRING (0 0, 1.5 1.5)
  18. LINESTRING (1.5 1.5, 2 2, 3 1)
  19. LINESTRING (2 0, 2 1, 1.5 1.5)
  20. LINESTRING (1.5 1.5, 1 2)
  21.  
  22. from shapely.ops import linemerge
  23. new_line1 = linemerge([line.union(line2)[0],line.union(line2)[1]])
  24. new_line2 = linemerge([line.union(line2)[2],line.union(line2)[3]])
  25. print new_line1
  26. LINESTRING (0 0, 1.5 1.5, 2 2, 3 1)
  27. print new_line2
  28. LINESTRING (2 0, 2 1, 1.5 1.5, 1 2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement