diff --git a/packages/geo/src/index.ts b/packages/geo/src/index.ts index 4b0f3b350..f376da9f1 100644 --- a/packages/geo/src/index.ts +++ b/packages/geo/src/index.ts @@ -16,4 +16,5 @@ export { GoogleTms } from './tms/google.js'; export { TileMatrixSets } from './tms/index.js'; export { Nztm2000QuadTms, Nztm2000Tms } from './tms/nztm2000.js'; export { WmtsProvider } from './wmts/wmts.js'; +export { getXyOrder } from './xy.order.js'; export { TileMatrixSetType, TileMatrixType } from '@linzjs/tile-matrix-set'; diff --git a/packages/geo/src/tile.matrix.set.ts b/packages/geo/src/tile.matrix.set.ts index 15bd0fbeb..2edbb3750 100644 --- a/packages/geo/src/tile.matrix.set.ts +++ b/packages/geo/src/tile.matrix.set.ts @@ -2,7 +2,7 @@ import { TileMatrixSetType, TileMatrixType } from '@linzjs/tile-matrix-set'; import { Bounds, Point } from './bounds.js'; import { Epsg } from './epsg.js'; -import { getXyOrder, XyOrder } from './xy.order.js'; +import { getXyOrder } from './xy.order.js'; export type Tile = Point & { z: number }; @@ -58,7 +58,7 @@ export class TileMatrixSet { this.projection = projection; /** Some projections @see EPSG:2193 are defined with XY Order of */ - if (getXyOrder(this.projection) === XyOrder.Yx) { + if (getXyOrder(this.projection) === 'yx') { this.indexX = 1; this.indexY = 0; } diff --git a/packages/geo/src/xy.order.ts b/packages/geo/src/xy.order.ts index 6f46d08a6..aed38e3a4 100644 --- a/packages/geo/src/xy.order.ts +++ b/packages/geo/src/xy.order.ts @@ -1,30 +1,26 @@ -import { Epsg } from './epsg.js'; +import { Epsg, EpsgCode } from './epsg.js'; /** * Order of X & Y coordinates when defined as a array * * `[x,y]` vs `[y,x]` */ -export enum XyOrder { - /** [x, y] */ - Xy, - /** [y, x] */ - Yx, -} +export type XyOrder = 'xy' | 'yx'; /** * Get the X & Y coordinate order for a given EPSG * @param epsg EPSG to lookup */ -export function getXyOrder(epsg: Epsg): XyOrder { +export function getXyOrder(epsg: Epsg | EpsgCode): XyOrder { + const code = typeof epsg === 'number' ? epsg : epsg.code; /** - * [EPSG:2193](https://www.opengis.net/def/crs/EPSG/0/2193) (NZTM) is defined in [y, x] + * - [EPSG:2193](https://www.opengis.net/def/crs/EPSG/0/2193) (NZTM) is defined in [y, x] + * - [EPSG:3793](https://www.opengis.net/def/crs/EPSG/0/3793) (CITM) is defined in [y, x] * specified by the coordinate system [cs:4500](https://www.opengis.net/def/cs/EPSG/0/4500) */ - if (epsg === Epsg.Nztm2000) { - return XyOrder.Yx; - } + if (code === EpsgCode.Nztm2000 || code === EpsgCode.Citm2000) return 'yx'; - // TODO there are other projections that are YX - return XyOrder.Xy; + // TODO there are other projections that are YX, + // TileMatrixSet v2 specification includes Xy ordering, https://docs.ogc.org/is/17-083r4/21-066r1.html#_adding_optional_orderedaxes_to_highlight_crs_axis_ordering + return 'xy'; } diff --git a/scripts/debug.tile.matrix.ts b/scripts/debug.tile.matrix.ts index 4dd85c97e..80d43db14 100644 --- a/scripts/debug.tile.matrix.ts +++ b/scripts/debug.tile.matrix.ts @@ -1,12 +1,12 @@ -import { Bounds, Epsg, Nztm2000QuadTms, Projection, ProjectionLoader } from '@basemaps/geo'; +import { Bounds, Epsg, Nztm2000QuadTms, Projection, ProjectionLoader, getXyOrder } from '@basemaps/geo'; import { CliInfo } from '@basemaps/shared/build/cli/info'; import { writeFileSync } from 'fs'; /** * Attempt to create a debug tile matrix given a projection code. * - * General flow of the creaion - * - Lookup the projection information from spatialreference + * General flow of the creation + * - Lookup the projection information from spatial reference * - Attempt to find the bounds of the projection * - Using the bounds attempt to find a tile matrix zoom level that would cover the entire bounds * - Create a basic debugging tile matrix from the information @@ -77,14 +77,15 @@ async function main() { const centerProjected = proj.fromWgs84([centerLon, centerLat]) - const tileMatrixBounds = new Bounds(centerProjected[0] - halfTileZeroWidth, centerProjected[1] - halfTileZeroWidth, tileZeroWidth, tileZeroWidth); - const outputBounds = proj.boundsToGeoJsonFeature(tileMatrixBounds) - const tileMatrix = structuredClone(Nztm2000QuadTms.def) + const xyOrder = getXyOrder(TargetProjection) + + const xy = xyOrder === 'xy' ? { x: 0, y: 1 } : { x: 1, y: 0 } + tileMatrix.title = 'Debug tile matrix for EPSG:' + TargetProjection; - tileMatrix.boundingBox.lowerCorner = [centerProjected[0] - halfTileZeroWidth, centerProjected[1] - halfTileZeroWidth] - tileMatrix.boundingBox.upperCorner = [centerProjected[0] + halfTileZeroWidth, centerProjected[1] + halfTileZeroWidth] + tileMatrix.boundingBox.lowerCorner = [centerProjected[xy.x] - halfTileZeroWidth, centerProjected[xy.y] - halfTileZeroWidth] + tileMatrix.boundingBox.upperCorner = [centerProjected[xy.x] + halfTileZeroWidth, centerProjected[xy.y] + halfTileZeroWidth] tileMatrix.tileMatrix = tileMatrix.tileMatrix.slice(zOffset).map((x, i) => { x.identifier = String(i);