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' #1085

Open
shiyue-code opened this issue Apr 29, 2024 · 1 comment
Open

Encountered some issues when using 'voronoi_polygons' #1085

shiyue-code opened this issue Apr 29, 2024 · 1 comment

Comments

@shiyue-code
Copy link

I reported this issue in shapely, but it's an upstream GEOS issue.
Can you tell me if this is something that can be optimized or if GEOS can't handle such a large amount of points.

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 the polygon representing a city road.

import shapely

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

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
geos 3.11.1

@JamesParrott
Copy link
Contributor

JamesParrott commented May 2, 2024

I can't say there is definitely no issue with Geos, but I wonder if you've just found a better method to solve your particular problem.

scipy.spatial uses QuickHull (from http://www.qhull.org/) whereas I think voronoi_polygons and Geos uses Guibas and Stolfi's Divide and Conquer to find the Delauney Triangulation. Geos uses Graham's Scan to calculate Convex Hulls.

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

2 participants