@loaders.gl/potree 4.4.0-alpha.9 → 4.4.0

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/dist/dist.dev.js CHANGED
@@ -268,7 +268,7 @@ var __exports__ = (() => {
268
268
  }
269
269
  this.data = data;
270
270
  this.url = typeof data === "string" ? resolvePath(data) : "";
271
- this.loadOptions = { ...this.options.core?.loadOptions };
271
+ this.loadOptions = normalizeDirectLoaderOptions(this.options.core?.loadOptions);
272
272
  this.fetch = getFetchFunction(this.loadOptions);
273
273
  }
274
274
  setProps(options) {
@@ -311,6 +311,23 @@ var __exports__ = (() => {
311
311
  }
312
312
  return (url) => fetch(url);
313
313
  }
314
+ function normalizeDirectLoaderOptions(options) {
315
+ const loadOptions = { ...options };
316
+ if (options?.core) {
317
+ loadOptions.core = { ...options.core };
318
+ }
319
+ const topLevelBaseUri = typeof loadOptions.baseUri === "string" ? loadOptions.baseUri : void 0;
320
+ const topLevelBaseUrl = typeof loadOptions.baseUrl === "string" ? loadOptions.baseUrl : void 0;
321
+ if (topLevelBaseUri !== void 0 || topLevelBaseUrl !== void 0) {
322
+ loadOptions.core ||= {};
323
+ if (loadOptions.core.baseUrl === void 0) {
324
+ loadOptions.core.baseUrl = topLevelBaseUrl ?? topLevelBaseUri;
325
+ }
326
+ delete loadOptions.baseUri;
327
+ delete loadOptions.baseUrl;
328
+ }
329
+ return loadOptions;
330
+ }
314
331
 
315
332
  // ../las/src/las-format.ts
316
333
  var LASFormat = {
@@ -19145,6 +19162,8 @@ var __exports__ = (() => {
19145
19162
  start2 += 48;
19146
19163
  o.maxs = [bounds[0], bounds[2], bounds[4]];
19147
19164
  o.mins = [bounds[1], bounds[3], bounds[5]];
19165
+ const colorPointFormats = /* @__PURE__ */ new Set([2, 3]);
19166
+ o.hasColor = colorPointFormats.has(o.pointsFormatId & 63);
19148
19167
  return o;
19149
19168
  }
19150
19169
  var LASLoader = class {
@@ -19282,11 +19301,10 @@ var __exports__ = (() => {
19282
19301
  }
19283
19302
  /**
19284
19303
  * @param count
19285
- * @param offset
19286
19304
  * @param skip
19287
19305
  * @returns Data
19288
19306
  */
19289
- readData(count, offset, skip) {
19307
+ readData(count, skip) {
19290
19308
  if (!this.instance) {
19291
19309
  throw new Error("You need to open the file before trying to read stuff");
19292
19310
  }
@@ -19430,12 +19448,11 @@ var __exports__ = (() => {
19430
19448
  }
19431
19449
  /**
19432
19450
  * @param count
19433
- * @param start
19434
19451
  * @param skip
19435
19452
  * @returns Data
19436
19453
  */
19437
- readData(count, start2, skip) {
19438
- return this.loader.readData(count, start2, skip);
19454
+ readData(count, skip) {
19455
+ return this.loader.readData(count, skip);
19439
19456
  }
19440
19457
  /**
19441
19458
  * Closes the file
@@ -19808,6 +19825,328 @@ var __exports__ = (() => {
19808
19825
  return self2;
19809
19826
  }
19810
19827
 
19828
+ // ../../node_modules/wkt-parser/PROJJSONBuilderBase.js
19829
+ var PROJJSONBuilderBase = class {
19830
+ static getId(node) {
19831
+ const idNode = node.find((child) => Array.isArray(child) && child[0] === "ID");
19832
+ if (idNode && idNode.length >= 3) {
19833
+ return {
19834
+ authority: idNode[1],
19835
+ code: parseInt(idNode[2], 10)
19836
+ };
19837
+ }
19838
+ return null;
19839
+ }
19840
+ static convertUnit(node, type = "unit") {
19841
+ if (!node || node.length < 3) {
19842
+ return { type, name: "unknown", conversion_factor: null };
19843
+ }
19844
+ const name = node[1];
19845
+ const conversionFactor = parseFloat(node[2]) || null;
19846
+ const idNode = node.find((child) => Array.isArray(child) && child[0] === "ID");
19847
+ const id = idNode ? {
19848
+ authority: idNode[1],
19849
+ code: parseInt(idNode[2], 10)
19850
+ } : null;
19851
+ return {
19852
+ type,
19853
+ name,
19854
+ conversion_factor: conversionFactor,
19855
+ id
19856
+ };
19857
+ }
19858
+ static convertAxis(node) {
19859
+ const name = node[1] || "Unknown";
19860
+ let direction;
19861
+ const abbreviationMatch = name.match(/^\((.)\)$/);
19862
+ if (abbreviationMatch) {
19863
+ const abbreviation = abbreviationMatch[1].toUpperCase();
19864
+ if (abbreviation === "E")
19865
+ direction = "east";
19866
+ else if (abbreviation === "N")
19867
+ direction = "north";
19868
+ else if (abbreviation === "U")
19869
+ direction = "up";
19870
+ else
19871
+ throw new Error(`Unknown axis abbreviation: ${abbreviation}`);
19872
+ } else {
19873
+ direction = node[2] ? node[2].toLowerCase() : "unknown";
19874
+ }
19875
+ const orderNode = node.find((child) => Array.isArray(child) && child[0] === "ORDER");
19876
+ const order = orderNode ? parseInt(orderNode[1], 10) : null;
19877
+ const unitNode = node.find(
19878
+ (child) => Array.isArray(child) && (child[0] === "LENGTHUNIT" || child[0] === "ANGLEUNIT" || child[0] === "SCALEUNIT")
19879
+ );
19880
+ const unit = this.convertUnit(unitNode);
19881
+ return {
19882
+ name,
19883
+ direction,
19884
+ // Use the valid PROJJSON direction value
19885
+ unit,
19886
+ order
19887
+ };
19888
+ }
19889
+ static extractAxes(node) {
19890
+ return node.filter((child) => Array.isArray(child) && child[0] === "AXIS").map((axis) => this.convertAxis(axis)).sort((a, b) => (a.order || 0) - (b.order || 0));
19891
+ }
19892
+ static convert(node, result = {}) {
19893
+ switch (node[0]) {
19894
+ case "PROJCRS":
19895
+ result.type = "ProjectedCRS";
19896
+ result.name = node[1];
19897
+ result.base_crs = node.find((child) => Array.isArray(child) && child[0] === "BASEGEOGCRS") ? this.convert(node.find((child) => Array.isArray(child) && child[0] === "BASEGEOGCRS")) : null;
19898
+ result.conversion = node.find((child) => Array.isArray(child) && child[0] === "CONVERSION") ? this.convert(node.find((child) => Array.isArray(child) && child[0] === "CONVERSION")) : null;
19899
+ const csNode = node.find((child) => Array.isArray(child) && child[0] === "CS");
19900
+ if (csNode) {
19901
+ result.coordinate_system = {
19902
+ type: csNode[1],
19903
+ axis: this.extractAxes(node)
19904
+ };
19905
+ }
19906
+ const lengthUnitNode = node.find((child) => Array.isArray(child) && child[0] === "LENGTHUNIT");
19907
+ if (lengthUnitNode) {
19908
+ const unit2 = this.convertUnit(lengthUnitNode);
19909
+ result.coordinate_system.unit = unit2;
19910
+ }
19911
+ result.id = this.getId(node);
19912
+ break;
19913
+ case "BASEGEOGCRS":
19914
+ case "GEOGCRS":
19915
+ result.type = "GeographicCRS";
19916
+ result.name = node[1];
19917
+ const datumOrEnsembleNode = node.find(
19918
+ (child) => Array.isArray(child) && (child[0] === "DATUM" || child[0] === "ENSEMBLE")
19919
+ );
19920
+ if (datumOrEnsembleNode) {
19921
+ const datumOrEnsemble = this.convert(datumOrEnsembleNode);
19922
+ if (datumOrEnsembleNode[0] === "ENSEMBLE") {
19923
+ result.datum_ensemble = datumOrEnsemble;
19924
+ } else {
19925
+ result.datum = datumOrEnsemble;
19926
+ }
19927
+ const primem = node.find((child) => Array.isArray(child) && child[0] === "PRIMEM");
19928
+ if (primem && primem[1] !== "Greenwich") {
19929
+ datumOrEnsemble.prime_meridian = {
19930
+ name: primem[1],
19931
+ longitude: parseFloat(primem[2])
19932
+ };
19933
+ }
19934
+ }
19935
+ result.coordinate_system = {
19936
+ type: "ellipsoidal",
19937
+ axis: this.extractAxes(node)
19938
+ };
19939
+ result.id = this.getId(node);
19940
+ break;
19941
+ case "DATUM":
19942
+ result.type = "GeodeticReferenceFrame";
19943
+ result.name = node[1];
19944
+ result.ellipsoid = node.find((child) => Array.isArray(child) && child[0] === "ELLIPSOID") ? this.convert(node.find((child) => Array.isArray(child) && child[0] === "ELLIPSOID")) : null;
19945
+ break;
19946
+ case "ENSEMBLE":
19947
+ result.type = "DatumEnsemble";
19948
+ result.name = node[1];
19949
+ result.members = node.filter((child) => Array.isArray(child) && child[0] === "MEMBER").map((member) => ({
19950
+ type: "DatumEnsembleMember",
19951
+ name: member[1],
19952
+ id: this.getId(member)
19953
+ // Extract ID as { authority, code }
19954
+ }));
19955
+ const accuracyNode = node.find((child) => Array.isArray(child) && child[0] === "ENSEMBLEACCURACY");
19956
+ if (accuracyNode) {
19957
+ result.accuracy = parseFloat(accuracyNode[1]);
19958
+ }
19959
+ const ellipsoidNode = node.find((child) => Array.isArray(child) && child[0] === "ELLIPSOID");
19960
+ if (ellipsoidNode) {
19961
+ result.ellipsoid = this.convert(ellipsoidNode);
19962
+ }
19963
+ result.id = this.getId(node);
19964
+ break;
19965
+ case "ELLIPSOID":
19966
+ result.type = "Ellipsoid";
19967
+ result.name = node[1];
19968
+ result.semi_major_axis = parseFloat(node[2]);
19969
+ result.inverse_flattening = parseFloat(node[3]);
19970
+ const units = node.find((child) => Array.isArray(child) && child[0] === "LENGTHUNIT") ? this.convert(node.find((child) => Array.isArray(child) && child[0] === "LENGTHUNIT"), result) : null;
19971
+ break;
19972
+ case "CONVERSION":
19973
+ result.type = "Conversion";
19974
+ result.name = node[1];
19975
+ result.method = node.find((child) => Array.isArray(child) && child[0] === "METHOD") ? this.convert(node.find((child) => Array.isArray(child) && child[0] === "METHOD")) : null;
19976
+ result.parameters = node.filter((child) => Array.isArray(child) && child[0] === "PARAMETER").map((param) => this.convert(param));
19977
+ break;
19978
+ case "METHOD":
19979
+ result.type = "Method";
19980
+ result.name = node[1];
19981
+ result.id = this.getId(node);
19982
+ break;
19983
+ case "PARAMETER":
19984
+ result.type = "Parameter";
19985
+ result.name = node[1];
19986
+ result.value = parseFloat(node[2]);
19987
+ result.unit = this.convertUnit(
19988
+ node.find(
19989
+ (child) => Array.isArray(child) && (child[0] === "LENGTHUNIT" || child[0] === "ANGLEUNIT" || child[0] === "SCALEUNIT")
19990
+ )
19991
+ );
19992
+ result.id = this.getId(node);
19993
+ break;
19994
+ case "BOUNDCRS":
19995
+ result.type = "BoundCRS";
19996
+ const sourceCrsNode = node.find((child) => Array.isArray(child) && child[0] === "SOURCECRS");
19997
+ if (sourceCrsNode) {
19998
+ const sourceCrsContent = sourceCrsNode.find((child) => Array.isArray(child));
19999
+ result.source_crs = sourceCrsContent ? this.convert(sourceCrsContent) : null;
20000
+ }
20001
+ const targetCrsNode = node.find((child) => Array.isArray(child) && child[0] === "TARGETCRS");
20002
+ if (targetCrsNode) {
20003
+ const targetCrsContent = targetCrsNode.find((child) => Array.isArray(child));
20004
+ result.target_crs = targetCrsContent ? this.convert(targetCrsContent) : null;
20005
+ }
20006
+ const transformationNode = node.find((child) => Array.isArray(child) && child[0] === "ABRIDGEDTRANSFORMATION");
20007
+ if (transformationNode) {
20008
+ result.transformation = this.convert(transformationNode);
20009
+ } else {
20010
+ result.transformation = null;
20011
+ }
20012
+ break;
20013
+ case "ABRIDGEDTRANSFORMATION":
20014
+ result.type = "Transformation";
20015
+ result.name = node[1];
20016
+ result.method = node.find((child) => Array.isArray(child) && child[0] === "METHOD") ? this.convert(node.find((child) => Array.isArray(child) && child[0] === "METHOD")) : null;
20017
+ result.parameters = node.filter((child) => Array.isArray(child) && (child[0] === "PARAMETER" || child[0] === "PARAMETERFILE")).map((param) => {
20018
+ if (param[0] === "PARAMETER") {
20019
+ return this.convert(param);
20020
+ } else if (param[0] === "PARAMETERFILE") {
20021
+ return {
20022
+ name: param[1],
20023
+ value: param[2],
20024
+ id: {
20025
+ "authority": "EPSG",
20026
+ "code": 8656
20027
+ }
20028
+ };
20029
+ }
20030
+ });
20031
+ if (result.parameters.length === 7) {
20032
+ const scaleDifference = result.parameters[6];
20033
+ if (scaleDifference.name === "Scale difference") {
20034
+ scaleDifference.value = Math.round((scaleDifference.value - 1) * 1e12) / 1e6;
20035
+ }
20036
+ }
20037
+ result.id = this.getId(node);
20038
+ break;
20039
+ case "AXIS":
20040
+ if (!result.coordinate_system) {
20041
+ result.coordinate_system = { type: "unspecified", axis: [] };
20042
+ }
20043
+ result.coordinate_system.axis.push(this.convertAxis(node));
20044
+ break;
20045
+ case "LENGTHUNIT":
20046
+ const unit = this.convertUnit(node, "LinearUnit");
20047
+ if (result.coordinate_system && result.coordinate_system.axis) {
20048
+ result.coordinate_system.axis.forEach((axis) => {
20049
+ if (!axis.unit) {
20050
+ axis.unit = unit;
20051
+ }
20052
+ });
20053
+ }
20054
+ if (unit.conversion_factor && unit.conversion_factor !== 1) {
20055
+ if (result.semi_major_axis) {
20056
+ result.semi_major_axis = {
20057
+ value: result.semi_major_axis,
20058
+ unit
20059
+ };
20060
+ }
20061
+ }
20062
+ break;
20063
+ default:
20064
+ result.keyword = node[0];
20065
+ break;
20066
+ }
20067
+ return result;
20068
+ }
20069
+ };
20070
+ var PROJJSONBuilderBase_default = PROJJSONBuilderBase;
20071
+
20072
+ // ../../node_modules/wkt-parser/PROJJSONBuilder2015.js
20073
+ var PROJJSONBuilder2015 = class extends PROJJSONBuilderBase_default {
20074
+ static convert(node, result = {}) {
20075
+ super.convert(node, result);
20076
+ if (result.coordinate_system && result.coordinate_system.subtype === "Cartesian") {
20077
+ delete result.coordinate_system;
20078
+ }
20079
+ if (result.usage) {
20080
+ delete result.usage;
20081
+ }
20082
+ return result;
20083
+ }
20084
+ };
20085
+ var PROJJSONBuilder2015_default = PROJJSONBuilder2015;
20086
+
20087
+ // ../../node_modules/wkt-parser/PROJJSONBuilder2019.js
20088
+ var PROJJSONBuilder2019 = class extends PROJJSONBuilderBase_default {
20089
+ static convert(node, result = {}) {
20090
+ super.convert(node, result);
20091
+ const csNode = node.find((child) => Array.isArray(child) && child[0] === "CS");
20092
+ if (csNode) {
20093
+ result.coordinate_system = {
20094
+ subtype: csNode[1],
20095
+ axis: this.extractAxes(node)
20096
+ };
20097
+ }
20098
+ const usageNode = node.find((child) => Array.isArray(child) && child[0] === "USAGE");
20099
+ if (usageNode) {
20100
+ const scope = usageNode.find((child) => Array.isArray(child) && child[0] === "SCOPE");
20101
+ const area = usageNode.find((child) => Array.isArray(child) && child[0] === "AREA");
20102
+ const bbox = usageNode.find((child) => Array.isArray(child) && child[0] === "BBOX");
20103
+ result.usage = {};
20104
+ if (scope) {
20105
+ result.usage.scope = scope[1];
20106
+ }
20107
+ if (area) {
20108
+ result.usage.area = area[1];
20109
+ }
20110
+ if (bbox) {
20111
+ result.usage.bbox = bbox.slice(1);
20112
+ }
20113
+ }
20114
+ return result;
20115
+ }
20116
+ };
20117
+ var PROJJSONBuilder2019_default = PROJJSONBuilder2019;
20118
+
20119
+ // ../../node_modules/wkt-parser/buildPROJJSON.js
20120
+ function detectWKT2Version(root) {
20121
+ if (root.find((child) => Array.isArray(child) && child[0] === "USAGE")) {
20122
+ return "2019";
20123
+ }
20124
+ if (root.find((child) => Array.isArray(child) && child[0] === "CS")) {
20125
+ return "2015";
20126
+ }
20127
+ if (root[0] === "BOUNDCRS" || root[0] === "PROJCRS" || root[0] === "GEOGCRS") {
20128
+ return "2015";
20129
+ }
20130
+ return "2015";
20131
+ }
20132
+ function buildPROJJSON(root) {
20133
+ const version = detectWKT2Version(root);
20134
+ const builder = version === "2019" ? PROJJSONBuilder2019_default : PROJJSONBuilder2015_default;
20135
+ return builder.convert(root);
20136
+ }
20137
+
20138
+ // ../../node_modules/wkt-parser/detectWKTVersion.js
20139
+ function detectWKTVersion(wkt) {
20140
+ const normalizedWKT = wkt.toUpperCase();
20141
+ if (normalizedWKT.includes("PROJCRS") || normalizedWKT.includes("GEOGCRS") || normalizedWKT.includes("BOUNDCRS") || normalizedWKT.includes("VERTCRS") || normalizedWKT.includes("LENGTHUNIT") || normalizedWKT.includes("ANGLEUNIT") || normalizedWKT.includes("SCALEUNIT")) {
20142
+ return "WKT2";
20143
+ }
20144
+ if (normalizedWKT.includes("PROJCS") || normalizedWKT.includes("GEOGCS") || normalizedWKT.includes("LOCAL_CS") || normalizedWKT.includes("VERT_CS") || normalizedWKT.includes("UNIT")) {
20145
+ return "WKT1";
20146
+ }
20147
+ return "WKT1";
20148
+ }
20149
+
19811
20150
  // ../../node_modules/wkt-parser/parser.js
19812
20151
  var parser_default = parseString;
19813
20152
  var NEUTRAL = 1;
@@ -20050,6 +20389,19 @@ var __exports__ = (() => {
20050
20389
  sExpr(v[3], obj[key]);
20051
20390
  }
20052
20391
  return;
20392
+ case "EDATUM":
20393
+ case "ENGINEERINGDATUM":
20394
+ case "LOCAL_DATUM":
20395
+ case "DATUM":
20396
+ case "VERT_CS":
20397
+ case "VERTCRS":
20398
+ case "VERTICALCRS":
20399
+ v[0] = ["name", v[0]];
20400
+ mapit(obj, key, v);
20401
+ return;
20402
+ case "COMPD_CS":
20403
+ case "COMPOUNDCRS":
20404
+ case "FITTED_CS":
20053
20405
  case "PROJECTEDCRS":
20054
20406
  case "PROJCRS":
20055
20407
  case "GEOGCS":
@@ -20059,20 +20411,11 @@ var __exports__ = (() => {
20059
20411
  case "GEODCRS":
20060
20412
  case "GEODETICCRS":
20061
20413
  case "GEODETICDATUM":
20062
- case "EDATUM":
20063
- case "ENGINEERINGDATUM":
20064
- case "VERT_CS":
20065
- case "VERTCRS":
20066
- case "VERTICALCRS":
20067
- case "COMPD_CS":
20068
- case "COMPOUNDCRS":
20069
- case "ENGINEERINGCRS":
20070
20414
  case "ENGCRS":
20071
- case "FITTED_CS":
20072
- case "LOCAL_DATUM":
20073
- case "DATUM":
20415
+ case "ENGINEERINGCRS":
20074
20416
  v[0] = ["name", v[0]];
20075
20417
  mapit(obj, key, v);
20418
+ obj[key].type = key;
20076
20419
  return;
20077
20420
  default:
20078
20421
  i = -1;
@@ -20085,8 +20428,276 @@ var __exports__ = (() => {
20085
20428
  }
20086
20429
  }
20087
20430
 
20088
- // ../../node_modules/wkt-parser/index.js
20431
+ // ../../node_modules/wkt-parser/util.js
20089
20432
  var D2R2 = 0.017453292519943295;
20433
+ function d2r(input) {
20434
+ return input * D2R2;
20435
+ }
20436
+ function applyProjectionDefaults(wkt) {
20437
+ const normalizedProjName = (wkt.projName || "").toLowerCase().replace(/_/g, " ");
20438
+ if (!wkt.long0 && wkt.longc && (normalizedProjName === "albers conic equal area" || normalizedProjName === "lambert azimuthal equal area")) {
20439
+ wkt.long0 = wkt.longc;
20440
+ }
20441
+ if (!wkt.lat_ts && wkt.lat1 && (normalizedProjName === "stereographic south pole" || normalizedProjName === "polar stereographic (variant b)")) {
20442
+ wkt.lat0 = d2r(wkt.lat1 > 0 ? 90 : -90);
20443
+ wkt.lat_ts = wkt.lat1;
20444
+ delete wkt.lat1;
20445
+ } else if (!wkt.lat_ts && wkt.lat0 && (normalizedProjName === "polar stereographic" || normalizedProjName === "polar stereographic (variant a)")) {
20446
+ wkt.lat_ts = wkt.lat0;
20447
+ wkt.lat0 = d2r(wkt.lat0 > 0 ? 90 : -90);
20448
+ delete wkt.lat1;
20449
+ }
20450
+ }
20451
+
20452
+ // ../../node_modules/wkt-parser/transformPROJJSON.js
20453
+ function processUnit(unit) {
20454
+ let result = { units: null, to_meter: void 0 };
20455
+ if (typeof unit === "string") {
20456
+ result.units = unit.toLowerCase();
20457
+ if (result.units === "metre") {
20458
+ result.units = "meter";
20459
+ }
20460
+ if (result.units === "meter") {
20461
+ result.to_meter = 1;
20462
+ }
20463
+ } else if (unit && unit.name) {
20464
+ result.units = unit.name.toLowerCase();
20465
+ if (result.units === "metre") {
20466
+ result.units = "meter";
20467
+ }
20468
+ result.to_meter = unit.conversion_factor;
20469
+ }
20470
+ return result;
20471
+ }
20472
+ function toValue(valueOrObject) {
20473
+ if (typeof valueOrObject === "object") {
20474
+ return valueOrObject.value * valueOrObject.unit.conversion_factor;
20475
+ }
20476
+ return valueOrObject;
20477
+ }
20478
+ function calculateEllipsoid(value, result) {
20479
+ if (value.ellipsoid.radius) {
20480
+ result.a = value.ellipsoid.radius;
20481
+ result.rf = 0;
20482
+ } else {
20483
+ result.a = toValue(value.ellipsoid.semi_major_axis);
20484
+ if (value.ellipsoid.inverse_flattening !== void 0) {
20485
+ result.rf = value.ellipsoid.inverse_flattening;
20486
+ } else if (value.ellipsoid.semi_major_axis !== void 0 && value.ellipsoid.semi_minor_axis !== void 0) {
20487
+ result.rf = result.a / (result.a - toValue(value.ellipsoid.semi_minor_axis));
20488
+ }
20489
+ }
20490
+ }
20491
+ function transformPROJJSON(projjson, result = {}) {
20492
+ if (!projjson || typeof projjson !== "object") {
20493
+ return projjson;
20494
+ }
20495
+ if (projjson.type === "BoundCRS") {
20496
+ transformPROJJSON(projjson.source_crs, result);
20497
+ if (projjson.transformation) {
20498
+ if (projjson.transformation.method && projjson.transformation.method.name === "NTv2") {
20499
+ result.nadgrids = projjson.transformation.parameters[0].value;
20500
+ } else {
20501
+ result.datum_params = projjson.transformation.parameters.map((param) => param.value);
20502
+ }
20503
+ }
20504
+ return result;
20505
+ }
20506
+ Object.keys(projjson).forEach((key) => {
20507
+ const value = projjson[key];
20508
+ if (value === null) {
20509
+ return;
20510
+ }
20511
+ switch (key) {
20512
+ case "name":
20513
+ if (result.srsCode) {
20514
+ break;
20515
+ }
20516
+ result.name = value;
20517
+ result.srsCode = value;
20518
+ break;
20519
+ case "type":
20520
+ if (value === "GeographicCRS") {
20521
+ result.projName = "longlat";
20522
+ } else if (value === "ProjectedCRS" && projjson.conversion && projjson.conversion.method) {
20523
+ result.projName = projjson.conversion.method.name;
20524
+ }
20525
+ break;
20526
+ case "datum":
20527
+ case "datum_ensemble":
20528
+ if (value.ellipsoid) {
20529
+ result.ellps = value.ellipsoid.name;
20530
+ calculateEllipsoid(value, result);
20531
+ }
20532
+ if (value.prime_meridian) {
20533
+ result.from_greenwich = value.prime_meridian.longitude * Math.PI / 180;
20534
+ }
20535
+ break;
20536
+ case "ellipsoid":
20537
+ result.ellps = value.name;
20538
+ calculateEllipsoid(value, result);
20539
+ break;
20540
+ case "prime_meridian":
20541
+ result.long0 = (value.longitude || 0) * Math.PI / 180;
20542
+ break;
20543
+ case "coordinate_system":
20544
+ if (value.axis) {
20545
+ result.axis = value.axis.map((axis) => {
20546
+ const direction = axis.direction;
20547
+ if (direction === "east")
20548
+ return "e";
20549
+ if (direction === "north")
20550
+ return "n";
20551
+ if (direction === "west")
20552
+ return "w";
20553
+ if (direction === "south")
20554
+ return "s";
20555
+ throw new Error(`Unknown axis direction: ${direction}`);
20556
+ }).join("") + "u";
20557
+ if (value.unit) {
20558
+ const { units, to_meter } = processUnit(value.unit);
20559
+ result.units = units;
20560
+ result.to_meter = to_meter;
20561
+ } else if (value.axis[0] && value.axis[0].unit) {
20562
+ const { units, to_meter } = processUnit(value.axis[0].unit);
20563
+ result.units = units;
20564
+ result.to_meter = to_meter;
20565
+ }
20566
+ }
20567
+ break;
20568
+ case "id":
20569
+ if (value.authority && value.code) {
20570
+ result.title = value.authority + ":" + value.code;
20571
+ }
20572
+ break;
20573
+ case "conversion":
20574
+ if (value.method && value.method.name) {
20575
+ result.projName = value.method.name;
20576
+ }
20577
+ if (value.parameters) {
20578
+ value.parameters.forEach((param) => {
20579
+ const paramName = param.name.toLowerCase().replace(/\s+/g, "_");
20580
+ const paramValue = param.value;
20581
+ if (param.unit && param.unit.conversion_factor) {
20582
+ result[paramName] = paramValue * param.unit.conversion_factor;
20583
+ } else if (param.unit === "degree") {
20584
+ result[paramName] = paramValue * Math.PI / 180;
20585
+ } else {
20586
+ result[paramName] = paramValue;
20587
+ }
20588
+ });
20589
+ }
20590
+ break;
20591
+ case "unit":
20592
+ if (value.name) {
20593
+ result.units = value.name.toLowerCase();
20594
+ if (result.units === "metre") {
20595
+ result.units = "meter";
20596
+ }
20597
+ }
20598
+ if (value.conversion_factor) {
20599
+ result.to_meter = value.conversion_factor;
20600
+ }
20601
+ break;
20602
+ case "base_crs":
20603
+ transformPROJJSON(value, result);
20604
+ result.datumCode = value.id ? value.id.authority + "_" + value.id.code : value.name;
20605
+ break;
20606
+ default:
20607
+ break;
20608
+ }
20609
+ });
20610
+ if (result.latitude_of_false_origin !== void 0) {
20611
+ result.lat0 = result.latitude_of_false_origin;
20612
+ }
20613
+ if (result.longitude_of_false_origin !== void 0) {
20614
+ result.long0 = result.longitude_of_false_origin;
20615
+ }
20616
+ if (result.latitude_of_standard_parallel !== void 0) {
20617
+ result.lat0 = result.latitude_of_standard_parallel;
20618
+ result.lat1 = result.latitude_of_standard_parallel;
20619
+ }
20620
+ if (result.latitude_of_1st_standard_parallel !== void 0) {
20621
+ result.lat1 = result.latitude_of_1st_standard_parallel;
20622
+ }
20623
+ if (result.latitude_of_2nd_standard_parallel !== void 0) {
20624
+ result.lat2 = result.latitude_of_2nd_standard_parallel;
20625
+ }
20626
+ if (result.latitude_of_projection_centre !== void 0) {
20627
+ result.lat0 = result.latitude_of_projection_centre;
20628
+ }
20629
+ if (result.longitude_of_projection_centre !== void 0) {
20630
+ result.longc = result.longitude_of_projection_centre;
20631
+ }
20632
+ if (result.easting_at_false_origin !== void 0) {
20633
+ result.x0 = result.easting_at_false_origin;
20634
+ }
20635
+ if (result.northing_at_false_origin !== void 0) {
20636
+ result.y0 = result.northing_at_false_origin;
20637
+ }
20638
+ if (result.latitude_of_natural_origin !== void 0) {
20639
+ result.lat0 = result.latitude_of_natural_origin;
20640
+ }
20641
+ if (result.longitude_of_natural_origin !== void 0) {
20642
+ result.long0 = result.longitude_of_natural_origin;
20643
+ }
20644
+ if (result.longitude_of_origin !== void 0) {
20645
+ result.long0 = result.longitude_of_origin;
20646
+ }
20647
+ if (result.false_easting !== void 0) {
20648
+ result.x0 = result.false_easting;
20649
+ }
20650
+ if (result.easting_at_projection_centre) {
20651
+ result.x0 = result.easting_at_projection_centre;
20652
+ }
20653
+ if (result.false_northing !== void 0) {
20654
+ result.y0 = result.false_northing;
20655
+ }
20656
+ if (result.northing_at_projection_centre) {
20657
+ result.y0 = result.northing_at_projection_centre;
20658
+ }
20659
+ if (result.standard_parallel_1 !== void 0) {
20660
+ result.lat1 = result.standard_parallel_1;
20661
+ }
20662
+ if (result.standard_parallel_2 !== void 0) {
20663
+ result.lat2 = result.standard_parallel_2;
20664
+ }
20665
+ if (result.scale_factor_at_natural_origin !== void 0) {
20666
+ result.k0 = result.scale_factor_at_natural_origin;
20667
+ }
20668
+ if (result.scale_factor_at_projection_centre !== void 0) {
20669
+ result.k0 = result.scale_factor_at_projection_centre;
20670
+ }
20671
+ if (result.scale_factor_on_pseudo_standard_parallel !== void 0) {
20672
+ result.k0 = result.scale_factor_on_pseudo_standard_parallel;
20673
+ }
20674
+ if (result.azimuth !== void 0) {
20675
+ result.alpha = result.azimuth;
20676
+ }
20677
+ if (result.azimuth_at_projection_centre !== void 0) {
20678
+ result.alpha = result.azimuth_at_projection_centre;
20679
+ }
20680
+ if (result.angle_from_rectified_to_skew_grid) {
20681
+ result.rectified_grid_angle = result.angle_from_rectified_to_skew_grid;
20682
+ }
20683
+ applyProjectionDefaults(result);
20684
+ return result;
20685
+ }
20686
+
20687
+ // ../../node_modules/wkt-parser/index.js
20688
+ var knownTypes = [
20689
+ "PROJECTEDCRS",
20690
+ "PROJCRS",
20691
+ "GEOGCS",
20692
+ "GEOCCS",
20693
+ "PROJCS",
20694
+ "LOCAL_CS",
20695
+ "GEODCRS",
20696
+ "GEODETICCRS",
20697
+ "GEODETICDATUM",
20698
+ "ENGCRS",
20699
+ "ENGINEERINGCRS"
20700
+ ];
20090
20701
  function rename(obj, params) {
20091
20702
  var outName = params[0];
20092
20703
  var inName = params[1];
@@ -20097,10 +20708,25 @@ var __exports__ = (() => {
20097
20708
  }
20098
20709
  }
20099
20710
  }
20100
- function d2r(input) {
20101
- return input * D2R2;
20102
- }
20103
20711
  function cleanWKT(wkt) {
20712
+ var keys = Object.keys(wkt);
20713
+ for (var i = 0, ii = keys.length; i < ii; ++i) {
20714
+ var key = keys[i];
20715
+ if (knownTypes.indexOf(key) !== -1) {
20716
+ setPropertiesFromWkt(wkt[key]);
20717
+ }
20718
+ if (typeof wkt[key] === "object") {
20719
+ cleanWKT(wkt[key]);
20720
+ }
20721
+ }
20722
+ }
20723
+ function setPropertiesFromWkt(wkt) {
20724
+ if (wkt.AUTHORITY) {
20725
+ var authority = Object.keys(wkt.AUTHORITY)[0];
20726
+ if (authority && authority in wkt.AUTHORITY) {
20727
+ wkt.title = authority + ":" + wkt.AUTHORITY[authority];
20728
+ }
20729
+ }
20104
20730
  if (wkt.type === "GEOGCS") {
20105
20731
  wkt.projName = "longlat";
20106
20732
  } else if (wkt.type === "LOCAL_CS") {
@@ -20162,7 +20788,7 @@ var __exports__ = (() => {
20162
20788
  if (wkt.datumCode.slice(0, 2) === "d_") {
20163
20789
  wkt.datumCode = wkt.datumCode.slice(2);
20164
20790
  }
20165
- if (wkt.datumCode === "new_zealand_geodetic_datum_1949" || wkt.datumCode === "new_zealand_1949") {
20791
+ if (wkt.datumCode === "new_zealand_1949") {
20166
20792
  wkt.datumCode = "nzgd49";
20167
20793
  }
20168
20794
  if (wkt.datumCode === "wgs_1984" || wkt.datumCode === "world_geodetic_system_1984") {
@@ -20171,13 +20797,7 @@ var __exports__ = (() => {
20171
20797
  }
20172
20798
  wkt.datumCode = "wgs84";
20173
20799
  }
20174
- if (wkt.datumCode.slice(-6) === "_ferro") {
20175
- wkt.datumCode = wkt.datumCode.slice(0, -6);
20176
- }
20177
- if (wkt.datumCode.slice(-8) === "_jakarta") {
20178
- wkt.datumCode = wkt.datumCode.slice(0, -8);
20179
- }
20180
- if (~wkt.datumCode.indexOf("belge")) {
20800
+ if (wkt.datumCode === "belge_1972") {
20181
20801
  wkt.datumCode = "rnb72";
20182
20802
  }
20183
20803
  if (geogcs.DATUM && geogcs.DATUM.SPHEROID) {
@@ -20210,6 +20830,9 @@ var __exports__ = (() => {
20210
20830
  if (wkt.b && !isFinite(wkt.b)) {
20211
20831
  wkt.b = wkt.a;
20212
20832
  }
20833
+ if (wkt.rectified_grid_angle) {
20834
+ wkt.rectified_grid_angle = d2r(wkt.rectified_grid_angle);
20835
+ }
20213
20836
  function toMeter(input) {
20214
20837
  var ratio = wkt.to_meter || 1;
20215
20838
  return input * ratio;
@@ -20255,27 +20878,23 @@ var __exports__ = (() => {
20255
20878
  ["srsCode", "name"]
20256
20879
  ];
20257
20880
  list.forEach(renamer);
20258
- if (!wkt.long0 && wkt.longc && (wkt.projName === "Albers_Conic_Equal_Area" || wkt.projName === "Lambert_Azimuthal_Equal_Area")) {
20259
- wkt.long0 = wkt.longc;
20260
- }
20261
- if (!wkt.lat_ts && wkt.lat1 && (wkt.projName === "Stereographic_South_Pole" || wkt.projName === "Polar Stereographic (variant B)")) {
20262
- wkt.lat0 = d2r(wkt.lat1 > 0 ? 90 : -90);
20263
- wkt.lat_ts = wkt.lat1;
20264
- } else if (!wkt.lat_ts && wkt.lat0 && wkt.projName === "Polar_Stereographic") {
20265
- wkt.lat_ts = wkt.lat0;
20266
- wkt.lat0 = d2r(wkt.lat0 > 0 ? 90 : -90);
20267
- }
20881
+ applyProjectionDefaults(wkt);
20268
20882
  }
20269
20883
  function wkt_parser_default(wkt) {
20884
+ if (typeof wkt === "object") {
20885
+ return transformPROJJSON(wkt);
20886
+ }
20887
+ const version = detectWKTVersion(wkt);
20270
20888
  var lisp = parser_default(wkt);
20271
- var type = lisp.shift();
20272
- var name = lisp.shift();
20273
- lisp.unshift(["name", name]);
20274
- lisp.unshift(["type", type]);
20889
+ if (version === "WKT2") {
20890
+ const projjson = buildPROJJSON(lisp);
20891
+ return transformPROJJSON(projjson);
20892
+ }
20893
+ var type = lisp[0];
20275
20894
  var obj = {};
20276
20895
  sExpr(lisp, obj);
20277
20896
  cleanWKT(obj);
20278
- return obj;
20897
+ return obj[type];
20279
20898
  }
20280
20899
 
20281
20900
  // ../../node_modules/proj4/lib/defs.js