Skip to main content

Spatial Representation

Layers provides composable spatial primitives that fully subsume GeoJSON (RFC 7946), WKT/ISO 19125, ISO-Space (ISO 24617-7), SpatialML, RCC-8, DE-9IM, W3C spatial selectors, COCO/VOC/YOLO annotation formats, and SVG. This guide documents the spatial type system and maps each standard to Layers equivalents.

Two Kinds of Space​

Layers distinguishes media space from semantic space:

  • Media space (boundingBox, spatioTemporalAnchor): where in an image or video frame an annotation occurs. Expressed as pixel coordinates. Used for anchoring annotations to media: "this object is at pixel (100, 50) with width 200 and height 150."

  • Semantic space (spatialExpression): what place or region a linguistic expression refers to. Expressed as geographic coordinates, named locations, or relative positions. Used for spatial annotation: "this expression refers to downtown Tokyo."

Media space lives on anchors (pub.layers.defs#anchor.spatioTemporalAnchor). Semantic space lives on annotations (pub.layers.annotation.defs#annotation.spatial). They are independent: a spatial annotation at pixel (100, 50) in a satellite image might refer to "the Eiffel Tower at 48.8584° N, 2.2945° E."

Spatial Primitives​

Three composable objects in pub.layers.defs:

spatialEntity​

The normalized spatial value. Consumers dispatch on which fields are populated:

PatternFieldsExample
Pixel bounding boxbbox{x: 100, y: 50, width: 200, height: 150}
Geographic pointgeometry + type="point" + crs="wgs84""POINT(37.7749 -122.4194)"
Polygon regiongeometry + type="polygon""POLYGON((0 0, 100 0, 100 100, 0 100, 0 0))"
Line/pathgeometry + type="line-string""LINESTRING(0 0, 50 50, 100 0)"
Circlegeometry + type="circle""POINT(50 50)" with radius in features
GeoJSON geometrygeometry + geometryFormat="geojson"'{"type":"Point","coordinates":[-122.4194,37.7749]}'
Complex shapegeometry + geometryFormat="svg-path""M 10 10 L 100 10 L 100 100 Z"

The geometry field is a string whose format is specified by geometryFormat (default: WKT). The type field enables dispatch without parsing. The crs field specifies the coordinate reference system (pixel, percentage, wgs84, web-mercator, or community-defined via crsUri).

spatialModifier​

Qualitative modification: approximate, projected, interpolated, estimated, buffered, simplified, generalized.

spatialExpression​

The complete spatial annotation, packaging:

  • type: location, region, path, direction, distance, relative
  • value: ref to spatialEntity
  • modifier: ref to spatialModifier
  • anchorRef: what this expression is relative to (e.g., a landmark, reference location)
  • function: the role this place plays in the document (document-location, situation-location, origin, destination, etc.)

Spatial Relations​

Spatial relations between annotations use pub.layers.graph.graphEdge with RCC-8 topological relations, directional relations, and distance relations as edgeType values.

RCC-8 (Region Connection Calculus)​

The 8 jointly exhaustive and pairwise disjoint topological relations between spatial regions:

#RelationInverseVisualDefinition
1disconnecteddisconnectedA BNo common points (symmetric)
2externally-connectedexternally-connectedA)(BShare boundary only, interiors don't overlap (symmetric)
3partially-overlappingpartially-overlappingA(B)A/B(A)BSome interior overlap, neither contains the other (symmetric)
4tangential-proper-parttangential-proper-part-inverse(A)__/(BB)Source inside target, boundaries touch
5non-tangential-proper-partnon-tangential-proper-part-inverse_(A)_/(BBB)Source inside target, no boundary contact
6tangential-proper-part-inversetangential-proper-part(AA)/(B)__Source contains target, boundaries touch
7non-tangential-proper-part-inversenon-tangential-proper-part(AAA)/_(B)_Source contains target, no boundary contact
8spatially-equalspatially-equal(AB)Identical spatial extent (symmetric)

Symmetric relations: disconnected, externally-connected, partially-overlapping, and spatially-equal are symmetric: R(A,B) implies R(B,A). Both edge directions are valid.

Proper part convention: tangential-proper-part(A,B) means A is inside B. The inverse tangential-proper-part-inverse(A,B) means A contains B.

Point geometry: For points (zero-area regions), only disconnected and spatially-equal apply.

Constraint composition: RCC-8's composition table (what can be inferred from combining two relations) is an application-level concern, not encoded in the schema. Libraries can compute transitive closure over Layers graph edges.

DE-9IM / OGC Predicate Mapping​

The DE-9IM (Dimensionally Extended 9-Intersection Model) predicates used in PostGIS and JTS map to RCC-8 as follows:

OGC PredicateRCC-8 EquivalentNotes
Equalsspatially-equalIdentical extent
DisjointdisconnectedNo intersection
Touchesexternally-connectedBoundary contact only
Overlapspartially-overlappingPartial interior overlap
Withintangential-proper-part or non-tangential-proper-partA inside B
Containstangential-proper-part-inverse or non-tangential-proper-part-inverseA contains B
Coverstangential-proper-part-inverseContains with boundary sharing
CoveredBytangential-proper-partWithin with boundary sharing
IntersectsAny except disconnectedNegation of Disjoint
Crosses(none)Applies to line/point geometries; use partially-overlapping or features

Directional Relations​

ISO-Space orientational relations as graphEdge.edgeType values:

Edge typeInverseFrame
north-ofsouth-ofAbsolute (cardinal)
south-ofnorth-ofAbsolute (cardinal)
east-ofwest-ofAbsolute (cardinal)
west-ofeast-ofAbsolute (cardinal)
abovebelowVertical
belowaboveVertical
in-front-ofbehindRelative/intrinsic
behindin-front-ofRelative/intrinsic
left-ofright-ofRelative/intrinsic
right-ofleft-ofRelative/intrinsic

Frame of reference (absolute, relative, intrinsic) can be specified via graphEdge.properties features.

Distance Relations​

Edge typeMeaning
nearSource is close to target (threshold in properties)
farSource is distant from target (threshold in properties)
adjacentSource shares a boundary with target

Quantitative distances are stored in graphEdge.properties (e.g., {key: "distance", value: "50km"}).

The label field on spatial graphEdges can carry the linguistic spatial signal that triggered the relation (e.g., "in", "near", "above", "between"). Signal annotations themselves use subkind="spatial-signal" on annotation layers.

Composability Examples​

Simple pixel bounding box:

{
"subkind": "spatial-expression",
"label": "person",
"spatial": {
"type": "region",
"value": {
"bbox": { "x": 100, "y": 50, "width": 200, "height": 150 },
"crs": "pixel"
}
}
}

Geographic point ("located at 37.7749° N, 122.4194° W"):

{
"subkind": "location-mention",
"label": "San Francisco",
"text": "San Francisco",
"spatial": {
"type": "location",
"value": {
"geometry": "POINT(37.7749 -122.4194)",
"type": "point",
"geometryFormat": "wkt",
"crs": "wgs84"
}
}
}

GeoJSON polygon region:

{
"spatial": {
"type": "region",
"value": {
"geometry": "{\"type\":\"Polygon\",\"coordinates\":[[[-122.5,37.7],[-122.4,37.7],[-122.4,37.8],[-122.5,37.8],[-122.5,37.7]]]}",
"type": "polygon",
"geometryFormat": "geojson",
"crs": "wgs84"
}
}
}

Approximate location ("somewhere in downtown"):

{
"spatial": {
"type": "location",
"value": {
"geometry": "POINT(35.6762 139.6503)",
"type": "point",
"crs": "wgs84",
"uncertainty": "2km"
},
"modifier": { "mod": "approximate" }
}
}

Relative spatial reference ("behind the station"):

{
"spatial": {
"type": "relative",
"anchorRef": { "localId": { "value": "station-annotation-uuid" } }
}
}

Path/trajectory ("from Paris to Lyon"):

{
"spatial": {
"type": "path",
"value": {
"geometry": "LINESTRING(2.3522 48.8566, 4.8357 45.7640)",
"type": "line-string",
"crs": "wgs84"
},
"function": "origin"
}
}

COCO polygon annotation:

{
"spatial": {
"type": "region",
"value": {
"geometry": "[100,50,200,50,200,150,150,200,100,150]",
"type": "polygon",
"geometryFormat": "coco-polygon",
"crs": "pixel"
}
}
}

Spatial relation (graphEdge):

{
"source": {
"recordRef": "at://did:plc:.../pub.layers.annotation.annotationLayer/...",
"objectId": { "value": "place-1-uuid" }
},
"target": {
"recordRef": "at://did:plc:.../pub.layers.annotation.annotationLayer/...",
"objectId": { "value": "place-2-uuid" }
},
"edgeType": "north-of",
"label": "north of",
"confidence": 950
}

Standards Mapping​

GeoJSON (RFC 7946)​

GeoJSON is the standard JSON format for encoding geographic data structures. Layers maps all GeoJSON geometry types to spatialEntity.

GeoJSON TypeLayers EquivalentNotes
PointspatialEntity with type="point", geometryFormat="geojson"Single coordinate position
MultiPointspatialEntity with type="multi-point", geometryFormat="geojson"Array of positions
LineStringspatialEntity with type="line-string", geometryFormat="geojson"Ordered positions forming a line
MultiLineStringspatialEntity with type="multi-line-string", geometryFormat="geojson"Array of LineStrings
PolygonspatialEntity with type="polygon", geometryFormat="geojson"Closed ring(s), exterior + optional holes
MultiPolygonspatialEntity with type="multi-polygon", geometryFormat="geojson"Array of Polygons
GeometryCollectionspatialEntity with type="geometry-collection", geometryFormat="geojson"Mixed geometry types
coordinatesspatialEntity.geometryThe GeoJSON geometry object as a JSON string
CRS (default WGS84)spatialEntity.crs="wgs84"GeoJSON defaults to WGS84 (EPSG:4326)
bbox propertyspatialEntity.bbox or featuresBounding box envelope
3D coordinatesspatialEntity.dimensions=3Longitude, latitude, altitude

Completeness: Full subsumption. Every GeoJSON geometry type has a direct mapping. The GeoJSON geometry object is stored as a JSON string in the geometry field with geometryFormat="geojson".

WKT (Well-Known Text) / ISO 19125​

WKT is the OGC standard text representation for geometry objects. It is the default geometryFormat for spatialEntity.

WKT TypeLayers EquivalentExample
POINTspatialEntity with type="point"POINT(37.7749 -122.4194)
LINESTRINGspatialEntity with type="line-string"LINESTRING(0 0, 50 50, 100 0)
POLYGONspatialEntity with type="polygon"POLYGON((0 0, 100 0, 100 100, 0 100, 0 0))
MULTIPOINTspatialEntity with type="multi-point"MULTIPOINT((0 0), (1 1))
MULTILINESTRINGspatialEntity with type="multi-line-string"MULTILINESTRING((0 0, 1 1), (2 2, 3 3))
MULTIPOLYGONspatialEntity with type="multi-polygon"MULTIPOLYGON(((0 0, 1 0, 1 1, 0 0)))
GEOMETRYCOLLECTIONspatialEntity with type="geometry-collection"GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0, 1 1))
2D coordinatesdimensions=2(x y)
3D coordinates (Z)dimensions=3(x y z)
4D coordinates (ZM)dimensions=4 + features(x y z m) with measure value in features

