|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import wktParser from "wkt-parser"; |
| 3 | +import { generateTileMatrixSet } from "../src/tile-matrix-set.js"; |
| 4 | +import { loadGeoTIFF } from "./helpers.js"; |
| 5 | + |
| 6 | +const EPSG_4326 = { |
| 7 | + $schema: "https://proj.org/schemas/v0.7/projjson.schema.json", |
| 8 | + type: "GeographicCRS", |
| 9 | + name: "WGS 84", |
| 10 | + datum_ensemble: { |
| 11 | + name: "World Geodetic System 1984 ensemble", |
| 12 | + members: [ |
| 13 | + { |
| 14 | + name: "World Geodetic System 1984 (Transit)", |
| 15 | + id: { authority: "EPSG", code: 1166 }, |
| 16 | + }, |
| 17 | + { |
| 18 | + name: "World Geodetic System 1984 (G730)", |
| 19 | + id: { authority: "EPSG", code: 1152 }, |
| 20 | + }, |
| 21 | + { |
| 22 | + name: "World Geodetic System 1984 (G873)", |
| 23 | + id: { authority: "EPSG", code: 1153 }, |
| 24 | + }, |
| 25 | + { |
| 26 | + name: "World Geodetic System 1984 (G1150)", |
| 27 | + id: { authority: "EPSG", code: 1154 }, |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "World Geodetic System 1984 (G1674)", |
| 31 | + id: { authority: "EPSG", code: 1155 }, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "World Geodetic System 1984 (G1762)", |
| 35 | + id: { authority: "EPSG", code: 1156 }, |
| 36 | + }, |
| 37 | + { |
| 38 | + name: "World Geodetic System 1984 (G2139)", |
| 39 | + id: { authority: "EPSG", code: 1309 }, |
| 40 | + }, |
| 41 | + { |
| 42 | + name: "World Geodetic System 1984 (G2296)", |
| 43 | + id: { authority: "EPSG", code: 1383 }, |
| 44 | + }, |
| 45 | + ], |
| 46 | + ellipsoid: { |
| 47 | + name: "WGS 84", |
| 48 | + semi_major_axis: 6378137, |
| 49 | + inverse_flattening: 298.257223563, |
| 50 | + }, |
| 51 | + accuracy: "2.0", |
| 52 | + id: { authority: "EPSG", code: 6326 }, |
| 53 | + }, |
| 54 | + coordinate_system: { |
| 55 | + subtype: "ellipsoidal", |
| 56 | + axis: [ |
| 57 | + { |
| 58 | + name: "Geodetic latitude", |
| 59 | + abbreviation: "Lat", |
| 60 | + direction: "north", |
| 61 | + unit: "degree", |
| 62 | + }, |
| 63 | + { |
| 64 | + name: "Geodetic longitude", |
| 65 | + abbreviation: "Lon", |
| 66 | + direction: "east", |
| 67 | + unit: "degree", |
| 68 | + }, |
| 69 | + ], |
| 70 | + }, |
| 71 | + scope: "Horizontal component of 3D system.", |
| 72 | + area: "World.", |
| 73 | + bbox: { |
| 74 | + south_latitude: -90, |
| 75 | + west_longitude: -180, |
| 76 | + north_latitude: 90, |
| 77 | + east_longitude: 180, |
| 78 | + }, |
| 79 | + id: { authority: "EPSG", code: 4326 }, |
| 80 | +}; |
| 81 | + |
| 82 | +describe("test TMS", () => { |
| 83 | + it("can generate TMS from EPSG CRS", async () => { |
| 84 | + const geotiff = await loadGeoTIFF( |
| 85 | + "uint8_rgb_deflate_block64_cog", |
| 86 | + "rasterio", |
| 87 | + ); |
| 88 | + const crs = geotiff.crs; |
| 89 | + expect(crs).toEqual(4326); |
| 90 | + |
| 91 | + const parsedCrs = wktParser(EPSG_4326); |
| 92 | + |
| 93 | + const tms = generateTileMatrixSet(geotiff, parsedCrs, { id: "test-tms" }); |
| 94 | + |
| 95 | + expect(tms.crs).toEqual({ |
| 96 | + uri: "http://www.opengis.net/def/crs/EPSG/0/4326", |
| 97 | + }); |
| 98 | + expect(tms.boundingBox).toEqual({ |
| 99 | + lowerLeft: [0.0, -1.28], |
| 100 | + upperRight: [1.28, 0.0], |
| 101 | + crs: { uri: "http://www.opengis.net/def/crs/EPSG/0/4326" }, |
| 102 | + }); |
| 103 | + expect(tms.tileMatrices).toEqual([ |
| 104 | + { |
| 105 | + id: "0", |
| 106 | + scaleDenominator: 7951392.199519542, |
| 107 | + cellSize: 0.02, |
| 108 | + cornerOfOrigin: "topLeft", |
| 109 | + pointOfOrigin: [0.0, 0.0], |
| 110 | + tileWidth: 64, |
| 111 | + tileHeight: 64, |
| 112 | + matrixWidth: 1, |
| 113 | + matrixHeight: 1, |
| 114 | + }, |
| 115 | + { |
| 116 | + id: "1", |
| 117 | + scaleDenominator: 3975696.099759771, |
| 118 | + cellSize: 0.01, |
| 119 | + cornerOfOrigin: "topLeft", |
| 120 | + pointOfOrigin: [0.0, 0.0], |
| 121 | + tileWidth: 64, |
| 122 | + tileHeight: 64, |
| 123 | + matrixWidth: 2, |
| 124 | + matrixHeight: 2, |
| 125 | + }, |
| 126 | + ]); |
| 127 | + }); |
| 128 | +}); |
0 commit comments