![]() |
VOOZH | about |
dotnet add package IRI.Maptor.Ket.SqlitePersistence --version 2.9.1
NuGet\Install-Package IRI.Maptor.Ket.SqlitePersistence -Version 2.9.1
<PackageReference Include="IRI.Maptor.Ket.SqlitePersistence" Version="2.9.1" />
<PackageVersion Include="IRI.Maptor.Ket.SqlitePersistence" Version="2.9.1" />Directory.Packages.props
<PackageReference Include="IRI.Maptor.Ket.SqlitePersistence" />Project file
paket add IRI.Maptor.Ket.SqlitePersistence --version 2.9.1
#r "nuget: IRI.Maptor.Ket.SqlitePersistence, 2.9.1"
#:package IRI.Maptor.Ket.SqlitePersistence@2.9.1
#addin nuget:?package=IRI.Maptor.Ket.SqlitePersistence&version=2.9.1Install as a Cake Addin
#tool nuget:?package=IRI.Maptor.Ket.SqlitePersistence&version=2.9.1Install as a Cake Tool
SQLite-based geospatial format support for the Maptor library.
This package provides support for reading SQLite-based geospatial formats:
Both formats are cross-platform compatible and work seamlessly with .NET 8, MAUI, and mobile platforms (Android, iOS, Windows, macOS).
MBTiles is a specification for storing tiled map data in SQLite databases for immediate use and for transfer. It's optimized for offline mapping applications.
Features:
Specification: MBTiles Spec
GeoPackage is an OGC standard for geospatial data exchange. It can store multiple types of data in a single file:
Features:
Specification: OGC GeoPackage
dotnet add package IRI.Maptor.Ket.SqlitePersistence
using IRI.Maptor.Ket.SqlitePersistence.MbTiles;
using IRI.Maptor.Sta.Common.Primitives;
// Create and open MBTiles reader
using var reader = new MbTilesReader("path/to/map.mbtiles");
reader.Open();
// Get metadata
var metadata = reader.Metadata;
Console.WriteLine($"Name: {metadata?.Name}");
Console.WriteLine($"Format: {metadata?.Format}");
Console.WriteLine($"Zoom Range: {metadata?.MinZoom} - {metadata?.MaxZoom}");
Console.WriteLine($"Bounds: {metadata?.Bounds}");
// Get available zoom levels
var zoomLevels = reader.GetZoomLevels();
Console.WriteLine($"Available zooms: {string.Join(", ", zoomLevels)}");
// Get a specific tile (zoom, column, row in TMS scheme)
byte[]? tileData = reader.GetTile(zoom: 10, column: 512, row: 384);
if (tileData != null)
{
// Save tile to file or display
File.WriteAllBytes("tile.png", tileData);
}
// Get tile count
long totalTiles = reader.GetTileCount();
long tilesAtZoom10 = reader.GetTileCount(zoomLevel: 10);
// Get bounding box
BoundingBox? bbox = reader.GetBoundingBox();
using IRI.Maptor.Ket.SqlitePersistence.MbTiles;
using IRI.Maptor.Sta.Common.Primitives;
// Create MBTiles data source (for use with map viewers)
using var dataSource = new MbTilesDataSource("path/to/map.mbtiles");
// Get tiles for a specific area and map scale
var boundingBox = new BoundingBox(
xMin: -74.01, yMin: 40.70, // New York City area
xMax: -73.99, yMax: 40.72
);
double mapScale = 10000; // Adjust based on your zoom level
var tiles = dataSource.GetTiles(boundingBox, mapScale);
Console.WriteLine($"Loaded {tiles.Count} tiles");
foreach (var tile in tiles)
{
Console.WriteLine($"Tile: {tile.ImageBytes.Length} bytes, Bounds: {tile.BoundingBox}");
}
// Get available zoom levels
var availableZooms = dataSource.GetAvailableZoomLevels();
// Get specific tile
byte[]? specificTile = dataSource.GetTile(zoom: 10, column: 512, row: 384);
using IRI.Maptor.Ket.SqlitePersistence.GeoPackage;
using IRI.Maptor.Sta.Common.Primitives;
// Create and open GeoPackage vector reader
using var reader = new GpkgVectorReader("path/to/data.gpkg");
reader.Open();
// Get all feature layers
var layers = reader.GetFeatureLayers();
foreach (var layer in layers)
{
Console.WriteLine($"Layer: {layer.TableName}");
Console.WriteLine($" Type: {layer.DataType}");
Console.WriteLine($" Description: {layer.Description}");
Console.WriteLine($" Bounds: ({layer.MinX}, {layer.MinY}) to ({layer.MaxX}, {layer.MaxY})");
}
// Get geometry column information
var geometryInfo = reader.GetGeometryColumnInfo("countries");
Console.WriteLine($"Geometry Column: {geometryInfo?.ColumnName}");
Console.WriteLine($"Geometry Type: {geometryInfo?.GeometryTypeName}");
Console.WriteLine($"SRID: {geometryInfo?.SrsId}");
// Read all features from a layer
var features = reader.ReadFeatures("countries");
Console.WriteLine($"Loaded {features.Count} features");
foreach (var feature in features)
{
Console.WriteLine($"Geometry Type: {feature.TheGeometry?.Type}");
// Access attributes
if (feature.Attributes != null)
{
foreach (var attr in feature.Attributes)
{
Console.WriteLine($" {attr.Key}: {attr.Value}");
}
}
}
// Read features within a bounding box
var bbox = new BoundingBox(-10, 35, 5, 45); // Approximate bounds for Western Europe
var filteredFeatures = reader.ReadFeatures("countries", bbox);
// Get feature count
long featureCount = reader.GetFeatureCount("countries");
// Get spatial reference systems
var srsList = reader.GetSpatialReferenceSystems();
using IRI.Maptor.Ket.SqlitePersistence.GeoPackage;
using IRI.Maptor.Sta.Common.Primitives;
// Create GeoPackage vector data source
using var dataSource = new GeoPackageDataSource("path/to/data.gpkg", "countries");
// Get all features as FeatureSet
var featureSet = await dataSource.GetAsFeatureSetAsync();
Console.WriteLine($"Total features: {featureSet.Features.Count}");
Console.WriteLine($"SRID: {featureSet.Srid}");
// Get features within a bounding box
var bbox = new BoundingBox(-10, 35, 5, 45);
var filteredFeatureSet = await dataSource.GetAsFeatureSetAsync(bbox);
// Search features by text
var searchResults = await dataSource.SearchAsync("Germany");
// Get layer metadata
var metadata = dataSource.LayerMetadata;
Console.WriteLine($"Layer: {metadata?.TableName}");
Console.WriteLine($"Description: {metadata?.Description}");
// Get geometry column info
var geomCol = dataSource.GeometryColumn;
Console.WriteLine($"Geometry: {geomCol?.GeometryTypeName}");
// Get feature count
long count = dataSource.GetFeatureCount();
using IRI.Maptor.Ket.SqlitePersistence.GeoPackage;
// Create and open GeoPackage tile reader
using var reader = new GpkgTileReader("path/to/tiles.gpkg");
reader.Open();
// Get all tile layers
var tileLayers = reader.GetTileLayers();
foreach (var layer in tileLayers)
{
Console.WriteLine($"Tile Layer: {layer.TableName}");
Console.WriteLine($" Description: {layer.Description}");
}
// Get tile matrix set (pyramid information)
var tileMatrixSet = reader.GetTileMatrixSet("satellite_tiles");
Console.WriteLine($"SRS ID: {tileMatrixSet?.SrsId}");
Console.WriteLine($"Bounds: {tileMatrixSet?.MinX},{tileMatrixSet?.MinY} to {tileMatrixSet?.MaxX},{tileMatrixSet?.MaxY}");
// Get all zoom levels (tile matrices)
var matrices = reader.GetTileMatrices("satellite_tiles");
foreach (var matrix in matrices)
{
Console.WriteLine($"Zoom {matrix.ZoomLevel}: {matrix.MatrixWidth}x{matrix.MatrixHeight} tiles");
Console.WriteLine($" Tile size: {matrix.TileWidth}x{matrix.TileHeight} pixels");
}
// Get a specific tile
byte[]? tile = reader.GetTile("satellite_tiles", zoom: 10, column: 512, row: 384);
// Get available zoom levels
var zooms = reader.GetZoomLevels("satellite_tiles");
// Get tile count
long totalTiles = reader.GetTileCount("satellite_tiles");
long tilesAtZoom = reader.GetTileCount("satellite_tiles", zoomLevel: 10);
// Get zoom range
var (minZoom, maxZoom) = reader.GetZoomRange("satellite_tiles") ?? (0, 0);
using IRI.Maptor.Ket.SqlitePersistence.GeoPackage;
using IRI.Maptor.Sta.Common.Primitives;
// Create GeoPackage tile data source
using var dataSource = new GeoPackageTileDataSource("path/to/tiles.gpkg", "satellite_tiles");
// Get tiles for a specific area and map scale
var bbox = new BoundingBox(-74.01, 40.70, -73.99, 40.72); // NYC
double mapScale = 10000;
var tiles = dataSource.GetTiles(bbox, mapScale);
Console.WriteLine($"Loaded {tiles.Count} tiles");
// Get available zoom levels
var zoomLevels = dataSource.GetAvailableZoomLevels();
// Get specific tile
byte[]? tile = dataSource.GetTile(zoom: 10, column: 512, row: 384);
// Get metadata
var metadata = dataSource.LayerMetadata;
var tileMatrixSet = dataSource.TileMatrixSet;
// Get zoom range
var zoomRange = dataSource.GetZoomRange();
Console.WriteLine($"Zoom range: {zoomRange?.minZoom} - {zoomRange?.maxZoom}");
srs_id in metadata for the coordinate system4326 - WGS84 (Geographic)3857 - Web Mercator900913 - Google Web Mercator (legacy)// Converting from XYZ to TMS
int xyzY = 384;
int zoom = 10;
int maxTileIndex = (1 << zoom) - 1; // 2^zoom - 1
int tmsY = maxTileIndex - xyzY;
// Converting from TMS to XYZ
int tmsYValue = 639;
int xyzYValue = maxTileIndex - tmsYValue;
Both readers support async operations:
// MBTiles async
using var mbReader = new MbTilesReader("map.mbtiles");
await mbReader.OpenAsync();
byte[]? tile = await mbReader.GetTileAsync(10, 512, 384);
// GeoPackage async
using var gpReader = new GpkgVectorReader("data.gpkg");
await gpReader.OpenAsync();
using var tileReader = new GpkgTileReader("tiles.gpkg");
await tileReader.OpenAsync();
byte[]? gpTile = await tileReader.GetTileAsync("layer", 10, 512, 384);
β
.NET 8+
β
MAUI (Android, iOS, Windows, macOS)
β
Desktop (Windows, Linux, macOS)
β
Mobile (Android, iOS)
Microsoft.Data.Sqlite.Core - Modern SQLite ADO.NET providerSQLitePCLRaw.bundle_e_sqlite3 - Native SQLite binaries for all platformsIRI.Maptor.Sta.Persistence - Maptor persistence abstractionsIRI.Maptor.Sta.Spatial - Maptor spatial types and algorithmsIRI.Maptor.Sta.Ogc - OGC standard implementations// Validate MBTiles schema
using var mbReader = new MbTilesReader("map.mbtiles");
mbReader.Open();
bool isMbTilesValid = mbReader.ValidateSchema();
// Validate GeoPackage schema
using var gpReader = new GpkgVectorReader("data.gpkg");
gpReader.Open();
bool isGpkgValid = gpReader.ValidateSchema();
try
{
using var reader = new MbTilesReader("map.mbtiles");
reader.Open();
var tile = reader.GetTile(10, 512, 384);
if (tile == null)
{
Console.WriteLine("Tile not found");
}
}
catch (FileNotFoundException ex)
{
Console.WriteLine($"File not found: {ex.Message}");
}
catch (InvalidOperationException ex)
{
Console.WriteLine($"Invalid operation: {ex.Message}");
}
catch (SqliteException ex)
{
Console.WriteLine($"SQLite error: {ex.Message}");
}
using statements or call Dispose() to release resourcesValidateSchema() to ensure files are valid before processingContributions are welcome! Please see the Maptor Contributing Guide.
This package is part of the Maptor library and is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.10.0-alpha | 87 | 5/7/2026 |
| 2.9.1 | 117 | 4/16/2026 |
| 2.9.1-alpha | 95 | 4/19/2026 |
| 2.9.0 | 123 | 2/3/2026 |
| 2.9.0-alpha | 110 | 2/3/2026 |
| 2.8.13 | 154 | 12/26/2025 |
| 2.8.13-alpha | 136 | 12/26/2025 |
| 2.8.12 | 465 | 12/11/2025 |
| 2.8.12-alpha | 242 | 12/11/2025 |
| 2.8.11 | 441 | 11/19/2025 |
| 2.8.11-alpha | 422 | 11/19/2025 |
| 2.8.10 | 200 | 11/8/2025 |
| 2.8.10-alpha | 182 | 11/8/2025 |
| 2.8.9-alpha | 167 | 11/1/2025 |