question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ops.split behaviour on closed rings

See original GitHub issue

Hi,

This is a bit of a fringe use case, but I’m extracting parts of a polygon boundary by splitting at vertices. The boundary is a LineString, but obviously also closed and a ring (which differs from closed in that it is is both closed and not self-intersecting?). When fed a ring LineString shapely.ops.split() works given a MultiPoint or Point as a splitter, but the resulting number of parts is inconsistent, depending on the whether the splitting points happen to include the joining vertex for the closed boundary:

from shapely import geometry, ops
# examples where splitter doesn't contain joining vertex
poly = geometry.Polygon([(0,1),(1,0),(2,1),(1,2),(0,1)])
parts = ops.split(poly.boundary, geometry.MultiPoint([(1,0),(1,2)]))
len(parts) # 3
parts = ops.split(poly.boundary, geometry.Point((1,0)))
len(parts) # 2
# examples where splitter does contain joining vertex
poly = geometry.Polygon([(1,0),(2,1),(1,2),(0,1),(1,0)])
parts = ops.split(poly.boundary, geometry.MultiPoint([(1,0),(1,2)]))
len(parts) # 2
parts = ops.split(poly.boundary, geometry.Point((1,0)))
len(parts) # 1

I can see this isn’t simple - if you split a closed ring at a single point, then I guess the result depends on your definition of closed. If ‘closed’ means that the first and last vertex are coincident, then you shouldn’t be able to split a ring with a single point; if ‘closed’ is a separate attribute of the linestring, then it might make sense. With a multipoint, though, it would be more consistent to get back the same number of parts as points (assuming all the points fall on the boundary).

Operating system

Mac OS X 10.10.5

Shapely version and provenance

Python 3.6.4 installed using brew Shapely 1.6.4.post1 installed using pip

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
snorfalorpaguscommented, Sep 16, 2018

The shapely.ops.split function currently treats LineString and LinearRing geometries in the same way:

The coordinate sequence of a geometry is iterated over, testing each segment of the string for intersection with the splitting point(s). If an intersection is found a new object is appended to the result and the iteration continues. No special consideration is given to closed geometries. If a splitting point occurs on the first or last vertex (which may be the same location) it is considered not to have been split.

This works for a common use case: consider a LineString representing the GPS trace for a circular walk. Although the geometry is “closed” (i.e. it has the same start and end position) it does have a defined beginning and end. Splitting this geometry at a point somewhere along the walk should return two lines: before and after.

A LinearRing used to denote the boundary of a polygon is also closed. However the actual start and end points of the line are less meaningful. You have to start drawing the line somewhere, but the exact position isn’t really important. If you consider the ring to be continuous then splitting it with a single point isn’t meaningful either.

I think it sounds reasonable that split should treat LineStrings and LinearRings differently. The change should be quite small: for LinearRings the first and last geometry returned should be concatenated. If a ring is split with a single point a single geometry will be returned, but with a new start/end location. If users needed the old behaviour it’s easy to convert to a LineString first, e.g. split(LineString(ring), point).

Perhaps we should removed the bug tag? This feels more like a feature to me.

0reactions
davidormecommented, Oct 11, 2018

That makes sense: break is something you do to a LinearRing and the number of LineString features you get back does not include features either side of the arbitrary startpoint (unless the breaking feature intersects that point). Does that mean you can’t split a LinearRing?

I’ve got no strong opinions, but I think it makes sense to clarify the distinction.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Traffic Signal Timing Manual: Chapter 4 - Office of Operations
The ring identifies phases that may operate one after another and are typically conflicting phases organized in a particular order. For instance ...
Read more >
The Shapely User Manual — Shapely 2.0.0 documentation
A valid Polygon may not possess any overlapping exterior or interior rings. A valid MultiPolygon may not collect any overlapping polygons. Operations on...
Read more >
Close Your Rings - Apple Watch
Close the three Activity rings on your Apple Watch every day to live a ... Close your Move ring by hitting your personal...
Read more >
Influence of constitutive model in springback prediction using ...
For all tests, cutting and splitting operations were made at room temperature. It has to be noticed that the shape of the ring...
Read more >
Opening A Closed Split Ring - YouTube
Supply stores onlinehttp://www.georgiaseitz.com/ebay/store.htmlhttp://www.tattingcorner.com/http://www.hhtatting.com/
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found