MapFormat Class

A format of the maps of a MapCatalog: how the layers of a region are stored, read and written.

public abstract class MapFormat

Remarks

MapFormat.FlatGeobuf and MapFormat.GeoJson store a map as a folder named after the region, with a file per layer and a metadata.json file. Other formats come from other packages, such as the GeoPackageMapFormat of Meziantou.Framework.Geo.Maps.GeoPackage, which stores a map as one GeoPackage file.

Derive from this class to read and write another format.

Constructors

NameDescription
MapFormat()Initializes a new instance of the MapFormat class.

MapFormat()

MapFormat.cs

Initializes a new instance of the MapFormat class.

protected MapFormat()

Properties

NameDescription
FlatGeobufGets the format that stores a map as a folder with a FlatGeobuf file per layer, such as borders.fgb: compact, with a spatial index. It is the format of the generator by default.
GeoJsonGets the format that stores a map as a folder with a GeoJSON file per layer, such as borders.geojson: text that web libraries read, but several times larger than FlatGeobuf, and without spatial index, so a box query reads the whole layer.
NameGets the name of the format, such as FlatGeobuf.

FlatGeobuf

MapFormat.cs

Gets the format that stores a map as a folder with a FlatGeobuf file per layer, such as borders.fgb: compact, with a spatial index. It is the format of the generator by default.

public static MapFormat FlatGeobuf { get; }

Property value

MapFormat

Gets the format that stores a map as a folder with a GeoJSON file per layer, such as borders.geojson: text that web libraries read, but several times larger than FlatGeobuf, and without spatial index, so a box query reads the whole layer.

public static MapFormat GeoJson { get; }

Property value

MapFormat

Name

Gets the name of the format, such as FlatGeobuf.

public abstract string Name { get; }

Property value

string

Methods

NameDescription
FormatDate(DateTimeOffset)Writes a date as the metadata does: in ISO 8601, in UTC, to the millisecond, such as 2026-11-06T00:00:00.000Z, the form of the dates of GeoPackage.
FormatMetadata(MapMetadata, IReadOnlyDictionary<MapLayer, GeoFeatureCollection>)Writes the metadata of a map as JSON, the content of the metadata.json file of the folder formats: region, name, attribution, bounds (west, south, east, north), lastModified, the number of features of each layer, layers, and the sources (name, url, license).
GetLayerName(MapLayer)Gets the name of a layer in the files of a map, such as borders, states-provinces or marine-areas.
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.
ParseMetadata(string, string)Reads the metadata of a map written by MapFormat.FormatMetadata. The missing members are null.
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, Map)Writes a map in this format, such as a map of another format to convert it: every layer is loaded.
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.

FormatDate(DateTimeOffset)

MapFormat.cs

Writes a date as the metadata does: in ISO 8601, in UTC, to the millisecond, such as 2026-11-06T00:00:00.000Z, the form of the dates of GeoPackage.

protected static string FormatDate(DateTimeOffset date)

Parameters

date DateTimeOffset
The date.

Returns

string The text.

FormatMetadata(MapMetadata, IReadOnlyDictionary<MapLayer, GeoFeatureCollection>)

MapFormat.cs

Writes the metadata of a map as JSON, the content of the metadata.json file of the folder formats: region, name, attribution, bounds (west, south, east, north), lastModified, the number of features of each layer, layers, and the sources (name, url, license).

protected static string FormatMetadata(MapMetadata metadata, IReadOnlyDictionary<MapLayer, GeoFeatureCollection> layers)

Parameters

metadata MapMetadata
The description of the map.
layers IReadOnlyDictionary<MapLayer, GeoFeatureCollection>
The layers of the map.

Returns

string The indented JSON, with \n line endings.

GetLayerName(MapLayer)

MapFormat.cs

Gets the name of a layer in the files of a map, such as borders, states-provinces or marine-areas.

public static string GetLayerName(MapLayer layer)

Parameters

layer MapLayer
The layer.

Returns

string The name, in lowercase ASCII letters and hyphens.

Exceptions

ArgumentOutOfRangeException
layer is not a layer.

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.

public abstract 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.

Open(string)

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

public abstract Map Open(string path)

Parameters

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

Returns

Map The map.

Exceptions

FormatException
The metadata of the map is not valid.

ParseMetadata(string, string)

MapFormat.cs

Reads the metadata of a map written by MapFormat.FormatMetadata. The missing members are null.

protected static MapMetadata ParseMetadata(string region, string json)

Parameters

region string
The name of the region, used when the JSON has no region.
json string
The JSON.

Returns

MapMetadata The description of the map.

Exceptions

FormatException
The JSON is not valid, or its bounds are not finite numbers.

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.

public abstract 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 overloads

Write(string, Map)

MapFormat.cs

Writes a map in this format, such as a map of another format to convert it: every layer is loaded.

public void Write(string path, Map map)
Parameters
path string
The path of the map, such as the one MapFormat.GetPath returns.
map Map
The map.

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.

public abstract 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.