This library provides a seamless way to convert geometries between DuckDB's internal geometry format and NetTopologySuite (NTS) geometries in C#. It supports reading and writing geometries from/to byte arrays and streams, making it easy to integrate with DuckDB databases and work with spatial data in .NET applications.
You can install the library via NuGet:
dotnet add package DuckDb.Spatial.IO.Net
Below are examples demonstrating how to use the library for common operations: reading from and writing to byte arrays and streams.
To convert a DuckDB geometry stored as a byte array into an NTS geometry:
using DuckDb.Spatial.IO.Net;
...
var reader = new GeometryReader();
var geometry = reader.Read(bytes);
If your DuckDB geometry is stored in a stream, you can read it directly:
using DuckDb.Spatial.IO.Net;
...
var reader = new GeometryReader();
var geometry = reader.Read(stream);
To convert an NTS geometry into a DuckDB-compatible byte array:
using DuckDb.Spatial.IO.Net;
...
var writer = new GeometryWriter();
var bytes = writer.Write(geometry);
If you need to write an NTS geometry to a stream in DuckDB-compatible format:
using DuckDb.Spatial.IO.Net;
...
var writer = new GeometryWriter();
writer.Write(geometry, stream);
The library supports all geometry types compatible with both DuckDB and NetTopologySuite, including:
- Point
- LineString
- Polygon
- MultiPoint
- MultiLineString
- MultiPolygon
- GeometryCollection
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.