Completeness: Full subsumption. WKT is the default geometry format; any WKT string can be stored directly in the geometry field.

ISO-Space (ISO 24617-7)​

ISO-Space is the ISO standard for spatial and spatiotemporal annotation in natural language text. See the ISO-Space integration doc for the full type-by-type mapping.

ISO-Space ElementLayers EquivalentNotes
PLACEannotation with subkind="location-mention" + spatial fieldNamed/nominal place references. spatial.type="location"
SPATIAL_ENTITY (non-place)annotation with subkind="spatial-expression" + spatial fieldGeneral spatial entities
SPATIAL_SIGNALannotation with subkind="spatial-signal"Spatial prepositions/connectives ("in", "near", "above")
PATHannotation with spatial.type="path"Motion paths. spatial.value.geometry as WKT LINESTRING
MOTIONannotation with subkind="situation-mention" + argumentsMotion events with trajector, landmark, path arguments
QSLINK (qualitative spatial)graphEdge with RCC-8 edgeTypeTopological relations between spatial entities
OLINK (orientation)graphEdge with directional edgeTypeOrientational relations (above, north-of, etc.)
MEASURELINKgraphEdge with distance edgeType + propertiesMetric relations with distance values
MLINK (motion)graphEdge with edgeType="causal" + motion propertiesLinks between motion events and paths
Frame of referencegraphEdge.properties featuresIntrinsic, relative, or absolute frame

