Elements
Spatial element types represent the core data modalities in a spatial omics experiment.
Point collections
SpatialOmics.SpatialPoints — Type
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 transcriptsSee also
coords, features, feature_ids, instance_id, subsample, top_features
Point accessors
SpatialOmics.coords — Function
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
SpatialOmics.features — Function
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_ids — Function
SpatialOmics.coord_system — Function
coord_system(el) → StringReturn the name of the coordinate system that el belongs to.
Defined for SpatialPoints, SpatialShapes, SpatialImage, SpatialLabels, SpatialExtent, SpatialROI, and their view types.
SpatialOmics.instance_id — Function
instance_id(el) → Vector{Int32}
instance_id(shape) → Int32Return 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
SpatialOmics.instance_ids — Function
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
Shape collections
SpatialOmics.SpatialShapes — Type
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 regionSee also
SpatialOmics.SpatialShape — Type
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
Shape accessors
SpatialOmics.geometries — Function
geometries(shp) → Vector{G}Return the vector of geometries from a SpatialShapes collection.
See also
Utilities
SpatialOmics.subsample — Function
subsample(pts, n) → SpatialPointsReturn 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
SpatialOmics.top_features — Function
top_features(pts, n=10) → Vector{String}Return the n most frequent feature names in pts, sorted by descending count.
Returns an empty vector if pts has no feature codebook.
See also
SpatialOmics.count_per_instance — Function
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
Re-exported geometry types
Polygon and Point2f are re-exported from GeometryBasics.jl. Use Polygon(ring) to construct cell boundary polygons for SpatialShapes.