Skip to content

Documentation / @interstellar-tools/maps / tileGeoTransform

Function: tileGeoTransform() ​

ts
function tileGeoTransform(
  tile: TileInterface,
  width: number,
  height: number,
  R: number
): GeoTransformInterface;

Defined in: tiles/tile-geotransform.ts:57

Find where a web map tile's pixels lie on the mercator map: the GeoTransformInterface of a grid made from the tile, such as by decodeElevationTile.

Δx=2πR2zw,x0=R(2π(x+12w)2z−π),y0=Rπ(1−2(y+12h)2z)

and Δy likewise with h.

Where:

  • x, y and z are the tile's column, row and zoom, and w×h its size in pixels
  • R is the sphere's radius (m) the tiles were cut for

Units

  • Inputs: R in m; the size in pixels.
  • Output: the transform onto the Mercator map with lambda0 0, in m.

Notes

Parameters ​

ParameterTypeDescription
tileTileInterfaceThe tile, { x, y, z }, as tileAt gives it.
widthnumberWidth of the tile in pixels (an integer, > 0).
heightnumberHeight of the tile in pixels (an integer, > 0).
RnumberRadius of the sphere the tiles were cut for, in m (finite, > 0).

Returns ​

GeoTransformInterface

The transform from the tile's rows and columns to the Mercator map.

Throws ​

  • If R is not finite.
  • If the tile doesn't exist, width or height is not a positive integer, or R is <= 0.

Example ​

ts
// Latitude and longitude of the north-west pixel of a 256 × 256 tile
const transform = tileGeoTransform(tile, 256, 256, 6378137);
const { x, y } = cellToMap(transform, { row: 0, column: 0 });
inverseMercator(x, y, 6378137); // { phi, lambda } in radians

See ​