Skip to content

Get list of coordinates contained in Polygon #1823

Discussion options

You must be logged in to vote

You should be able to use the spatial index query method, after constructing your boxes (it will also prepare your input geoms automatically):

from shapely import STRtree

tree = STRtree(vector_boxes)
indices = tree.query(detection_area.polygon, predicate="contains_properly")
vector_boxes_in_detection_area = vector_boxes[indices]

bounds = shapely.bounds(vector_boxes_in_detection_area)  # returns array: [[xmin1, ymin1, xmax1, xmax1], [xmin2, ymin2, xmax2, ymax2]]

vector_coors = bounds[:,:2] // crop_factor  # this should be equivalent to what you were doing before

The spatial index should make this faster because it does a fast check for overlap between the bounding box of the detection_a…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by GeneralErrorOK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants