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

Shapely v1.8 deprecation warnings in advance of Shapely 2.0 release #764

Closed
Asteliks opened this issue Oct 27, 2021 · 17 comments
Closed

Shapely v1.8 deprecation warnings in advance of Shapely 2.0 release #764

Asteliks opened this issue Oct 27, 2021 · 17 comments

Comments

@Asteliks
Copy link

Is your feature proposal related to a problem?

Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the geoms property to access the constituent parts of a multi-part geometry.

Describe the solution you'd like to propose

Updating osmnx to use the geoms property

@gboeing
Copy link
Owner

gboeing commented Oct 28, 2021

What versions of OSMnx and Shapely are you using?

@Asteliks
Copy link
Author

I've got:
OSMnx: 1.1.1
Shapely: 1.8.0

@gboeing
Copy link
Owner

gboeing commented Oct 28, 2021

Thanks. Can you provide a reproducible code snippet?

@Asteliks
Copy link
Author

The code in which I've found this is part of my masters thesis, thus I can not share it before publication, but try this:

import osmnx as ox
Teren = "Bydgoszcz, województwo kujawsko-pomorskie, Polska"
G = ox.graph_from_place(Teren, network_type="drive")

image

@Asteliks
Copy link
Author

I you want I can try to make a PR that will fix this later

@EwoutH
Copy link
Contributor

EwoutH commented Oct 28, 2021

I have the same issue (using OSMnx 1.1.1):

osmnx\utils_geo.py:335: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.

More info in this PR, were the deprecation warnings is added: shapely/shapely#950. Shapely 1.8.0 was released a few days ago, which was the first stable release to include the warnings.

@gboeing
Copy link
Owner

gboeing commented Oct 28, 2021

Yes. This is a known issue we'll have to address in the coming weeks (see also shapely/shapely#932) as Shapely begins its deprecation warnings in advance of its v2.0 overhaul (see shapely/shapely#962 and shapely/shapely-rfc#1).

PRs are welcome if anyone spots a deprecation with a straightforward resolution!

@gboeing gboeing changed the title ShapelyDeprecationWarning Shapely v1.8 deprecation warnings in advance of Shapely 2.0 release Oct 28, 2021
@gboeing
Copy link
Owner

gboeing commented Oct 28, 2021

We probably should also constrain the requirements file to keep Shapely >=1.8 and <2.0 at this point, to keep users from installing 2.0 in their OSMnx environment before we confirm everything is compatible on our end.

@EwoutH
Copy link
Contributor

EwoutH commented Oct 29, 2021

These were the locations I found the warnings so far:

@jorisvandenbossche
Copy link

Quickly checking those listed occurences, they should be straightforward to fix I think. For example, the case of

    elif merged_outer_linestrings.geom_type == "MultiLineString":
        for merged_outer_linestring in list(merged_outer_linestrings):
            ...

can be changed to

    elif merged_outer_linestrings.geom_type == "MultiLineString":
        for merged_outer_linestring in merged_outer_linestrings.geoms:
            ...

(so adding a .geoms to explicitly get the parts of a MultiLineString)

See https://shapely.readthedocs.io/en/stable/migration.html#multi-part-geometries-will-no-longer-be-sequences-length-iterable-indexable for more details.

We probably should also constrain the requirements file to keep Shapely >=1.8 and <2.0 at this point

The >=1.8 should not necessarily be needed for now, I think. Normally all fixes you would need to do for getting it work on Shapely 1.8 without warnings should still be correct code for Shapely 1.7 as well.

@gboeing
Copy link
Owner

gboeing commented Nov 4, 2021

Thanks @jorisvandenbossche!

@gboeing
Copy link
Owner

gboeing commented Nov 7, 2021

Proposed fix in #773

@gboeing
Copy link
Owner

gboeing commented Nov 14, 2021

Resolved by #773

@gboeing gboeing closed this as completed Nov 14, 2021
@jihongyu-111
Copy link

快速检查那些列出的事件,我认为它们应该可以直接修复。例如,的情况

    elif merged_outer_linestrings.geom_type == "MultiLineString":
        for merged_outer_linestring in list(merged_outer_linestrings):
            ...

可以更改为

    elif merged_outer_linestrings.geom_type == "MultiLineString":
        for merged_outer_linestring in merged_outer_linestrings.geoms:
            ...

(因此,添加 a 以显式获取多行字符串的各个部分).geoms

有关更多详细信息,请参阅 https://shapely.readthedocs.io/en/stable/migration.html#multi-part-geometries-will-no-longer-be-sequences-length-iterable-indexable

我们可能还应该约束需求文件,以保持 Shapely >=1.8 和 <2.0 此时

我认为,现在不一定需要。通常,为了使其在 Shapely 1.8 上正常工作而需要执行的所有修复程序(没有警告)仍应是 Shapely 1.7 的正确代码。>=1.8

Hello, may I ask where this code was modified? I did not find the source file

@gboeing
Copy link
Owner

gboeing commented Apr 1, 2022

In #773

@serrayos
Copy link

What is the fix in #773 ? I do not see any solution

@gboeing
Copy link
Owner

gboeing commented Nov 18, 2022

@serrayos I don't understand your question... Did you examine the diff in #773? Do you feel that it doesn't resolve this issue?

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

6 participants