spatialdata icon indicating copy to clipboard operation
spatialdata copied to clipboard

Feature request: spatial cropping from select table rows

Open LucaMarconato opened this issue 2 years ago • 2 comments

From @EliHei2:

do we have reverse spatial queries? i.e., can one select some rows from the table and get the cropped image? easier case rectangular crops and more advanced exact curvatures?

I am currently working on similar things, so I adding this to my todo list.

LucaMarconato avatar Jun 05 '23 16:06 LucaMarconato

Hi,

Is this feature available?

I want to visualize the whole image where the spots are available but I am getting the visualization of the entire image. I have to create a boundind_box manually. Is there a way to only show where the spots are?

Cheers, Sinan

sinanugur avatar Jun 20 '24 09:06 sinanugur

Hi, for shapes and points you could use the new API (not available last year) join_spatialelement_table() with how='right' to return a SpatialElement that contains only the geometries corresponding to the table.

If you are using labels, how='right' is not available, but with the new to_polygons() API you can easily convert the labels to polygons/multipolygons.

Finally, after you have the polygons that match the rows in one of the two ways described above, you can use get_extent() (also new) to compute the bounding box of the geometries matching to the rows. You can use this to crop eventual images or even the whole SpatialData object.

Please let me know if it fits your use cases and if you have further questions.

LucaMarconato avatar Jun 24 '24 15:06 LucaMarconato