Bounding box query vs polygon query for circles
Open
Nobody has claimed this yet.
element: shapes ▲
method: query
needs: triage
priority: medium
- Dominant language
- Python
- Stars
- 394
- Forks
- 95
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 7
Description
Bounding box query selects circles whose center is contained inside the box, polygon query selects circles that intersect the box in any point.
You can reproduce with this code:
##
from spatialdata.datasets import blobs
from napari_spatialdata import Interactive
import matplotlib.pyplot as plt
import spatialdata_plot
import spatialdata as sd
from array import array
from shapely.geometry import Polygon
from geopandas import GeoDataFrame
plt.style.use('dark_background')
# define square to use as query geometry
x_coords = array("d", [243.331349706879, 348.864955663264, 348.8649556632623, 243.3313497068773, 243.331349706879])
y_coords = array("d", [392.5609882574645, 392.56098825746835, 214.4730282060675, 214.47302820606367, 392.5609882574645])
minx, maxx = min(x_coords), max(x_coords)
miny, maxy = min(y_coords), max(y_coords)
# rearrange to the vars needs to a bounding_box_query
min_coordinates = [minx, miny]
max_coordinates = [maxx, maxy]
# turn into shapely polygon
polygon = Polygon(zip(x_coords, y_coords))
# Print the results
print("Min coordinates:", min_coordinates)
print("Max coordinates:", max_coordinates)
print("Polygon:", polygon)
##
sdata = blobs().subset(["blobs_polygons", "blobs_circles", "blobs_image"])
sdata["box"] = sd.models.ShapesModel.parse(GeoDataFrame(geometry=[polygon]))
##
sdata.pl.render_images().pl.render_shapes("blobs_circles", color="red").pl.render_shapes(
"blobs_polygons", color="white"
).pl.render_shapes("box", color="#FFFFFF66").pl.show()
plt.show()
## bounding box query
queried_bb = sdata.query.bounding_box(
axes=("x", "y"), min_coordinate=min_coordinates, max_coordinate=max_coordinates, target_coordinate_system="global"
)
queried_bb.pl.render_images().pl.render_shapes("blobs_circles", color="red").pl.render_shapes(
"blobs_polygons", color="white"
).pl.render_shapes("box", color="#FFFFFF66").pl.show()
plt.show()
## polygon query
queried_pol = sdata.query.polygon(polygon, target_coordinate_system='global')
queried_pol.pl.render_images().pl.render_shapes("blobs_circles", color="red").pl.render_shapes(
"blobs_polygons", color="white"
).pl.render_shapes("box", color="#FFFFFF66").pl.show()
plt.show()
Which gives these three plots.
Full data
Bounding box query
Polygon query
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the sdata.query.bounding_box and sdata.query.polygon entry points and run the reproduction against the blobs dataset. Compare which circles each query returns, then trace the shape-selection logic to determine the intended consistent behavior. Done means the discrepancy is resolved and the provided example produces matching, documented selection semantics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 64/100