Skip to content

Npgsql: Enable direct marshalling between CrateDB GEO_SHAPE and .NET GeoJSON types #1299

@amotl

Description

@amotl

Problem

Currently, CrateDB's GEO_SHAPE types cannot be directly marshalled to/from .NET GeoJSON types when using Npgsql. While GEO_POINT works well with NpgsqlPoint, GeoJSON geometry types require manual string serialization.

Current Behavior

The InsertGeoJsonTyped() method in by-language/csharp-npgsql/DemoTypes.cs attempts to use NpgsqlDbType.Geometry but fails with:

System.NotSupportedException: The NpgsqlDbType 'Geometry' isn't present in your 
database. You may need to install an extension or upgrade to a newer version.

Workaround: The InsertGeoJsonString() method manually serializes GeoJSON objects (Point, Polygon, etc.) to JSON strings using JsonConvert.SerializeObject() and passes them as NpgsqlDbType.Json.

Desired Behavior

Enable fluent marshalling similar to PostgreSQL with PostGIS, where GeoJSON types can be directly used:

  • Use Npgsql's PostGIS/GeoJSON Type Plugin
  • Directly pass .NET GeoJSON.Net types (Point, Polygon, etc.) as parameters
  • Directly read GeoJSON types from query results without manual deserialization

Technical Details

  • CrateDB communicates GEO_SHAPE as string types (WKT or GeoJSON format)
  • The PostGIS/GeoJSON plugin expects the database to identify as PostGIS
  • CrateDB does not currently identify itself as PostGIS (see review discussion)

Related

Tasks

  • Investigate why NpgsqlDbType.Geometry is not recognized by CrateDB
  • Determine if CrateDB can/should identify as PostGIS for geometry type compatibility
  • Explore alternative approaches to enable direct GeoJSON type marshalling
  • Consider supporting direct conversion to Npgsql geometry types (NpgsqlLSeg, NpgsqlBox, NpgsqlPath, NpgsqlPolygon, NpgsqlCircle)

/cc @kneth, @seut

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions