Layers & Spatial Exports
Terragnos Core provides powerful spatial export capabilities including GeoJSON feeds, vector tiles (MVT), and OGC API Features endpoints. This guide covers creating layer definitions, exporting spatial data, and integrating with GIS tools.
What are Layers?
Layers are reusable spatial export configurations that define:
- Filters – Which objects to include (by type, attributes, spatial bounds)
- Fields – Which attributes to include in the export
- Caching – TTL for cached responses
- Format – GeoJSON, MVT, or OGC API Features
Creating Layer Definitions
Via API
curl -X POST \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"name": "Traffic Signals",
"slug": "traffic-signals",
"definition": {
"filters": {
"typeId": "traffic-signal"
},
"fields": ["id", "typeId", "attributes", "geometry"]
},
"cacheTtlSeconds": 3600
}' \
https://core.example.com/v1/layers/definitions
Via Admin Console
- Navigate to Layers in the Admin Console
- Click Create New Layer
- Configure filters, fields, and caching
- Save the layer definition
GeoJSON Export
Basic Export
GET /v1/layers/objects
Returns a GeoJSON FeatureCollection:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "object-id",
"geometry": {
"type": "Point",
"coordinates": [12.34, 56.78]
},
"properties": {
"typeId": "traffic-signal",
"attributes": {
"signalType": "standard"
}
}
}
]
}
Using Layer Definitions
GET /v1/layers/objects?layer=traffic-signals
Filtering
# By type
GET /v1/layers/objects?typeId=traffic-signal
# By bounding box
GET /v1/layers/objects?bbox=12.0,56.0,13.0,57.0
# Combined
GET /v1/layers/objects?layer=traffic-signals&bbox=12.0,56.0,13.0,57.0
Field Selection
# Select specific fields
GET /v1/layers/objects?fields=id,typeId,attributes.signalType
Available fields:
id– Object IDtypeId– Object type IDpublicId– Public identifierattributes– All attributes (or specific paths)geometry– Spatial geometryworkflowState– Current workflow statecreatedAt– Creation timestampupdatedAt– Last update timestamp
Streaming Export (NDJSON)
For large datasets, use the streaming endpoint:
GET /v1/layers/objects/stream?layer=traffic-signals
Returns newline-delimited JSON (NDJSON), one feature per line:
{"type":"Feature","id":"obj-1","geometry":{...},"properties":{...}}
{"type":"Feature","id":"obj-2","geometry":{...},"properties":{...}}
This is more memory-efficient for large exports.
Vector Tiles (MVT)
Terragnos Core supports Mapbox Vector Tiles (MVT) for efficient map rendering:
GET /v1/layers/tiles/{layer}/{z}/{x}/{y}
Parameters:
layer– Layer slugz– Zoom level (0-18)x– Tile X coordinatey– Tile Y coordinate
Example:
GET /v1/layers/tiles/traffic-signals/12/2048/1365
Using with Map Libraries
Leaflet:
L.vectorGrid.protobuf('https://core.example.com/v1/layers/tiles/traffic-signals/{z}/{x}/{y}', {
vectorTileLayerStyles: {
'traffic-signals': {
fillColor: '#ff0000',
fillOpacity: 0.6,
stroke: true,
color: '#000000',
weight: 1
}
}
}).addTo(map);
Mapbox GL:
map.addSource('traffic-signals', {
type: 'vector',
tiles: ['https://core.example.com/v1/layers/tiles/traffic-signals/{z}/{x}/{y}']
});
map.addLayer({
id: 'traffic-signals',
type: 'circle',
source: 'traffic-signals',
paint: {
'circle-color': '#ff0000',
'circle-radius': 5
}
});
OGC API Features
Terragnos Core provides an OGC API Features compliant endpoint:
GET /v1/layers/ogc/features?layer=traffic-signals
Response format:
{
"type": "FeatureCollection",
"features": [...],
"links": [
{
"rel": "next",
"href": "/v1/layers/ogc/features?layer=traffic-signals&offset=100"
}
]
}
Caching
Layer responses are cached for performance:
- Cache TTL – Configurable per layer (default: 3600 seconds)
- ETag support – Conditional requests return 304 Not Modified
- Cache-Control headers – Standard HTTP caching headers
Cache Invalidation
Caches are automatically invalidated when:
- Objects in the layer are updated
- Layer definition is modified
- Cache TTL expires
Time-Travel Queries
All layer endpoints support time-travel queries:
GET /v1/layers/objects?layer=traffic-signals&asOf=2024-01-15T10:30:00Z
Returns the layer state at the specified point in time.
Best Practices
- Use layer definitions – Create reusable layer definitions instead of inline filters
- Optimize fields – Only request fields you need
- Use bounding boxes – Limit spatial queries with bbox parameters
- Leverage caching – Set appropriate cache TTLs for your use case
- Use streaming for large exports – Use
/streamendpoint for large datasets - Use vector tiles for maps – MVT is more efficient than GeoJSON for map rendering
- Monitor cache hit rates – Track cache performance