MapFormat Class
A format of the maps of a MapCatalog: how the layers of a region are stored, read and written.
public abstract class MapFormatRemarks
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
| Name | Description |
|---|---|
| MapFormat() | Initializes a new instance of the MapFormat class. |
MapFormat()
MapFormat.csInitializes a new instance of the MapFormat class.
protected MapFormat()Properties
| Name | Description |
|---|---|
| FlatGeobuf | 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. |
| GeoJson | 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. |
| Name | Gets the name of the format, such as FlatGeobuf. |
FlatGeobuf
MapFormat.csGeoJson
MapFormat.csGets 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
Name
Methods
| Name | Description |
|---|---|
| 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.csWrites 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)FormatMetadata(MapMetadata, IReadOnlyDictionary<MapLayer, GeoFeatureCollection>)
MapFormat.csWrites 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
metadataMapMetadata- The description of the map.
layersIReadOnlyDictionary<MapLayer, GeoFeatureCollection>- The layers of the map.
Returns
string The indented JSON, with \n line endings.
GetLayerName(MapLayer)
MapFormat.csGets the name of a layer in the files of a map, such as borders, states-provinces or marine-areas.
Parameters
layerMapLayer- The layer.
Returns
string The name, in lowercase ASCII letters and hyphens.
Exceptions
ArgumentOutOfRangeExceptionlayeris 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.
Open(string)
Opens the map at a path. The layers are read when they are loaded.
Parameters
pathstring- The path of the map, one that
MapFormat.TryGetRegionaccepts.
Returns
Map The map.
Exceptions
FormatException- The metadata of the map is not valid.
ParseMetadata(string, string)
MapFormat.csReads the metadata of a map written by MapFormat.FormatMetadata. The missing members are null.
protected static MapMetadata ParseMetadata(string region, string json)Parameters
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.
Write overloads
Write(string, Map)
MapFormat.csWrite(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
pathstring- The path of the map, such as the one
MapFormat.GetPathreturns. metadataMapMetadata- The description of the map.
layersIReadOnlyDictionary<MapLayer, GeoFeatureCollection>- The features of each layer; a layer that is not there is not written.