Store geospatial values in Chronicle
Cratis Chronicle supports geographic points, paths and areas as typed values in events and read models. Use Point, LineString and Polygon for a location, route or boundary that a projection or reducer needs to carry into a view.
The .NET types come from Cratis.Fundamentals in the Cratis.Geospatial namespace. Kotlin and Java use the types in io.cratis.fundamentals.geospatial, with GeoJSON adapters supplied by their Chronicle client.
Geospatial types
Section titled “Geospatial types”Choose a type for the shape your event records:
using Cratis.Geospatial;
public static class GeospatialTypeExamples{ public static Point CreatePoint() => new(10.456, 42.123);
public static LineString CreatePath() => new([ new Point(10.456, 42.123), new Point(11.789, 43.456) ]);
public static Polygon CreateBoundary() => new( Shell: new LinearRing([ new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0) ]), Holes: []);}import io.cratis.fundamentals.geospatial.LinearRingimport io.cratis.fundamentals.geospatial.LineStringimport io.cratis.fundamentals.geospatial.Pointimport io.cratis.fundamentals.geospatial.Polygon
object GeospatialTypeExamples { fun createPoint(): Point = Point(longitude = 10.456, latitude = 42.123)
fun createPath(): LineString = LineString( Point(10.456, 42.123), Point(11.789, 43.456) )
fun createBoundary(): Polygon = Polygon( shell = LinearRing( Point(0.0, 0.0), Point(10.0, 0.0), Point(10.0, 10.0), Point(0.0, 10.0), Point(0.0, 0.0) ), holes = emptyList() )}import io.cratis.fundamentals.geospatial.LinearRing;import io.cratis.fundamentals.geospatial.LineString;import io.cratis.fundamentals.geospatial.Point;import io.cratis.fundamentals.geospatial.Polygon;
import java.util.Collections;
class GeospatialTypeExamples { static Point createPoint() { return new Point(10.456, 42.123); }
static LineString createPath() { return new LineString( new Point(10.456, 42.123), new Point(11.789, 43.456)); }
static Polygon createBoundary() { LinearRing shell = new LinearRing( new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0)); return new Polygon(shell, Collections.emptyList()); }}Elixir does not support this workflow yet.TypeScript does not support this workflow yet.Point represents one location, with longitude before latitude as in GeoJSON. LineString joins points into a path. Polygon defines an area with an outer boundary, or shell, and optional inner boundaries, or holes. A LinearRing supplies the closed loop of points used for a polygon boundary.
Using geospatial types in events and read models
Section titled “Using geospatial types in events and read models”Declare the geometry as a property on the event and on the read model that will hold it. These examples record an asset’s location, a route’s path and a zone’s boundaries:
using Cratis.Chronicle.Events;using Cratis.Geospatial;
[EventType]public record GeospatialAssetLocationUpdated(Point Location);
[EventType]public record GeospatialRouteCreated(LineString Path);
[EventType]public record GeospatialZoneEstablished(Polygon Boundaries);
public record GeospatialAssetReadModel(Guid Id, Point Location);public record GeospatialRouteReadModel(Guid Id, LineString Path);public record GeospatialZoneReadModel(Guid Id, Polygon Boundaries);import io.cratis.chronicle.events.EventTypeimport io.cratis.fundamentals.geospatial.LineStringimport io.cratis.fundamentals.geospatial.Pointimport io.cratis.fundamentals.geospatial.Polygon
@EventTypedata class GeospatialAssetLocationUpdated(val location: Point)
@EventTypedata class GeospatialRouteCreated(val path: LineString)
@EventTypedata class GeospatialZoneEstablished(val boundaries: Polygon)
data class GeospatialAssetReadModel(val id: String, val location: Point)data class GeospatialRouteReadModel(val id: String, val path: LineString)data class GeospatialZoneReadModel(val id: String, val boundaries: Polygon)import io.cratis.chronicle.events.EventType;import io.cratis.fundamentals.geospatial.LineString;import io.cratis.fundamentals.geospatial.Point;import io.cratis.fundamentals.geospatial.Polygon;
@EventTyperecord GeospatialAssetLocationUpdated(Point location) {}
@EventTyperecord GeospatialRouteCreated(LineString path) {}
@EventTyperecord GeospatialZoneEstablished(Polygon boundaries) {}
record GeospatialAssetReadModel(String id, Point location) {}record GeospatialRouteReadModel(String id, LineString path) {}record GeospatialZoneReadModel(String id, Polygon boundaries) {}Elixir does not support this workflow yet.TypeScript does not support this workflow yet.A projection can copy the geometry into the read model through AutoMap; it does not need to map each coordinate separately:
using Cratis.Chronicle.Events;using Cratis.Chronicle.Projections;using Cratis.Geospatial;
[EventType]public record GeospatialProjAssetLocationUpdated(Point Location);
public record GeospatialProjAssetReadModel(Guid Id, Point Location);
public class GeospatialProjAssetProjection : IProjectionFor<GeospatialProjAssetReadModel>{ // AutoMap picks up the Point-typed property automatically — no manual mapping needed public void Define(IProjectionBuilderFor<GeospatialProjAssetReadModel> builder) => builder .From<GeospatialProjAssetLocationUpdated>();}import io.cratis.chronicle.events.EventTypeimport io.cratis.fundamentals.geospatial.Pointimport io.cratis.chronicle.projections.IProjectionBuilderForimport io.cratis.chronicle.projections.IProjectionForimport io.cratis.chronicle.projections.Projection
@EventTypedata class GeospatialProjAssetLocationUpdated(val location: Point)
data class GeospatialProjAssetReadModel(val id: String = "", val location: Point? = null)
// AutoMap picks up the Point-typed property automatically - no manual mapping needed@Projectionclass GeospatialProjAssetProjection : IProjectionFor<GeospatialProjAssetReadModel> { override fun define(builder: IProjectionBuilderFor<GeospatialProjAssetReadModel>) { builder.from(GeospatialProjAssetLocationUpdated::class) }}import io.cratis.chronicle.events.EventType;import io.cratis.fundamentals.geospatial.Point;import io.cratis.chronicle.projections.IProjectionBuilderFor;import io.cratis.chronicle.projections.IProjectionFor;import io.cratis.chronicle.projections.Projection;
import io.cratis.chronicle.java.ProjectionBuilderJavaBridge;
@EventTyperecord GeospatialProjAssetLocationUpdated(Point location) {}
record GeospatialProjAssetReadModel(String id, Point location) {}
// AutoMap picks up the Point-typed property automatically - no manual mapping needed@Projectionclass GeospatialProjAssetProjection implements IProjectionFor<GeospatialProjAssetReadModel> { @Override public void define(IProjectionBuilderFor<GeospatialProjAssetReadModel> builder) { ProjectionBuilderJavaBridge.from(builder, GeospatialProjAssetLocationUpdated.class); }}Elixir does not support this workflow yet.TypeScript does not support this workflow yet.JSON schema
Section titled “JSON schema”The .NET schema generator describes a geospatial value as a leaf: an object carrying its format, with no sub-properties. The format identifies the type for storage and materialization, which turns stored content back into typed values:
{ "type": "object", "format": "point" }{ "type": "object", "format": "linestring" }{ "type": "object", "format": "polygon" }The .NET storage path materializes each geometry as one typed value. Its GeoJSON converter owns the coordinates and other members inside that value. Flattening them into event or read-model properties would cause coordinates to be dropped during conversion.
Storage sinks use the format annotation to recover the typed value. The Workbench also uses it to recognize and display a geographic field.
On the wire, the value itself is GeoJSON:
{ "pickedUpAt": { "type": "Point", "coordinates": [10.7522, 59.9139] }}Longitude comes first, then latitude, matching both GeoJSON and the Point constructor.
Geospatial values alongside PII
Section titled “Geospatial values alongside PII”An event may contain both a location and personally identifiable information (PII), such as a venue location beside an organizer’s name. When a property is marked [PII], Chronicle’s compliance pass visits the whole document, including the geospatial value.
An unmarked geospatial value stays in plaintext. The pass treats it as one value instead of descending into its GeoJSON members, which have no separate schema properties for [PII] markers. Decide whether the location itself is personal data before storing it; a public venue and a person’s precise location have different privacy implications.
Storage
Section titled “Storage”MongoDB sink
Section titled “MongoDB sink”The MongoDB read-model sink uses the following BSON (binary JSON) shapes, which differ from the GeoJSON wire format above:
Point: Flat document with longitude and latitude
{ "longitude": 10.456, "latitude": 42.123 }LineString: Array of points
[ { "longitude": 10.456, "latitude": 42.123 }, { "longitude": 11.789, "latitude": 43.456 }]Polygon: Document with shell (outer ring) and holes (inner rings)
{ "shell": [ { "longitude": 0, "latitude": 0 }, { "longitude": 10, "latitude": 0 }, { "longitude": 10, "latitude": 10 }, { "longitude": 0, "latitude": 10 }, { "longitude": 0, "latitude": 0 } ], "holes": []}Chronicle registers these BSON serializers automatically.
SQL sink
Section titled “SQL sink”Geospatial types appear as objects in the schema, so the SQL read-model sink stores them in JSON columns. No additional migration or configuration is required for these types.
Workbench display
Section titled “Workbench display”The Chronicle Workbench recognizes geospatial format markers in event schemas and renders them as human-readable strings rather than expanding nested structures:
Point: lat: 42.123, long: 10.456LineString: [lat: 42.123, long: 10.456], [lat: 43.456, long: 11.789]Polygon: shell with 5 points, 0 holesOnce the event and read-model properties are defined, use declarative projections to build the view. If the event contains personal data, review PII protection before choosing what location detail to retain.