GeoPackageMapFormat Class

The format that stores a map as one GeoPackage file named after its region, such as France.gpkg: a feature table per layer, with an R-tree spatial index, that QGIS, GDAL and ArcGIS open.

public sealed class GeoPackageMapFormat : MapFormat

Remarks

The file is a GeoPackage 1.4 in WGS 84 (EPSG:4326). A layer is the table named after MapFormat.GetLayerName, with hyphens replaced by underscores, such as states_provinces: its identifier is the name of the region and of the layer, and its description the attribution. The metadata of the map, the JSON of the metadata.json file of the folder formats, is in the metadata extension, with the scope of the whole file.

The property values get the type of their column: a Boolean for BOOLEAN, an Int32 for MEDIUMINT, a Int64 for INTEGER, a Double for DOUBLE, a DateTimeOffset for DATETIME, an array of bytes for BLOB and a String for TEXT. The writer gives a column the type of its values, as the FlatGeobuf writer does, and the text of the values for other mixes.

Reading a file needs the native SQLite library of Microsoft.Data.Sqlite, with its R-tree module.

Inheritance
MapFormat GeoPackageMapFormat

Properties

NameDescription
InstanceGets the GeoPackage format.
NameGets the name of the format, such as FlatGeobuf.

Gets the GeoPackage format.

public static GeoPackageMapFormat Instance { get; }

Property value

GeoPackageMapFormat

Gets the name of the format, such as FlatGeobuf.

public override string Name { get; }

Property value

string

Methods

NameDescription
GetPath(string, string)Gets the path of the map of a region in the folder of a catalog, such as the folder maps/France or the file maps/France.gpkg.
Open(string)Opens the map at a path. The layers are read when they are loaded.
TryGetRegion(string, string?)Gets the region of the map at a path, when the file or folder at this path is a map of this format.
Write(string, MapMetadata, IReadOnlyDictionary<MapLayer, GeoFeatureCollection>)Writes a map: its layers, and its metadata. The layers of a map that was at this path, and that layers does not have, are removed.

GetPath(string, string)

GeoPackageMapFormat.cs

Gets the path of the map of a region in the folder of a catalog, such as the folder maps/France or the file maps/France.gpkg.

public override string GetPath(string directory, string region)

Parameters

directory string
The folder of the catalog.
region string
The name of the region.

Returns

string The path; the map may not exist.

Opens the map at a path. The layers are read when they are loaded.

public override Map Open(string path)

Parameters

path string
The path of the map, one that MapFormat.TryGetRegion accepts.

Returns

Map The map.

Exceptions

FormatException
The file is not a GeoPackage, or its metadata is not valid.

TryGetRegion(string, string?)

GeoPackageMapFormat.cs

Gets the region of the map at a path, when the file or folder at this path is a map of this format.

public override bool TryGetRegion(string path, out string? region)

Parameters

path string
The path of a file or a folder of a catalog.
region string?
The name of the region, or null when the path is not a map of this format.

Returns

bool true when the path is a map of this format; otherwise, false.

Write(string, MapMetadata, IReadOnlyDictionary<MapLayer, GeoFeatureCollection>)

GeoPackageMapFormat.cs

Writes a map: its layers, and its metadata. The layers of a map that was at this path, and that layers does not have, are removed.

public override void Write(string path, MapMetadata metadata, IReadOnlyDictionary<MapLayer, GeoFeatureCollection> layers)

Parameters

path string
The path of the map, such as the one MapFormat.GetPath returns.
metadata MapMetadata
The description of the map.
layers IReadOnlyDictionary<MapLayer, GeoFeatureCollection>
The features of each layer; a layer that is not there is not written.

Exceptions

ArgumentException
A property cannot be a column of a table: its name is fid or geom, or differs from another one only by case.

Remarks

The file is replaced. Its dates, the last change of the layers, are MapMetadata.LastModified, else the current date: with the same date, the same map gives the same file.