# Questions on Shapes + Tables vs single AnnData object

**URL:** <https://discourse.scverse.org/t/questions-on-shapes-tables-vs-single-anndata-object/3814>\
**Category:** spatialdata\
**Created:** [October 2, 2025, 12:17pm UTC](https://discourse.scverse.org/t/questions-on-shapes-tables-vs-single-anndata-object/3814 "2025-10-02T12:17:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [October 2, 2025, 12:17pm UTC](https://discourse.scverse.org/t/questions-on-shapes-tables-vs-single-anndata-object/3814/1 "2025-10-02T12:17:50Z")

</div>

Moving the conversation [from a GitHub issue](https://github.com/scverse/spatialdata-io/issues/323#issuecomment-3304985113) to here.

Original message from [asmlgkj (curry\_fan) · GitHub](https://github.com/asmlgkj)

> I have a couple of questions regarding the SpatialData outputs and how cell positions are represented in Seurat objects:
> 
> SpatialData outputs: When using SpatialData, the results (image and expression) are stored as separate elements. However, this makes it more difficult to interface with downstream tools such as Squidpy, which often rely on each cell (or observation) having an associated spatial coordinate. Similarly, visualization tools that expect an H&E image may fail if the AnnData/Seurat object does not directly contain the image.
> 
> What is the recommended way to ensure compatibility with such tools?
> 
> Should we be explicitly merging the image and expression layers, or is there a standard workflow for linking them?
> 
> Polygon-based cells: For segmented cells represented by polygons, a single representative point is often required for certain downstream analyses (e.g., co-localization, neighbor graphs).
> 
> Does Seurat currently use the geometric centroid of each polygon, or some other representative location?
> 
> In cases where the centroid falls outside of the polygon (e.g., crescent-shaped or elongated cells), would you recommend using the centroid, or instead an interior point (such as st\_point\_on\_surface in sf)?
> 
> I would greatly appreciate your advice on best practices here, as this has important implications for interoperability with Squidpy and other spatial analysis or visualization software.

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [October 2, 2025, 12:20pm UTC](https://discourse.scverse.org/t/questions-on-shapes-tables-vs-single-anndata-object/3814/2 "2025-10-02T12:20:38Z")

</div>

> [@LucaMarconato](#):
>
> Similarly, visualization tools that expect an H&E image may fail if the AnnData/Seurat object does not directly contain the image.

The visualization packages `spatialdata-plot` or `napari-spatialdata` are built to support `SpatialData` object. Tools that are designed to expect an `AnnData` or `Seurat` object containing an image will naturally not work with a `SpatialData` object, or an `AnnData` object in the table slot. This is expected.

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [October 2, 2025, 12:21pm UTC](https://discourse.scverse.org/t/questions-on-shapes-tables-vs-single-anndata-object/3814/3 "2025-10-02T12:21:32Z")

</div>

> [@LucaMarconato](#):
>
> What is the recommended way to ensure compatibility with such tools?

You can still try using [spatialdata\_io.to\_legacy\_anndata()](https://spatialdata.scverse.org/projects/io/en/stable/generated/spatialdata_io.experimental.to_legacy_anndata.html#spatialdata_io.experimental.to_legacy_anndata), that we developed for these use cases, but the image will be downscaled.

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [October 2, 2025, 12:26pm UTC](https://discourse.scverse.org/t/questions-on-shapes-tables-vs-single-anndata-object/3814/4 "2025-10-02T12:26:31Z")

</div>

> [@LucaMarconato](#):
>
> Should we be explicitly merging the image and expression layers, or is there a standard workflow for linking them?

We provide several APIs to help with this:

- `match_element_to_table()`, `match_sdata_to_table()`, `match_table_to_element()` [documented here](https://spatialdata.scverse.org/en/stable/search.html?q=match)
- Internally these function use the more powerful (but less user-friendly) API: `join_spatial_element_table()` ([docs here](https://spatialdata.scverse.org/en/stable/api/operations.html#spatialdata.join_spatialelement_table))
- We will provide also a convenient way to filter and match the object at the same time (you can do this by filtering the table and then calling one of the above, but with the new way it will be less verbose). You can see a preview [in this Pull Request](https://github.com/scverse/spatialdata/pull/894) with `filter_table_by_query()`

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [October 2, 2025, 12:28pm UTC](https://discourse.scverse.org/t/questions-on-shapes-tables-vs-single-anndata-object/3814/5 "2025-10-02T12:28:01Z")

</div>

> [@LucaMarconato](#):
>
> Does Seurat currently use the geometric centroid of each polygon, or some other representative location?

You can get the centroid of a polygon (or any element) with `get_centroids()`[documented here](https://spatialdata.scverse.org/en/stable/api/operations.html#spatialdata.get_centroids).

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [October 2, 2025, 12:28pm UTC](https://discourse.scverse.org/t/questions-on-shapes-tables-vs-single-anndata-object/3814/6 "2025-10-02T12:28:36Z")

</div>

> [@LucaMarconato](#):
>
> In cases where the centroid falls outside of the polygon (e.g., crescent-shaped or elongated cells), would you recommend using the centroid, or instead an interior point (such as st\_point\_on\_surface in sf)?

This depends on the specific analysis and use case, so I won’t comment on this.

---

<div class="post-metadata">

**Author:** ![denvercal1234GitHub](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/denvercal1234github/32/921_2.png) [@denvercal1234GitHub](https://discourse.scverse.org/u/denvercal1234GitHub)\
**Post date:** [December 11, 2025, 10:02pm UTC](https://discourse.scverse.org/t/questions-on-shapes-tables-vs-single-anndata-object/3814/7 "2025-12-11T22:02:03Z")

</div>

Thanks, @LucaMarconato for the response. I currently have anndata objects (h5ad) of the CosMx, do you think it is best to reconstruct the `spatialdata` from scratch or use `spatialdata_io.experimental.from_legacy_anndata`? Does the `spatialdata_io.experimental.from_legacy_anndata` preserve all the obs, var, obsm etc data? Thank you for your advice. Ref: [spatialdata\_io.experimental.from\_legacy\_anndata — spatialdata-io](https://spatialdata.scverse.org/projects/io/en/latest/generated/spatialdata_io.experimental.from_legacy_anndata.html)
