Documentation / @interstellar-tools/maps / stitchTiles
Function: stitchTiles()
ts
function stitchTiles(
tiles: readonly TileGridInterface[],
R: number
): StitchedTilesInterface;Defined in: tiles/stitch-tiles.ts:92
Stitch neighbouring tiles into one grid, such as a block of elevation tiles for an area larger than a tile, and find where it lies on the map.
The tiles must fill a rectangle of tiles at one zoom, each with a grid of the same size. Its cells' size, on the ground, is taken at the middle of the whole block, as decodeElevationTile takes a single tile's:
Where:
is the sphere's radius (m) the tiles were cut for is the zoom, a tile's width in cells, and likewise with its height and are the block's first and last rows of tiles
Units
- Inputs:
Rin m. - Output: the grid, cell size in m on the ground, and its transform onto the Mercator map in m.
Notes
- The tiles may come in any order. A tile that couldn't be fetched can be stood in for by a grid of
NaN. - Missing cells,
noDataorNaNin any tile, areNaNin the stitched grid. - The cell size is right at the block's middle only, so the error toward its north and south edges grows with the block's height: keep blocks a few tiles high, or project the grid, for slopes far from the middle.
- Tiles on both sides of the antimeridian don't form a rectangle, as columns 0 and
aren't next to each other here: stitch each side apart.
Parameters
| Parameter | Type | Description |
|---|---|---|
tiles | readonly TileGridInterface[] | The tiles and their grids. |
R | number | Radius of the sphere the tiles were cut for, in m (finite, > 0). |
Returns
The stitched grid and its transform.
Throws
- If
R, a size or a cell size is not finite, or a value is infinite. - If there are no tiles, a tile doesn't exist or is given twice, the zooms or grid sizes differ, the tiles don't fill a rectangle, a grid's parts don't fit together, or
Ris<= 0.
Example
ts
// The 2 × 2 tiles around a point, decoded and stitched
const { x, y, z } = tileAt(phi, lambda, 12);
const tiles = [
{ x, y, z },
{ x: x + 1, y, z },
{ x, y: y + 1, z },
{ x: x + 1, y: y + 1, z }
];
const { grid, transform } = stitchTiles(
tiles.map((tile, i) => ({
tile,
grid: decodeElevationTile(images[i], tile, 6378137)
})),
6378137
);