MapCatalog Class

The maps of a folder: a folder or a file per region, in one of the formats of the catalog.

public sealed class MapCatalog

Remarks

By default, a catalog reads the folder formats, MapFormat.FlatGeobuf and MapFormat.GeoJson: a region is a folder with a file per layer and a metadata.json file. Pass the formats to read other formats, such as the GeoPackageMapFormat of Meziantou.Framework.Geo.Maps.GeoPackage. The tools/Meziantou.Framework.Geo.Maps.Tool tool of the repository writes the maps; the packages it makes with --package-content files copy them to a maps folder next to the application. The published packages, Meziantou.Framework.Geo.Maps.Data.<Key>, embed the map in an assembly instead, opened with a static extension property of Map, such as Map.Region_France.

Constructors

NameDescription
MapCatalog(string)Initializes a new instance of the MapCatalog class that reads the folder formats, MapFormat.FlatGeobuf and MapFormat.GeoJson.
MapCatalog(string, IEnumerable<MapFormat>)Initializes a new instance of the MapCatalog class.

MapCatalog overloads

MapCatalog(string)

MapCatalog.cs

Initializes a new instance of the MapCatalog class that reads the folder formats, MapFormat.FlatGeobuf and MapFormat.GeoJson.

public MapCatalog(string directory)
Parameters
directory string
The folder that holds the maps.

MapCatalog(string, IEnumerable<MapFormat>)

MapCatalog.cs

Initializes a new instance of the MapCatalog class.

public MapCatalog(string directory, IEnumerable<MapFormat> formats)
Parameters
directory string
The folder that holds the maps.
formats IEnumerable<MapFormat>
The formats of the maps, in order of preference: when a region has maps in several formats, the first format wins.
Exceptions
ArgumentException
formats is empty.

Properties

NameDescription
DefaultGets the catalog of the maps folder next to the application, where the packages of map bundles made with --package-content files copy their regions, with the default formats.
DefaultFormatsGets the formats a catalog reads by default: MapFormat.FlatGeobuf, then MapFormat.GeoJson.
DirectoryGets the full path of the folder of the catalog.
FormatsGets the formats of the catalog, in order of preference.
RegionsGets the names of the regions of the catalog, in ordinal order, or an empty list when the folder does not exist.

Gets the catalog of the maps folder next to the application, where the packages of map bundles made with --package-content files copy their regions, with the default formats.

public static MapCatalog Default { get; }

Property value

MapCatalog

DefaultFormats

MapCatalog.cs

Gets the formats a catalog reads by default: MapFormat.FlatGeobuf, then MapFormat.GeoJson.

public static IReadOnlyList<MapFormat> DefaultFormats { get; }

Directory

MapCatalog.cs

Gets the full path of the folder of the catalog.

public string Directory { get; }

Property value

string

Gets the formats of the catalog, in order of preference.

public IReadOnlyList<MapFormat> Formats { get; }

Gets the names of the regions of the catalog, in ordinal order, or an empty list when the folder does not exist.

public IReadOnlyList<string> Regions { get; }

Property value

IReadOnlyList<string>

Methods

NameDescription
Contains(string)Gets a value that indicates whether the catalog has the map of a region.
GetMap(string)Gets the map of a region.
TryGetMap(string, Map?)Gets the map of a region, when the catalog has it.

Contains(string)

MapCatalog.cs

Gets a value that indicates whether the catalog has the map of a region.

public bool Contains(string region)

Parameters

region string
The name of the region, such as World, Europe or Switzerland.

Returns

bool true when the catalog has a map of the region in one of its formats; otherwise, false.

Exceptions

ArgumentException
region is empty or is not the name of a file.

GetMap(string)

MapCatalog.cs

Gets the map of a region.

public Map GetMap(string region)

Parameters

region string
The name of the region, such as World, Europe or Switzerland.

Returns

Map The map.

Exceptions

ArgumentException
region is empty or is not the name of a file.
KeyNotFoundException
The catalog has no map of this region in its formats.
FormatException
The metadata of the map is not valid.

TryGetMap(string, Map?)

MapCatalog.cs

Gets the map of a region, when the catalog has it.

public bool TryGetMap(string region, out Map? map)

Parameters

region string
The name of the region, such as World, Europe or Switzerland.
map Map?
The map, or null when the catalog does not have it.

Returns

bool true when the catalog has the map of the region; otherwise, false.

Exceptions

ArgumentException
region is empty or is not the name of a file.
FormatException
The metadata of the map is not valid.