Skip to content

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.

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: []);
}

View C# snippet source on GitHub

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);

View C# snippet source on GitHub

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>();
}

View C# snippet source on GitHub

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.

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.

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.

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.

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.456
LineString: [lat: 42.123, long: 10.456], [lat: 43.456, long: 11.789]
Polygon: shell with 5 points, 0 holes

Once 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.