spatialdata.polygon_query

Contents

spatialdata.polygon_query#

spatialdata.polygon_query(element, polygon, target_coordinate_system, filter_table=True, shapes=True, points=True, images=True, labels=True)#

Query a SpatialData object or a SpatialElement by a polygon or multipolygon.

Parameters:
  • element (Union[SpatialImage, MultiscaleSpatialImage, GeoDataFrame, DataFrame, SpatialData]) – The SpatialElement or SpatialData object to query.

  • polygon (Polygon | MultiPolygon) – The polygon/multipolygon to query by.

  • target_coordinate_system (str) – The coordinate system of the polygon/multipolygon.

  • filter_table (bool (default: True)) – If True, the table is filtered to only contain rows that are annotating regions contained within the query polygon/multipolygon.

  • [Deprecated] (labels) – This argument is now ignored and will be removed. Please filter the SpatialData object before calling this function.

  • [Deprecated] – This argument is now ignored and will be removed. Please filter the SpatialData object before calling this function.

  • [Deprecated] – This argument is now ignored and will be removed. Please filter the SpatialData object before calling this function.

  • [Deprecated] – This argument is now ignored and will be removed. Please filter the SpatialData object before calling this function.

Return type:

Union[SpatialImage, MultiscaleSpatialImage, GeoDataFrame, DataFrame, SpatialData, None]

Returns:

: The queried SpatialData object or SpatialElement containing the requested data. Eventual empty Elements are omitted by the SpatialData object.

Examples

Here is an example for multipolygon use case. If you have a sequence of polygons/multipolygons, in particular a GeoDataFrame, and you want to query the data that belongs to any one of these shapes, you can call this function to the multipolygon obtained by merging all the polygons. To merge you can use a unary union.