Discussion:
[Community] Shapely: LinearRing intersections with polygons
Fabien
2015-01-20 09:09:15 UTC
Permalink
Hi All,

LinearRing behaves differently when interecting at the "junction point",
from shapely.geometry import *
coords = [(1,1), (0,1), (0,2), (1,2), (3,2), (3,1), (1,1)]
print(Point(1.0, 1.0).buffer(0.4).intersection(LinearRing(coords)))
MULTILINESTRING ((1 1, 0.6 1), (1.4 1, 1 1))

These are the two "sides" of the junction.
print(Point(2.0, 2.0).buffer(0.4).intersection(LinearRing(coords)))
LINESTRING (1.6 2, 2.4 2)

Is this a bug or is it expected? What makes me think it is a bug is that
print(Point(1.0, 1.0).buffer(0.4).intersection(Polygon(coords)))
POLYGON ((0.6 ...

Any idea? Thanks!

Fabien
Harasty, Daniel J
2015-01-20 13:54:44 UTC
Permalink
Just one opinion:

I agree that what you describe is [philosophically] "wrong". It is understandable if the LinearRing is implemented (under the covers) as a LineString that has the same point as both endpoints.

But, topologically, the LinearRing is NOT that; it has no "boundary", just and interior and an exterior.

Other thoughts?

Fabien: as a quick fix, I think you might be able to use shapely.ops.linemerge() or shapely.ops.cascaded_union().



-----Original Message-----
From: community-***@lists.gispython.org [mailto:community-***@lists.gispython.org] On Behalf Of Fabien
Sent: Tuesday, January 20, 2015 4:09 AM
To: ***@lists.gispython.org
Subject: [Community] Shapely: LinearRing intersections with polygons

Hi All,
from shapely.geometry import *
coords = [(1,1), (0,1), (0,2), (1,2), (3,2), (3,1), (1,1)] >>> print(Point(1.0, 1.0).buffer(0.4).intersection(LinearRing(coords)))
MULTILINESTRING ((1 1, 0.6 1), (1.4 1, 1 1))

These are the two "sides" of the junction.
print(Point(2.0, 2.0).buffer(0.4).intersection(LinearRing(coords)))
LINESTRING (1.6 2, 2.4 2)
print(Point(1.0, 1.0).buffer(0.4).intersection(Polygon(coords)))
POLYGON ((0.6 ...

Any idea? Thanks!

Fabien
Fabien
2015-01-20 17:21:57 UTC
Permalink
Hi Daniel,

thanks for your quick Answer. "topologically", I agree, but LinearRings
are then only "rings" in some cases (on a graphical representation for
example when the ring is closed) and are not closed in other (my use
case here).

Given the circumstances, I tend to agree that changing Shapely's
behaviour may be too much. Maybe add something in the doc?

Thanks for the fix, I was able to get my workflow to run.

Fabien

Loading...