cog-tiler-wasm 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cog-tiler.js CHANGED
@@ -165,6 +165,43 @@ async function readTiffTag(img, name) {
165
165
  return undefined;
166
166
  }
167
167
 
168
+ // Root keyword of a projected WKT (OGC `PROJCS`/`PROJCRS`, including the ESRI PE
169
+ // string flavour ArcGIS writes). Matching the keyword lets us slice off any
170
+ // `ESRI PE String = ` prefix.
171
+ const PROJECTED_WKT_ROOT = /\b(?:PROJCS|PROJCRS)\s*\[/i;
172
+
173
+ /** Pull a projected WKT/ESRI-PE-string definition out of a GeoTIFF citation geo
174
+ * key, if one is present. Returns the WKT from the `PROJCS`/`PROJCRS` keyword
175
+ * onward, or `null`. */
176
+ function projectedWktFromGeoKeys(geoKeys) {
177
+ for (const citation of [geoKeys.PCSCitationGeoKey, geoKeys.GTCitationGeoKey]) {
178
+ if (typeof citation !== "string") continue;
179
+ const match = PROJECTED_WKT_ROOT.exec(citation);
180
+ if (match) return citation.slice(match.index);
181
+ }
182
+ return null;
183
+ }
184
+
185
+ /**
186
+ * Resolve the source CRS as a proj4 definition (a `+proj=...` string or a WKT).
187
+ *
188
+ * `geotiff-geokeys-to-proj4` builds the def from the numeric geo keys, but for a
189
+ * projection it cannot express (no `ProjCoordTransGeoKey`, e.g. ESRI world
190
+ * projections such as Mollweide/54009 written only as an `ESRI PE String`) it
191
+ * silently falls back to the bare geographic CRS (`+proj=longlat`, `isGCS`).
192
+ * That would place a projected raster at lon/lat where its metre coordinates
193
+ * are, so it never draws. When the keys carry a projected WKT, prefer it; proj4
194
+ * parses the ESRI/OGC WKT directly.
195
+ */
196
+ function sourceCrsDef(geoKeys) {
197
+ const result = geokeysToProj4.toProj4(geoKeys);
198
+ if (result.isGCS) {
199
+ const wkt = projectedWktFromGeoKeys(geoKeys);
200
+ if (wkt) return wkt;
201
+ }
202
+ return result.proj4;
203
+ }
204
+
168
205
  /** Build a 256-entry RGBA palette from a TIFF ColorMap (16-bit R,G,B blocks). */
169
206
  function buildPalette(colorMap) {
170
207
  if (!colorMap) return null;
@@ -282,7 +319,7 @@ export async function openCog(source) {
282
319
  }
283
320
 
284
321
  // Warp path: read the real source CRS + optional palette from the header.
285
- const srcDef = geokeysToProj4.toProj4(img.getGeoKeys()).proj4;
322
+ const srcDef = sourceCrsDef(img.getGeoKeys());
286
323
  if (!srcDef) throw new Error("could not derive source CRS from GeoTIFF geokeys");
287
324
  const toSource = proj4("EPSG:3857", srcDef); // forward: mercator -> source
288
325
  const toLonLat = proj4(srcDef, "EPSG:4326"); // forward: source -> lon/lat
@@ -304,10 +341,20 @@ export async function openCog(source) {
304
341
  toSource,
305
342
  palette,
306
343
  boundsLonLat: [Math.min(...lons), Math.min(...lats), Math.max(...lons), Math.max(...lats)],
307
- crsLabel: "warped from " + (srcDef.match(/\+proj=\w+/) || ["custom CRS"])[0],
344
+ crsLabel: "warped from " + crsLabelForDef(srcDef),
308
345
  });
309
346
  }
310
347
 
348
+ /** A short label for a proj4 def: the `+proj=...` token, or the WKT's CRS name,
349
+ * falling back to "custom CRS". */
350
+ function crsLabelForDef(srcDef) {
351
+ const projTag = srcDef.match(/\+proj=\w+/);
352
+ if (projTag) return projTag[0];
353
+ const wktName = srcDef.match(/\b(?:PROJCS|PROJCRS)\s*\[\s*"([^"]+)"/i);
354
+ if (wktName) return wktName[1];
355
+ return "custom CRS";
356
+ }
357
+
311
358
  /** A single opened COG. Renders XYZ tiles via {@link CogSource#renderTileRGBA}. */
312
359
  export class CogSource {
313
360
  constructor(fields) {
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Qiusheng Wu <giswqs@gmail.com>"
6
6
  ],
7
7
  "description": "Serverless Cloud Optimized GeoTIFF (COG) dynamic tiling in WebAssembly. TiTiler-style XYZ tiles, no backend.",
8
- "version": "0.2.3",
8
+ "version": "0.2.4",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",