Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiPoint.difference(Point) doesn't keep original order #696

Closed
GeorgySk opened this issue Apr 1, 2019 · 3 comments
Closed

MultiPoint.difference(Point) doesn't keep original order #696

GeorgySk opened this issue Apr 1, 2019 · 3 comments

Comments

@GeorgySk
Copy link

GeorgySk commented Apr 1, 2019

Simple example:

>>> from shapely.geometry import MultiPoint, Point
>>> points = MultiPoint([Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1)])
>>> points.wkt
'MULTIPOINT (0 0, 1 0, 1 1, 0 1)'
>>> bad_point = Point(1, 0)
>>> points.difference(bad_point).wkt
'MULTIPOINT (0 0, 0 1, 1 1)'

As you can see, removing a Point from a MultiPoint by using difference breaks the initial ordering. Expected output would be:

'MULTIPOINT (0 0, 1 1, 0 1)'

Is this a bug or by design? Docs don't say anything on this behaviour.

Shapely version: 1.6.4.post1, installed from conda.

@snorfalorpagus
Copy link
Member

This is a behaviour that is inherited from GEOS, the library that Shapely is a wrapper around.

I don't think this is a bug per se. It just isn't the way the algorithm that calculates the difference works. The two outputs are geometrically equivalent. I don't think the simple feature model places any significance on the order of parts in a collection.

Something explaining this could be added to the documentation. I'm not sure where the best place would be to add it though as this isn't something specific to the difference method.

@mwtoews
Copy link
Member

mwtoews commented Apr 1, 2019

See OGC 06-103r4 for simple feature access, §6.1.5 for MultiPoint:

The Points are not connected or ordered in any semantically important way (see the discussion at GeometryCollection).

So this indicates the behavior is by design. It's also the same behavior in JTS.

A similar object that preserves order is a [Multi]LineString, but the example would need to be processed differently.

@GeorgySk
Copy link
Author

GeorgySk commented Apr 2, 2019

Ok, I see. I think a word of warning that one shouldn't rely on preserving the order could be added in the end of the Collections section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants