shapely / shapely/shapely

Small difference in polygon coords results in point intersection instead of polygon intersection

Open
#1,639 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

geos upstream bug
Dominant language
Python
Stars
4.5k
Forks
631
Avg merge
1d 11h
Merged PRs (30d)
10

Description

Expected behavior and actual behavior.

I have two polygons which are extremely similar to each other and I intersect them both with a third polygon. I expect the intersection to be a large polygon, but in one case I end up with a point.

Steps to reproduce the problem.

from shapely import wkt
from shapely.ops import orient

zone = wkt.loads('POLYGON ((79.57006468414316 227.16715306136757, 43.44048377114246 -7.28462320799008, 127.74283932445364 -13.587090929970145, 154.99848808655608 219.60419326741248, 79.57006468414316 227.16715306136757))')

geom_0 = wkt.loads('POLYGON ((127.74283932445364 -13.587090929970145, 43.44048377114247 -7.28462320799008, 54.329847263553376 63.37854389007508, 54.61818554266568 63.33040101339976, 135.62637080265046 53.862076963892896, 127.74283932445364 -13.587090929970145))')
geom_0.intersection(zone).wkt # outputs 'POINT (127.74283932445364 -13.587090929970145)'

# yet orienting geom_0 first, gives a polygon
orient(geom_0).intersection(zone).wkt # 'POLYGON ((127.74283932445364 -13.587090929970145, 43.44048377114247 -7.28462320799008, 54.329847263553376 63.37854389007508, 54.61818554266568 63.33040101339976, 135.62637080265046 53.862076963892896, 127.74283932445364 -13.587090929970145))'

# this geometry is almost exactly the same as geom_0
geom_1 = wkt.loads('POLYGON ((127.74283932445363 -13.587091019377114, 43.44048377114246 -7.284623297862709, 54.32984726350768 63.37854379976558, 54.61818554261504 63.33040092309082, 135.62637080259915 53.862076873508386, 127.74283932445363 -13.587091019377114))')
geom_1.intersection(zone).wkt # outputs 'POLYGON ((54.32984726350768 63.37854379976558, 54.61818554261504 63.33040092309082, 135.6263707922279 53.862076874720586, 127.74283932445364 -13.587090929970145, 43.440483784834306 -7.284623209013686, 54.32984726350768 63.37854379976558))'

# another observation
geom_0.intersection(zone) # is a point
zone.intersection(geom_0) # is a point

# but
zone.buffer(0).intersection(geom_0) # is a polygon
geom_0.buffer(0).intersection(zone) # is a point

Operating system

Debian 5.19.11

Shapely version and provenance

Shapely 1.8.2 installed with pip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported Python reproduction with Shapely 1.8.2 and compare intersection results for geom_0, geom_1, orient(geom_0), and the buffer(0) variants. Trace the polygon intersection entry point and add a regression test for the coordinate-sensitive case; done means equivalent valid inputs produce the expected polygon intersection consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.