Completeness: Full subsumption. Every ISO-Space element and attribute has a direct or compositional mapping.

SpatialML (NGA/MITRE)​

SpatialML is a markup language for geographic place references in natural language text with geo-coordinate grounding.

SpatialML ElementLayers EquivalentNotes
PLACEannotation with subkind="location-mention" + spatial fieldspatial.type="location", geo-coordinates in spatial.value
PLACE.gazrefannotation.knowledgeRefsGazetteer reference as knowledgeRef
PLACE.latLongspatialEntity.geometry with crs="wgs84"WKT POINT
PLACE.country/continentannotation.featuresAdministrative hierarchy in features
LINKgraphEdge with RCC-8/directional edgeTypeTopological and directional relations between places
RLINKgraphEdge with edgeType + path propertiesRelative location with trajectory information
SIGNALannotation with subkind="spatial-signal"Spatial indicator words

Completeness: Full subsumption. SpatialML's geo-coordinate grounding maps directly to spatialEntity with WGS84 coordinates.

W3C Web Annotation Selectors​

W3C spatial selectors for identifying regions in images and documents.

W3C SelectorLayers EquivalentNotes
FragmentSelector (xywh= pixel)spatialEntity.bboxxywh=100,50,200,150 → {x:100, y:50, width:200, height:150}
FragmentSelector (xywh= percent)spatialEntity with geometry + crs="percentage"Percentage-based coordinates
SvgSelectorspatialEntity with geometryFormat="svg-path"SVG shapes for non-rectangular regions
ImageApiSelector (IIIF)spatialEntity.bbox or geometry + crs="percentage"IIIF region selectors

