IRI.Maptor.Infrastructure.Sqlite 3.0.0

dotnet add package IRI.Maptor.Infrastructure.Sqlite --version 3.0.0
                    
NuGet\Install-Package IRI.Maptor.Infrastructure.Sqlite -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IRI.Maptor.Infrastructure.Sqlite" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IRI.Maptor.Infrastructure.Sqlite" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="IRI.Maptor.Infrastructure.Sqlite" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IRI.Maptor.Infrastructure.Sqlite --version 3.0.0
                    
#r "nuget: IRI.Maptor.Infrastructure.Sqlite, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IRI.Maptor.Infrastructure.Sqlite@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IRI.Maptor.Infrastructure.Sqlite&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=IRI.Maptor.Infrastructure.Sqlite&version=3.0.0
                    
Install as a Cake Tool

IRI.Maptor.Infrastructure.Sqlite

NuGet Target

SQLite-based geospatial format support for the Maptor library: readers and map data sources for MBTiles (tiled map storage for offline mapping) and OGC GeoPackage (vector features and raster tiles in a single container). Both formats are cross-platform and work with .NET 8, MAUI, and mobile platforms.

Installation

dotnet add package IRI.Maptor.Infrastructure.Sqlite

Features

  • MbTilesReader — read MBTiles files: metadata, tiles (raster PNG/JPEG/WebP or vector PBF), zoom levels, tile counts, bounds, schema validation
  • MbTilesDataSource — MBTiles-backed raster data source for map viewers (tiles by bounding box and map scale)
  • GpkgVectorReader — read GeoPackage vector layers: layer metadata, geometry column info, features (optionally filtered by bounding box), feature counts, spatial reference systems
  • GeoPackageDataSource — GeoPackage-backed vector data source (FeatureSet loading, bounding-box filtering, text search)
  • GpkgTileReader — read GeoPackage tile layers: tile matrix sets, tile matrices, tiles, zoom levels and ranges
  • GeoPackageTileDataSource — GeoPackage-backed tile data source for map viewers
  • Async variants of the read operations (OpenAsync, GetTileAsync, ReadFeaturesAsync)

Usage

MBTiles - reading tiles

using IRI.Maptor.Infrastructure.Sqlite.MbTiles;
using IRI.Maptor.Core.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();

// Get a specific tile (zoom, column, row in TMS scheme)
byte[]? tileData = reader.GetTile(zoom: 10, column: 512, row: 384);
if (tileData != null)
{
    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();

MBTiles - using the data source

using IRI.Maptor.Infrastructure.Sqlite.MbTiles;
using IRI.Maptor.Core.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;

var tiles = dataSource.GetTiles(boundingBox, mapScale);

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);

GeoPackage - reading vector features

using IRI.Maptor.Infrastructure.Sqlite.GeoPackage;
using IRI.Maptor.Core.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($"  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");

foreach (var feature in features)
{
    Console.WriteLine($"Geometry Type: {feature.TheGeometry?.Type}");

    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();

GeoPackage - using the vector data source

using IRI.Maptor.Infrastructure.Sqlite.GeoPackage;
using IRI.Maptor.Core.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}");

// 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 and geometry column info
var metadata = dataSource.LayerMetadata;
var geomCol = dataSource.GeometryColumn;

// Get feature count
long count = dataSource.GetFeatureCount();

GeoPackage - reading tile layers

using IRI.Maptor.Infrastructure.Sqlite.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();

// Get tile matrix set (pyramid information)
var tileMatrixSet = reader.GetTileMatrixSet("satellite_tiles");
Console.WriteLine($"SRS ID: {tileMatrixSet?.SrsId}");

// 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, tile counts, and zoom range
var zooms = reader.GetZoomLevels("satellite_tiles");
long totalTiles = reader.GetTileCount("satellite_tiles");
var (minZoom, maxZoom) = reader.GetZoomRange("satellite_tiles") ?? (0, 0);

GeoPackage - using the tile data source

using IRI.Maptor.Infrastructure.Sqlite.GeoPackage;
using IRI.Maptor.Core.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);

// 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();

Coordinate systems

MBTiles:

  • Uses the TMS (Tile Map Service) coordinate scheme
  • Y-axis origin at bottom-left (row 0 is at the bottom)
  • Tiles are typically in Web Mercator (EPSG:3857)
  • Bounds are stored in WGS84 (EPSG:4326)

GeoPackage:

  • Uses the XYZ tile scheme for tiles (Y-axis origin at top-left)
  • Supports multiple coordinate reference systems (check srs_id in the metadata)
  • Common systems: 4326 (WGS84 geographic), 3857 (Web Mercator), 900913 (legacy Google Web Mercator)

Converting between tile schemes

// 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;

Async operations

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);

Validation

// 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();

Dependencies

  • Microsoft.Data.Sqlite.Core - SQLite ADO.NET provider
  • SQLitePCLRaw.bundle_e_sqlite3 - native SQLite binaries for all platforms
  • IRI.Maptor.Core.Persistence - Maptor persistence abstractions
  • IRI.Maptor.Core.Spatial - Maptor spatial types and algorithms
  • IRI.Maptor.Core.Ogc - OGC standard implementations

References


NuGet package · Report issues · Back to IRI.Maptor.Infrastructure

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on IRI.Maptor.Infrastructure.Sqlite:

Package Downloads
IRI.Maptor.Presentation.Wpf

The WPF map UI library: the central MapViewer control, MVVM building blocks, layer types (feature, raster, grid, group), cartographic rendering and symbology, tile-service providers, map markers, converters/behaviors, and Excel/Word export helpers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 60 8/23/2026
3.0.0-alpha 51 8/22/2026