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

Encountered some issues when using 'voronoi_polygons' #2043

Open
shiyue-code opened this issue Apr 28, 2024 · 2 comments
Open

Encountered some issues when using 'voronoi_polygons' #2043

shiyue-code opened this issue Apr 28, 2024 · 2 comments
Labels

Comments

@shiyue-code
Copy link

shiyue-code commented Apr 28, 2024

Is this a bug?

Using voronoi_polygons(road) resulted in a memory usage of over 10 GB and then was forcibly terminated by the OOM killer. The road consists of approximately 4.6 million points forming polygons with holes. However, there were no issues encountered when using from scipy.spatial import Voronoi, and the memory usage was minimal.

Steps to reproduce the problem.

First import the geometry from the ’polygon.wkb‘ file. The file's cloud drive link is file: https://drive.google.com/file/d/14pH9wpJRURtokWLc_rpvo2jykLDSLN0-/view?usp=drive_link
This is actually a very complex road
Then use the following code to test if it will result in an OOM.

voronoied = voronoi_polygons(borders,only_edges=True) #equivalent to the scipy.spatial.Voronoi

scipy.spatial .Voronoi is ok

from scipy.spatial import Voronoi
points = []
exterior_points = list(borders.exterior.coords)
interior_points = []
for interior in borders.interiors:
    interior_points.extend(list(interior.coords))
points += exterior_points + interior_points
v = Voronoi(np.array(points))

Operating system

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy

Shapely version and provenance

shapely 2.0.3

@shiyue-code shiyue-code changed the title Encountered some issues when using voronoi_polygons Encountered some issues when using 'voronoi_polygons' Apr 28, 2024
@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Apr 29, 2024

To read the file (@shiyue-code it would be helpful to include that in your report, it's not necessarily clear what exactly the file exists of):

import shapely

with open("polygon.wkb", "rb") as f:
    borders = shapely.from_wkb(f.read())

I can reproduce this, causing a lot of memory usage and then (in my case, at the point of taking around 30GB hitting the limit of my system) killing itself.

It is a lot of points though, and GEOS builds up indices on top of this to determine the resulting polygons I assume, so honestly I have no clue if this is "expected" and GEOS simply cannot really handle that much of points given the way the algo works, or if there is actually something GEOS could do to improve memory usage. In either case, it's an upstream GEOS issue, so I would recommend reporting it there (https://github.com/libgeos/geos/issues)

@shiyue-code
Copy link
Author

To read the file (@shiyue-code it would be helpful to include that in your report, it's not necessarily clear what exactly the file exists of):

import shapely

with open("polygon.wkb", "rb") as f:
    borders = shapely.from_wkb(f.read())

I can reproduce this, causing a lot of memory usage and then (in my case, at the point of taking around 30GB hitting the limit of my system) killing itself.

It is a lot of points though, and GEOS builds up indices on top of this to determine the resulting polygons I assume, so honestly I have no clue if this is "expected" and GEOS simply cannot really handle that much of points given the way the algo works, or if there is actually something GEOS could do to improve memory usage. In either case, it's an upstream GEOS issue, so I would recommend reporting it there (https://github.com/libgeos/geos/issues)

Thank you for your response, I reported the issue in GEOS.

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

No branches or pull requests

2 participants