Skip to content

Geometry Handling

Formation uses WKT (Well-Known Text) for geometry storage via NetTopologySuite in the backend and GeoJSON for map rendering in the frontend.

Geometry is stored as SQL Server geometry types and exposed via the API as WKT strings:

// Entity model
public Point? DbLocation { get; set; } // POINT(-0.1234 51.5678)
// API exposure
[NotMapped]
public string? Location { get; set; } // "POINT(-0.1234 51.5678)"

The frontend converts between WKT and GeoJSON for map rendering:

import { wktToGeoJSON, geojsonToWKT } from '@terraformer/wkt'
// Display on map
const geoJson = wktToGeoJSON('POINT(-0.1234 51.5678)')
// Send back to API
const wkt = geojsonToWKT(geoJson)

The GeometryValidationService filters entities with corrupt geometries before returning them from the API. Invalid geometries have their Location or Boundary set to null, with a warning logged.

// Called automatically in controllers
_geometryValidationService.FilterInvalidGeometries(results);

This prevents “shell is empty” errors when rendering invalid geometries on the frontend.