Elements

Spatial element types represent the core data modalities in a spatial omics experiment.

Point collections

SpatialOmics.SpatialPointsType
SpatialPoints{T<:AbstractFloat}

Point cloud of 2-D spatial observations — transcripts, centroids, or other coordinates in a named coordinate system.

Stored as parallel arrays (struct-of-arrays layout). Feature labels (gene names, cell types, etc.) are encoded as integer indices into a compact feature_codebook for O(1) lookup by name via coords(pts, feature).

Constructors

SpatialPoints(coords; feature_id, feature_codebook, instance_id, coord_system)

Bare coordinates constructor. coords is a Vector{Point{2,T}}.

SpatialPoints(table; x=:x, y=:y, gene=nothing, coord_system="")

Tables.jl constructor. Reads x/y from columns named by x and y; optionally encodes a gene/label column via gene.

pts = SpatialPoints(df; x=:x_centroid, y=:y_centroid, gene=:target, coord_system="global")
length(pts)          # number of points
features(pts)        # gene names in codebook order
coords(pts, "Epcam") # coordinates of all Epcam transcripts

See also

coords, features, feature_ids, instance_id, subsample, top_features

Point accessors

SpatialOmics.coordsFunction
coords(pts) → Vector{Point{2,T}}
coords(pts, feature) → Vector{Point{2,T}}

Return all coordinates in pts, or only those whose feature label matches feature.

The single-argument form returns the full coordinate vector. The two-argument form performs an O(n) filter using the integer codebook index; raises an error if feature is not in the codebook.

See also

features, feature_ids

SpatialOmics.featuresFunction
features(pts) → Vector{String}

Return the feature codebook — the unique feature labels (gene names, cell types, …) present in pts, in the order used by feature_ids.

SpatialOmics.feature_idsFunction
feature_ids(pts) → Vector{Int32}

Return the per-point feature index vector. Each value is a 1-based index into features(pts); 0 means unlabelled.

See also

features, coords

SpatialOmics.coord_systemFunction
coord_system(el) → String

Return the name of the coordinate system that el belongs to.

Defined for SpatialPoints, SpatialShapes, SpatialImage, SpatialLabels, SpatialExtent, SpatialROI, and their view types.

SpatialOmics.instance_idFunction
instance_id(el) → Vector{Int32}
instance_id(shape) → Int32

Return per-observation instance IDs for a collection, or the single instance ID for a SpatialShape row. 0 means unassigned (transcript not inside any cell, or shape not assigned to a region).

See also

instance_ids, count_per_instance

SpatialOmics.instance_idsFunction
instance_ids(pts) → Vector{Int32}

Return the per-point instance ID vector for a SpatialPoints collection.

Alias for instance_id(pts) provided for consistency with instance_ids(lbl::SpatialLabels). 0 means unassigned.

instance_ids(lbl) → Vector{Int32}

Return the sorted list of unique instance IDs present in a SpatialLabels mask.

Does not include the background (pixels not in instance_map).

See also

instance_id, SpatialLabels

Shape collections

SpatialOmics.SpatialShapesType
SpatialShapes{G<:AbstractGeometry}

Collection of 2-D geometries (typically cell boundary polygons) in a named coordinate system. Each shape carries an instance_id linking it to cells or objects in a SpatialRelation.

Implements the GeoInterface GeometryCollectionTrait, making it compatible with GeometryOps operations directly.

Constructors

SpatialShapes(geometries; instance_id, coord_system)

SpatialShapes(ext::SpatialExtent)        # rectangular region
SpatialShapes(roi::SpatialROI)           # polygon region

See also

geometries, instance_id, SpatialROI, SpatialPoints

SpatialOmics.SpatialShapeType
SpatialShape{G<:AbstractGeometry}

Single-shape row accessor produced by indexing into a SpatialShapes collection.

Carries the geometry, its instance_id, and the coordinate system name. Row-accessor and collection share the same field names (geometry, instance_id, coord_system) so code generalises across both.

See also

SpatialShapes, geometry

Shape accessors

Utilities

SpatialOmics.subsampleFunction
subsample(pts, n) → SpatialPoints

Return a new SpatialPoints with a random subset of n observations.

If n ≥ length(pts), the original object is returned unchanged. The feature codebook is preserved; indices are rebuilt from the subset.

See also

top_features

SpatialOmics.count_per_instanceFunction
count_per_instance(pts) → Dict{Int32, Int}

Return a dictionary mapping each non-zero instance ID to its observation count.

Unassigned points (instance_id == 0) are excluded. Useful for computing transcript counts per cell or density metrics.

See also

instance_id, top_features

Re-exported geometry types

Polygon and Point2f are re-exported from GeometryBasics.jl. Use Polygon(ring) to construct cell boundary polygons for SpatialShapes.