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

shape/make_valid consistency #2051

Open
gmakarowski-yara opened this issue May 13, 2024 · 0 comments
Open

shape/make_valid consistency #2051

gmakarowski-yara opened this issue May 13, 2024 · 0 comments

Comments

@gmakarowski-yara
Copy link

Expected behavior and actual behavior.

Consider the following examples:

from shapely.geometry import mapping, shape
from shapely.validation import explain_validity, make_valid
import numpy as np
g = {
    'type': 'Polygon',
    'coordinates': [[[30.0, 10.0, np.NaN], [40.0, 40.0, np.Inf], [20.0, 40.0], [10.0, 20.0],
                     [30.0, 10.0]]]
}
s = shape(g)

Result:

ValueError: Inconsistent coordinate dimensionality
g = {
    'type': 'LineString',
    'coordinates': [[30.0, 10.0, np.NaN], [40.0, 40.0, np.Inf]]
}
s = shape(g)
make_valid(s)

Result:

<LINESTRING (30 10, 40 40)>

I would expect either shape() to raise an error in both cases or to silently accept the invalid coordinate component and then fix in in the make_valid().

Right now geometries that allow the user initialize with a NaN are: Point, LineString, MultiPoint
make_valid() fixes the error in all of these cases.

Geometries that raise a ValueError: Polygon, MultiLineString, MultiPolygon.

Steps to reproduce the problem.

See the example from the previous section.

Operating system

macOS Monteray 12.6.2 (21G320)

Shapely version and provenance

Shapely 2.0.4, installed from PyPI using pup

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

No branches or pull requests

1 participant