Class TileGrid
- Namespace
- SpatialNET.IO
- Assembly
- SpatialNET.IO.dll
A tile grid in any coordinate reference system: origin, origin corner, tile size in pixels and one resolution (world units per pixel) per level. The grid only does arithmetic; it never projects.
public sealed class TileGridInheritance
Inherited Members
Constructors
TileGrid(double, double, IEnumerable<double>, int, int, TileOrigin)
Creates a grid.
public TileGrid(double originX, double originY, IEnumerable<double> resolutions, int tileWidth = 256, int tileHeight = 256, TileOrigin origin = TileOrigin.UpperLeft)Parameters
originXdouble-
The X coordinate of the origin.
originYdouble-
The Y coordinate of the origin.
resolutionsIEnumerable<double>-
World units per pixel per level, level 0 first.
tileWidthint-
The tile width in pixels; default 256.
tileHeightint-
The tile height in pixels; default 256.
originTileOrigin-
The origin corner; default SpatialNET.IO.TileOrigin.UpperLeft.
Exceptions
- ArgumentNullException
-
resolutionsisnull. - ArgumentOutOfRangeException
-
The origin is not finite, a resolution is not finite and positive, or a tile size is not positive.
Fields
MetersPerInch
The meters per inch used to convert between scale and resolution (OGC: 0.0254).
public const double MetersPerInch = 0.0254Field Value
WebMercatorHalfExtent
The half extent of the WebMercator (EPSG:3857) world: 20037508.342789244 m.
public const double WebMercatorHalfExtent = 20037508.342789244Field Value
Properties
LevelCount
The number of levels.
public int LevelCount { get; }Property Value
Origin
The origin corner.
public TileOrigin Origin { get; }Property Value
OriginX
The X coordinate of the origin.
public double OriginX { get; }Property Value
OriginY
The Y coordinate of the origin.
public double OriginY { get; }Property Value
Resolutions
The resolutions (world units per pixel) per level.
public IReadOnlyList<double> Resolutions { get; }Property Value
TileHeight
The tile height in pixels.
public int TileHeight { get; }Property Value
TileWidth
The tile width in pixels.
public int TileWidth { get; }Property Value
Methods
FromScales(double, double, IEnumerable<double>, double, int, int, TileOrigin)
Creates a grid from map scales (as tile service metadata usually lists them).
public static TileGrid FromScales(double originX, double originY, IEnumerable<double> scales, double dpi = 96, int tileWidth = 256, int tileHeight = 256, TileOrigin origin = TileOrigin.UpperLeft)Parameters
originXdouble-
The X coordinate of the origin.
originYdouble-
The Y coordinate of the origin.
scalesIEnumerable<double>-
The scale denominators per level, level 0 first.
dpidouble-
The dots per inch the scales refer to; default 96.
tileWidthint-
The tile width in pixels; default 256.
tileHeightint-
The tile height in pixels; default 256.
originTileOrigin-
The origin corner; default SpatialNET.IO.TileOrigin.UpperLeft.
Returns
Exceptions
- ArgumentNullException
-
scalesisnull. - ArgumentOutOfRangeException
-
A value is out of range (see the constructor), or
dpiis not finite and positive.
Resolution(int)
The resolution of a level.
public double Resolution(int level)Parameters
levelint-
The level.
Returns
Exceptions
- ArgumentOutOfRangeException
-
levelis not a level of the grid.
ResolutionToScale(double, double)
Converts a resolution into a scale denominator: resolution · dpi / 0.0254.
public static double ResolutionToScale(double resolution, double dpi = 96)Parameters
resolutiondouble-
The resolution in world units (meters) per pixel.
dpidouble-
The dots per inch; default 96.
Returns
Exceptions
- ArgumentOutOfRangeException
-
dpiis not finite and positive.
Scale(int, double)
The scale denominator of a level.
public double Scale(int level, double dpi = 96)Parameters
Returns
Exceptions
- ArgumentOutOfRangeException
-
levelis not a level of the grid, ordpiis invalid.
ScaleToResolution(double, double)
Converts a scale denominator into a resolution: scale · 0.0254 / dpi.
public static double ScaleToResolution(double scale, double dpi = 96)Parameters
Returns
Exceptions
- ArgumentOutOfRangeException
-
dpiis not finite and positive.
TileAt(int, double, double)
The tile that contains a world coordinate; a point on a tile border belongs to the tile right of / away from the origin.
public (long Row, long Column) TileAt(int level, double x, double y)Parameters
Returns
Exceptions
- ArgumentOutOfRangeException
-
levelis not a level of the grid.
TileEnvelope(int, long, long)
The world envelope of a tile.
public Envelope2D TileEnvelope(int level, long row, long column)Parameters
levelint-
The level.
rowlong-
The row, counted from the origin corner.
columnlong-
The column, counted from the origin to the right.
Returns
Exceptions
- ArgumentOutOfRangeException
-
levelis not a level of the grid.
TileRange(int, Envelope2D)
The inclusive row and column range of the tiles that meet a world envelope.
public (long MinRow, long MinColumn, long MaxRow, long MaxColumn) TileRange(int level, Envelope2D envelope)Parameters
levelint-
The level.
envelopeEnvelope2D-
The envelope; must not be empty.
Returns
Exceptions
- ArgumentOutOfRangeException
-
levelis not a level of the grid, or the envelope is empty.
TryGetWebMercatorZoom(int, out int, double)
Whether a level of this grid is a standard WebMercator zoom level: same origin (upper left), 256 px tiles and the resolution
of zoom zoom. Tiles of such a level can be served under that z/x/y unchanged.
public bool TryGetWebMercatorZoom(int level, out int zoom, double relativeTolerance = 1E-06)Parameters
levelint-
The level.
zoomint-
The WebMercator zoom, or -1.
relativeTolerancedouble-
The allowed relative difference of origin and resolution; default 1e-6.
Returns
Exceptions
- ArgumentOutOfRangeException
-
levelis not a level of the grid.
TryGetWebMercatorZoom(double, out int, double, double)
Whether a map scale matches a WebMercator zoom level (0..30). The scale is that of the projected plane (as tile services state it, e.g. 1:591657527.59 for zoom 0 at 96 dpi), not the true scale at a latitude.
public static bool TryGetWebMercatorZoom(double scale, out int zoom, double dpi = 96, double relativeTolerance = 1E-06)Parameters
scaledouble-
The scale denominator.
zoomint-
The zoom level, or -1.
dpidouble-
The dots per inch; default 96.
relativeTolerancedouble-
The allowed relative difference; default 1e-6. Use a larger one for rounded scales.
Returns
Exceptions
- ArgumentOutOfRangeException
-
dpiis not finite and positive.
TryGetWebMercatorZoomForResolution(double, out int, double)
Whether a resolution matches a WebMercator zoom level (0..30).
public static bool TryGetWebMercatorZoomForResolution(double resolution, out int zoom, double relativeTolerance = 1E-06)Parameters
resolutiondouble-
The resolution in meters per pixel.
zoomint-
The zoom level, or -1.
relativeTolerancedouble-
The allowed relative difference; default 1e-6.
Returns
WebMercator(int)
The standard WebMercator grid (EPSG:3857, Google/OSM/Mapbox XYZ): origin (-20037508.342789244, 20037508.342789244) upper left, 256 px tiles, level z has 2^z × 2^z tiles. Level = zoom, row = y, column = x.
public static TileGrid WebMercator(int maxZoom = 24)Parameters
maxZoomint-
The highest zoom level; default 24.
Returns
Exceptions
- ArgumentOutOfRangeException
-
maxZoomis not in 0..30.
WebMercatorResolution(int)
The resolution of a WebMercator zoom level: 2 · 20037508.342789244 / 256 / 2^zoom.
public static double WebMercatorResolution(int zoom)Parameters
zoomint-
The zoom level, ≥ 0.
Returns
Exceptions
- ArgumentOutOfRangeException
-
zoomis negative.