MapPiloteGeopackageHelper
Modern .NET library for creating, reading, and bulk-loading GeoPackage (GPKG) data using SQLite and NetTopologySuite.
What This Library Does
- Creates GeoPackages with required core tables
- Creates layers (tables) with geometry + custom attribute columns
- Bulk writes features with validation and progress tracking
- Streams features back with filtering, sorting, and paging
- Modern async patterns with cancellation support
- Schema inspection and validation
- Optional WAL mode for improved concurrency and performance
Quick Start - Modern Fluent API
// Create/open GeoPackage with fluent API
using var geoPackage = await GeoPackage.OpenAsync("data.gpkg", defaultSrid: 3006);
// Create layer with schema
var layer = await geoPackage.EnsureLayerAsync("cities", new Dictionary<string, string>
{
["name"] = "TEXT",
["population"] = "INTEGER"
});
// Create features with geometry
var features = new[]
{
new FeatureRecord(
new Point(674188, 6580251), // Stockholm (SWEREF99 TM)
new Dictionary<string, string?> { ["name"] = "Stockholm", ["population"] = "975000" }),
new FeatureRecord(
new Point(319178, 6399617), // Gothenburg
new Dictionary<string, string?> { ["name"] = "Gothenburg", ["population"] = "583000" })
};
// Bulk insert with validation and progress
var progress = new Progress<BulkProgress>(p =>
Console.WriteLine($"Progress: {p.PercentComplete:F1}%"));
await layer.BulkInsertAsync(features,
new BulkInsertOptions(BatchSize: 1000, ValidateGeometryType: true),
progress);
// Query and access both geometry and attributes
await foreach (var city in layer.ReadFeaturesAsync(
new ReadOptions(WhereClause: "population > 100000", OrderBy: "population DESC")))
{
var point = (Point)city.Geometry!;
Console.WriteLine($"{city.Attributes["name"]}: {city.Attributes["population"]} people at ({point.X}, {point.Y})");
}
Modern Features
| Feature | Description | Example |
|---|
| Async/Await | Proper async support with CancellationToken | await layer.BulkInsertAsync(...) |
| Fluent API | Chain operations naturally | GeoPackage.OpenAsync().EnsureLayerAsync() |