Computer Vision Formats​

FormatLayers EquivalentNotes
COCO bbox [x,y,w,h]spatialEntity.bboxDirect mapping (top-left origin, pixel coords)
COCO polygonspatialEntity with geometryFormat="coco-polygon", type="polygon"Coordinate array as string
COCO RLE maskspatialEntity with geometryFormat="coco-rle", type="polygon"Run-length encoded segmentation
Pascal VOC [xmin,ymin,xmax,ymax]spatialEntity.bboxConvert: width=xmax-xmin, height=ymax-ymin
YOLO [x_center,y_center,w,h] normalizedspatialEntity with type="box", crs="percentage"Normalized [0,1] coordinates

SVG Shapes​

SVG ElementLayers spatialEntity.typeNotes
<rect>boxbbox for axis-aligned; geometry+svg-path for rotated
<circle>circleCenter + radius in geometry string or features
<ellipse>ellipseCenter + radii in geometry string or features
<polygon>polygonCoordinate list as geometry string
<polyline>line-stringOpen line as geometry string
<path>AnySVG path data in geometry with geometryFormat="svg-path"

RCC-8 (Region Connection Calculus)​

All 8 RCC-8 relations are first-class graphEdge.edgeType values. See the Spatial Relations section above for the complete table.

Inverse convention: For symmetric relations (disconnected, externally-connected, partially-overlapping, spatially-equal), both edge directions are equivalent. For asymmetric relations, use the appropriate direction or its inverse.

ELAN / Gesture and Sign Language Annotation​

ELAN ConceptLayers EquivalentNotes
Spatial tier (gesture annotation)annotationLayer with subkind="spatial-expression"Annotations carry spatial field
Signing spacespatialEntity with crs="pixel"Signing space coordinates relative to video frame
Hand positionspatialEntity with type="point", crs="pixel"Point in video frame
Motion trajectoryspatialEntity with type="line-string"Sequence of positions over time
Spatial reference in signsspatialExpression with type="relative" + anchorRefSpatial reference relative to signer body

See Also​