Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Discussion options

You must be logged in to vote

Assuming you are using Shapely 2.x, you can use the points function, which is vectorized to return numpy array types.

import numpy as np
import shapely

rng = np.random.default_rng(123)
n = 10_000
xq = rng.random(n)
yq = rng.random(n)
pts = shapely.points(xq, yq)

and when you get to do the point-in-polygon check, also use vectorized functions like contains:

poly = shapely.from_wkt("POLYGON((0 0, 0 0.1, 0.1 0.1, 0 0))")
pt_in_poly = shapely.contains(poly, pts)
# or poly.contains(pts)
pt_in_poly.sum()  # 60

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@tianzhuqiao
Comment options

Answer selected by tianzhuqiao
Comment options

You must be logged in to vote
4 replies
@theroggy
Comment options

@tianzhuqiao
Comment options

@theroggy
Comment options

@tianzhuqiao
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2116 on August 19, 2024 23:54.