@loaders.gl/gis 3.1.3 → 4.0.0-alpha.5

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.
Files changed (54) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/bundle.js.map +1 -0
  3. package/dist/index.js +6 -18
  4. package/dist/index.js.map +1 -0
  5. package/dist/lib/binary-to-geojson.js +242 -201
  6. package/dist/lib/binary-to-geojson.js.map +1 -0
  7. package/dist/lib/extract-geometry-info.js +102 -93
  8. package/dist/lib/extract-geometry-info.js.map +1 -0
  9. package/dist/lib/flat-geojson-to-binary-types.js +2 -2
  10. package/dist/{es5/lib → lib}/flat-geojson-to-binary-types.js.map +0 -0
  11. package/dist/lib/flat-geojson-to-binary.js +309 -345
  12. package/dist/lib/flat-geojson-to-binary.js.map +1 -0
  13. package/dist/lib/geojson-to-binary.js +20 -23
  14. package/dist/lib/geojson-to-binary.js.map +1 -0
  15. package/dist/lib/geojson-to-flat-geojson.js +104 -116
  16. package/dist/lib/geojson-to-flat-geojson.js.map +1 -0
  17. package/dist/lib/transform.js +42 -51
  18. package/dist/lib/transform.js.map +1 -0
  19. package/package.json +6 -6
  20. package/dist/es5/bundle.js +0 -7
  21. package/dist/es5/bundle.js.map +0 -1
  22. package/dist/es5/index.js +0 -64
  23. package/dist/es5/index.js.map +0 -1
  24. package/dist/es5/lib/binary-to-geojson.js +0 -330
  25. package/dist/es5/lib/binary-to-geojson.js.map +0 -1
  26. package/dist/es5/lib/extract-geometry-info.js +0 -204
  27. package/dist/es5/lib/extract-geometry-info.js.map +0 -1
  28. package/dist/es5/lib/flat-geojson-to-binary-types.js +0 -2
  29. package/dist/es5/lib/flat-geojson-to-binary.js +0 -397
  30. package/dist/es5/lib/flat-geojson-to-binary.js.map +0 -1
  31. package/dist/es5/lib/geojson-to-binary.js +0 -30
  32. package/dist/es5/lib/geojson-to-binary.js.map +0 -1
  33. package/dist/es5/lib/geojson-to-flat-geojson.js +0 -169
  34. package/dist/es5/lib/geojson-to-flat-geojson.js.map +0 -1
  35. package/dist/es5/lib/transform.js +0 -73
  36. package/dist/es5/lib/transform.js.map +0 -1
  37. package/dist/esm/bundle.js +0 -5
  38. package/dist/esm/bundle.js.map +0 -1
  39. package/dist/esm/index.js +0 -6
  40. package/dist/esm/index.js.map +0 -1
  41. package/dist/esm/lib/binary-to-geojson.js +0 -274
  42. package/dist/esm/lib/binary-to-geojson.js.map +0 -1
  43. package/dist/esm/lib/extract-geometry-info.js +0 -105
  44. package/dist/esm/lib/extract-geometry-info.js.map +0 -1
  45. package/dist/esm/lib/flat-geojson-to-binary-types.js +0 -2
  46. package/dist/esm/lib/flat-geojson-to-binary-types.js.map +0 -1
  47. package/dist/esm/lib/flat-geojson-to-binary.js +0 -339
  48. package/dist/esm/lib/flat-geojson-to-binary.js.map +0 -1
  49. package/dist/esm/lib/geojson-to-binary.js +0 -21
  50. package/dist/esm/lib/geojson-to-binary.js.map +0 -1
  51. package/dist/esm/lib/geojson-to-flat-geojson.js +0 -116
  52. package/dist/esm/lib/geojson-to-flat-geojson.js.map +0 -1
  53. package/dist/esm/lib/transform.js +0 -50
  54. package/dist/esm/lib/transform.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/geojson-to-flat-geojson.ts"],"names":["geojsonToFlatGeojson","features","options","coordLength","fixRingWinding","map","feature","flattenFeature","flattenPoint","coordinates","data","indices","push","length","i","flattenLineString","c","flattenPolygon","areas","count","ringAreas","polygons","lineString","lineString2d","p","slice","area","flat","ccw","reverse","geometry","type","Error"],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;;;AA0BO,SAASA,oBAAT,CACLC,QADK,EAGU;AAAA,MADfC,OACe,uEADwB;AAACC,IAAAA,WAAW,EAAE,CAAd;AAAiBC,IAAAA,cAAc,EAAE;AAAjC,GACxB;AACf,SAAOH,QAAQ,CAACI,GAAT,CAAa,UAACC,OAAD;AAAA,WAAaC,cAAc,CAACD,OAAD,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AOpB,MAAAA,OAAO,EAAPA,OAAP;AAAgBD,MAAAA,IAAI,EAAJA,IAAhB;AAAsBQ,MAAAA,KAAK,EAALA;AAAtB;AAA9B;AACD","sourcesContent":["import {getPolygonSignedArea} from '@math.gl/polygon';\n\nimport {Feature, Position, FlatFeature} from '@loaders.gl/schema';\n\n/**\n * Options for `geojsonToFlatGeojson`\n */\nexport type GeojsonToFlatGeojsonOptions = {\n coordLength: number;\n fixRingWinding: boolean;\n};\n\n// Coordinates defining a Point\ntype PointCoordinates = Position;\n// Coordinates defining a LineString\ntype LineStringCoordinates = Position[];\n// Coordinates defining a Polygon\ntype PolygonCoordinates = Position[][];\n\n/**\n * Convert GeoJSON features to Flat GeoJSON features\n *\n * @param features\n * @param options\n * @returns an Array of Flat GeoJSON features\n */\nexport function geojsonToFlatGeojson(\n features: Feature[],\n options: GeojsonToFlatGeojsonOptions = {coordLength: 2, fixRingWinding: true}\n): FlatFeature[] {\n return features.map((feature) => flattenFeature(feature, options));\n}\n\n/**\n * Helper function to copy Point values from `coordinates` into `data` & `indices`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param options\n */\nfunction flattenPoint(\n coordinates: PointCoordinates,\n data: number[],\n indices: number[],\n options: GeojsonToFlatGeojsonOptions\n) {\n indices.push(data.length);\n data.push(...coordinates);\n\n // Pad up to coordLength\n for (let i = coordinates.length; i < options.coordLength; i++) {\n data.push(0);\n }\n}\n\n/**\n * Helper function to copy LineString values from `coordinates` into `data` & `indices`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param options\n */\nfunction flattenLineString(\n coordinates: LineStringCoordinates,\n data: number[],\n indices: number[],\n options: GeojsonToFlatGeojsonOptions\n) {\n indices.push(data.length);\n for (const c of coordinates) {\n data.push(...c);\n\n // Pad up to coordLength\n for (let i = c.length; i < options.coordLength; i++) {\n data.push(0);\n }\n }\n}\n\n/**\n * Helper function to copy Polygon values from `coordinates` into `data` & `indices` & `areas`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param areas\n * @param options\n */\nfunction flattenPolygon(\n coordinates: PolygonCoordinates,\n data: number[],\n indices: number[][],\n areas: number[][],\n options: GeojsonToFlatGeojsonOptions\n) {\n let count = 0;\n const ringAreas: number[] = [];\n const polygons: number[] = [];\n for (const lineString of coordinates) {\n const lineString2d = lineString.map((p) => p.slice(0, 2));\n let area = getPolygonSignedArea(lineString2d.flat());\n const ccw = area < 0;\n\n // Exterior ring must be CCW and interior rings CW\n if (options.fixRingWinding && ((count === 0 && !ccw) || (count > 0 && ccw))) {\n lineString.reverse();\n area = -area;\n }\n ringAreas.push(area);\n flattenLineString(lineString, data, polygons, options);\n count++;\n }\n\n if (count > 0) {\n areas.push(ringAreas);\n indices.push(polygons);\n }\n}\n\n/**\n * Flatten single GeoJSON feature into Flat GeoJSON\n *\n * @param feature\n * @param options\n * @returns A Flat GeoJSON feature\n */\nfunction flattenFeature(feature: Feature, options: GeojsonToFlatGeojsonOptions): FlatFeature {\n const {geometry} = feature;\n if (geometry.type === 'GeometryCollection') {\n throw new Error('GeometryCollection type not supported');\n }\n const data = [];\n const indices = [];\n let areas;\n let type;\n\n switch (geometry.type) {\n case 'Point':\n type = 'Point';\n flattenPoint(geometry.coordinates, data, indices, options);\n break;\n case 'MultiPoint':\n type = 'Point';\n geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));\n break;\n case 'LineString':\n type = 'LineString';\n flattenLineString(geometry.coordinates, data, indices, options);\n break;\n case 'MultiLineString':\n type = 'LineString';\n geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));\n break;\n case 'Polygon':\n type = 'Polygon';\n areas = [];\n flattenPolygon(geometry.coordinates, data, indices, areas, options);\n break;\n case 'MultiPolygon':\n type = 'Polygon';\n areas = [];\n geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));\n break;\n default:\n throw new Error(`Unknown type: ${type}`);\n }\n\n return {...feature, geometry: {type, indices, data, areas}};\n}\n"],"file":"geojson-to-flat-geojson.js"}
@@ -1,73 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.transformBinaryCoords = transformBinaryCoords;
7
- exports.transformGeoJsonCoords = transformGeoJsonCoords;
8
-
9
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
10
-
11
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
-
13
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
14
-
15
- function transformBinaryCoords(binaryFeatures, transformCoordinate) {
16
- if (binaryFeatures.points) {
17
- transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);
18
- }
19
-
20
- if (binaryFeatures.lines) {
21
- transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);
22
- }
23
-
24
- if (binaryFeatures.polygons) {
25
- transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);
26
- }
27
-
28
- return binaryFeatures;
29
- }
30
-
31
- function transformBinaryGeometryPositions(binaryGeometry, fn) {
32
- var positions = binaryGeometry.positions;
33
-
34
- for (var i = 0; i < positions.value.length; i += positions.size) {
35
- var _coord = Array.from(positions.value.subarray(i, i + positions.size));
36
-
37
- var transformedCoord = fn(_coord);
38
- positions.value.set(transformedCoord, i);
39
- }
40
- }
41
-
42
- function transformGeoJsonCoords(features, fn) {
43
- var _iterator = _createForOfIteratorHelper(features),
44
- _step;
45
-
46
- try {
47
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
48
- var feature = _step.value;
49
- feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);
50
- }
51
- } catch (err) {
52
- _iterator.e(err);
53
- } finally {
54
- _iterator.f();
55
- }
56
-
57
- return features;
58
- }
59
-
60
- function coordMap(array, fn) {
61
- if (isCoord(array)) {
62
- return fn(array);
63
- }
64
-
65
- return array.map(function (item) {
66
- return coordMap(item, fn);
67
- });
68
- }
69
-
70
- function isCoord(array) {
71
- return Number.isFinite(array[0]) && Number.isFinite(array[1]);
72
- }
73
- //# sourceMappingURL=transform.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/transform.ts"],"names":["transformBinaryCoords","binaryFeatures","transformCoordinate","points","transformBinaryGeometryPositions","lines","polygons","binaryGeometry","fn","positions","i","value","length","size","coord","Array","from","subarray","transformedCoord","set","transformGeoJsonCoords","features","feature","geometry","coordinates","coordMap","array","isCoord","map","item","Number","isFinite"],"mappings":";;;;;;;;;;;;;;AAUO,SAASA,qBAAT,CACLC,cADK,EAELC,mBAFK,EAGW;AAChB,MAAID,cAAc,CAACE,MAAnB,EAA2B;AACzBC,IAAAA,gCAAgC,CAACH,cAAc,CAACE,MAAhB,EAAwBD,mBAAxB,CAAhC;AACD;;AACD,MAAID,cAAc,CAACI,KAAnB,EAA0B;AACxBD,IAAAA,gCAAgC,CAACH,cAAc,CAACI,KA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B,WAAOJ,QAAQ,CAACI,IAAD,EAAOrB,EAAP,CAAf;AACD,GAFM,CAAP;AAGD;;AAED,SAASmB,OAAT,CAAiBD,KAAjB,EAAwB;AACtB,SAAOI,MAAM,CAACC,QAAP,CAAgBL,KAAK,CAAC,CAAD,CAArB,KAA6BI,MAAM,CAACC,QAAP,CAAgBL,KAAK,CAAC,CAAD,CAArB,CAApC;AACD","sourcesContent":["import type {BinaryFeatures, BinaryGeometry} from '@loaders.gl/schema';\n\ntype TransformCoordinate = (coord: number[]) => number[];\n\n/**\n * Apply transformation to every coordinate of binary features\n * @param binaryFeatures binary features\n * @param transformCoordinate Function to call on each coordinate\n * @return Transformed binary features\n */\nexport function transformBinaryCoords(\n binaryFeatures: BinaryFeatures,\n transformCoordinate: TransformCoordinate\n): BinaryFeatures {\n if (binaryFeatures.points) {\n transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);\n }\n if (binaryFeatures.lines) {\n transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);\n }\n if (binaryFeatures.polygons) {\n transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);\n }\n return binaryFeatures;\n}\n\n/** Transform one binary geometry */\nfunction transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: TransformCoordinate) {\n const {positions} = binaryGeometry;\n for (let i = 0; i < positions.value.length; i += positions.size) {\n // @ts-ignore inclusion of bigint causes problems\n const coord: Array<number> = Array.from(positions.value.subarray(i, i + positions.size));\n const transformedCoord = fn(coord);\n // @ts-ignore typescript typing for .set seems to require bigint?\n positions.value.set(transformedCoord, i);\n }\n}\n\n/**\n * Apply transformation to every coordinate of GeoJSON features\n *\n * @param features Array of GeoJSON features\n * @param fn Function to call on each coordinate\n * @return Transformed GeoJSON features\n */\nexport function transformGeoJsonCoords(\n features: object[],\n fn: (coord: number[]) => number[]\n): object[] {\n for (const feature of features) {\n // @ts-ignore\n feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);\n }\n return features;\n}\n\nfunction coordMap(array, fn) {\n if (isCoord(array)) {\n return fn(array);\n }\n\n return array.map((item) => {\n return coordMap(item, fn);\n });\n}\n\nfunction isCoord(array) {\n return Number.isFinite(array[0]) && Number.isFinite(array[1]);\n}\n"],"file":"transform.js"}
@@ -1,5 +0,0 @@
1
- const moduleExports = require('./index');
2
-
3
- globalThis.loaders = globalThis.loaders || {};
4
- module.exports = Object.assign(globalThis.loaders, moduleExports);
5
- //# sourceMappingURL=bundle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
package/dist/esm/index.js DELETED
@@ -1,6 +0,0 @@
1
- export { flatGeojsonToBinary } from './lib/flat-geojson-to-binary';
2
- export { geojsonToBinary } from './lib/geojson-to-binary';
3
- export { geojsonToFlatGeojson } from './lib/geojson-to-flat-geojson';
4
- export { binaryToGeojson, binaryToGeoJson, binaryToGeometry } from './lib/binary-to-geojson';
5
- export { transformBinaryCoords, transformGeoJsonCoords } from './lib/transform';
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":["flatGeojsonToBinary","geojsonToBinary","geojsonToFlatGeojson","binaryToGeojson","binaryToGeoJson","binaryToGeometry","transformBinaryCoords","transformGeoJsonCoords"],"mappings":"AAGA,SAAQA,mBAAR,QAAkC,8BAAlC;AACA,SAAQC,eAAR,QAA8B,yBAA9B;AACA,SAAQC,oBAAR,QAAmC,+BAAnC;AACA,SAAQC,eAAR,EAAyBC,eAAzB,EAA0CC,gBAA1C,QAAiE,yBAAjE;AACA,SAAQC,qBAAR,EAA+BC,sBAA/B,QAA4D,iBAA5D","sourcesContent":["// Types from `@loaders.gl/schema`\n\n// Functions\nexport {flatGeojsonToBinary} from './lib/flat-geojson-to-binary';\nexport {geojsonToBinary} from './lib/geojson-to-binary';\nexport {geojsonToFlatGeojson} from './lib/geojson-to-flat-geojson';\nexport {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"file":"index.js"}
@@ -1,274 +0,0 @@
1
- export function binaryToGeojson(data, options) {
2
- const globalFeatureId = options === null || options === void 0 ? void 0 : options.globalFeatureId;
3
-
4
- if (globalFeatureId !== undefined) {
5
- return getSingleFeature(data, globalFeatureId);
6
- }
7
-
8
- return parseFeatures(data, options === null || options === void 0 ? void 0 : options.type);
9
- }
10
- export function binaryToGeoJson(data, type, format = 'feature') {
11
- switch (format) {
12
- case 'feature':
13
- return parseFeatures(data, type);
14
-
15
- case 'geometry':
16
- return binaryToGeometry(data);
17
-
18
- default:
19
- throw new Error(format);
20
- }
21
- }
22
-
23
- function getSingleFeature(data, globalFeatureId) {
24
- const dataArray = normalizeInput(data);
25
-
26
- for (const data of dataArray) {
27
- let lastIndex = 0;
28
- let lastValue = data.featureIds.value[0];
29
-
30
- for (let i = 0; i < data.featureIds.value.length; i++) {
31
- const currValue = data.featureIds.value[i];
32
-
33
- if (currValue === lastValue) {
34
- continue;
35
- }
36
-
37
- if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {
38
- return parseFeature(data, lastIndex, i);
39
- }
40
-
41
- lastIndex = i;
42
- lastValue = currValue;
43
- }
44
-
45
- if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {
46
- return parseFeature(data, lastIndex, data.featureIds.value.length);
47
- }
48
- }
49
-
50
- throw new Error("featureId:".concat(globalFeatureId, " not found"));
51
- }
52
-
53
- function parseFeatures(data, type) {
54
- const dataArray = normalizeInput(data, type);
55
- return parseFeatureCollection(dataArray);
56
- }
57
-
58
- export function binaryToGeometry(data, startIndex, endIndex) {
59
- switch (data.type) {
60
- case 'Point':
61
- return pointToGeoJson(data, startIndex, endIndex);
62
-
63
- case 'LineString':
64
- return lineStringToGeoJson(data, startIndex, endIndex);
65
-
66
- case 'Polygon':
67
- return polygonToGeoJson(data, startIndex, endIndex);
68
-
69
- default:
70
- const unexpectedInput = data;
71
- throw new Error("Unsupported geometry type: ".concat(unexpectedInput === null || unexpectedInput === void 0 ? void 0 : unexpectedInput.type));
72
- }
73
- }
74
-
75
- function normalizeInput(data, type) {
76
- const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons);
77
-
78
- if (!isHeterogeneousType) {
79
- data.type = type || parseType(data);
80
- return [data];
81
- }
82
-
83
- const features = [];
84
-
85
- if (data.points) {
86
- data.points.type = 'Point';
87
- features.push(data.points);
88
- }
89
-
90
- if (data.lines) {
91
- data.lines.type = 'LineString';
92
- features.push(data.lines);
93
- }
94
-
95
- if (data.polygons) {
96
- data.polygons.type = 'Polygon';
97
- features.push(data.polygons);
98
- }
99
-
100
- return features;
101
- }
102
-
103
- function parseFeatureCollection(dataArray) {
104
- const features = [];
105
-
106
- for (const data of dataArray) {
107
- if (data.featureIds.value.length === 0) {
108
- continue;
109
- }
110
-
111
- let lastIndex = 0;
112
- let lastValue = data.featureIds.value[0];
113
-
114
- for (let i = 0; i < data.featureIds.value.length; i++) {
115
- const currValue = data.featureIds.value[i];
116
-
117
- if (currValue === lastValue) {
118
- continue;
119
- }
120
-
121
- features.push(parseFeature(data, lastIndex, i));
122
- lastIndex = i;
123
- lastValue = currValue;
124
- }
125
-
126
- features.push(parseFeature(data, lastIndex, data.featureIds.value.length));
127
- }
128
-
129
- return features;
130
- }
131
-
132
- function parseFeature(data, startIndex, endIndex) {
133
- const geometry = binaryToGeometry(data, startIndex, endIndex);
134
- const properties = parseProperties(data, startIndex, endIndex);
135
- const fields = parseFields(data, startIndex, endIndex);
136
- return {
137
- type: 'Feature',
138
- geometry,
139
- properties,
140
- ...fields
141
- };
142
- }
143
-
144
- function parseFields(data, startIndex = 0, endIndex) {
145
- return data.fields && data.fields[data.featureIds.value[startIndex]];
146
- }
147
-
148
- function parseProperties(data, startIndex = 0, endIndex) {
149
- const properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);
150
-
151
- for (const key in data.numericProps) {
152
- properties[key] = data.numericProps[key].value[startIndex];
153
- }
154
-
155
- return properties;
156
- }
157
-
158
- function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
159
- const {
160
- positions
161
- } = data;
162
- const polygonIndices = data.polygonIndices.value.filter(x => x >= startIndex && x <= endIndex);
163
- const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(x => x >= startIndex && x <= endIndex);
164
- const multi = polygonIndices.length > 2;
165
-
166
- if (!multi) {
167
- const coordinates = [];
168
-
169
- for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
170
- const startRingIndex = primitivePolygonIndices[i];
171
- const endRingIndex = primitivePolygonIndices[i + 1];
172
- const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
173
- coordinates.push(ringCoordinates);
174
- }
175
-
176
- return {
177
- type: 'Polygon',
178
- coordinates
179
- };
180
- }
181
-
182
- const coordinates = [];
183
-
184
- for (let i = 0; i < polygonIndices.length - 1; i++) {
185
- const startPolygonIndex = polygonIndices[i];
186
- const endPolygonIndex = polygonIndices[i + 1];
187
- const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
188
- coordinates.push(polygonCoordinates);
189
- }
190
-
191
- return {
192
- type: 'MultiPolygon',
193
- coordinates
194
- };
195
- }
196
-
197
- function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
198
- const {
199
- positions
200
- } = data;
201
- const pathIndices = data.pathIndices.value.filter(x => x >= startIndex && x <= endIndex);
202
- const multi = pathIndices.length > 2;
203
-
204
- if (!multi) {
205
- const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
206
- return {
207
- type: 'LineString',
208
- coordinates
209
- };
210
- }
211
-
212
- const coordinates = [];
213
-
214
- for (let i = 0; i < pathIndices.length - 1; i++) {
215
- const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
216
- coordinates.push(ringCoordinates);
217
- }
218
-
219
- return {
220
- type: 'MultiLineString',
221
- coordinates
222
- };
223
- }
224
-
225
- function pointToGeoJson(data, startIndex, endIndex) {
226
- const {
227
- positions
228
- } = data;
229
- const coordinates = ringToGeoJson(positions, startIndex, endIndex);
230
- const multi = coordinates.length > 1;
231
-
232
- if (multi) {
233
- return {
234
- type: 'MultiPoint',
235
- coordinates
236
- };
237
- }
238
-
239
- return {
240
- type: 'Point',
241
- coordinates: coordinates[0]
242
- };
243
- }
244
-
245
- function ringToGeoJson(positions, startIndex, endIndex) {
246
- startIndex = startIndex || 0;
247
- endIndex = endIndex || positions.value.length / positions.size;
248
- const ringCoordinates = [];
249
-
250
- for (let j = startIndex; j < endIndex; j++) {
251
- const coord = Array();
252
-
253
- for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
254
- coord.push(Number(positions.value[k]));
255
- }
256
-
257
- ringCoordinates.push(coord);
258
- }
259
-
260
- return ringCoordinates;
261
- }
262
-
263
- function parseType(data) {
264
- if (data.pathIndices) {
265
- return 'LineString';
266
- }
267
-
268
- if (data.polygonIndices) {
269
- return 'Polygon';
270
- }
271
-
272
- return 'Point';
273
- }
274
- //# sourceMappingURL=binary-to-geojson.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/binary-to-geojson.ts"],"names":["binaryToGeojson","data","options","globalFeatureId","undefined","getSingleFeature","parseFeatures","type","binaryToGeoJson","format","binaryToGeometry","Error","dataArray","normalizeInput","lastIndex","lastValue","featureIds","value","i","length","currValue","globalFeatureIds","parseFeature","parseFeatureCollection","startIndex","endIndex","pointToGeoJson","lineStringToGeoJson","polygonToGeoJson","unexpectedInput","isHeterogeneousType","Boolean","points","lines","polygons","parseType","features","push","geometry","properties","parseProperties","fields","parseFields","Object","assign","key","numericProps","Infinity","positions","polygonIndices","filter","x","primitivePolygonIndices","multi","coordinates","startRingIndex","endRingIndex","ringCoordinates","ringToGeoJson","startPolygonIndex","endPolygonIndex","polygonCoordinates","pathIndices","size","j","coord","Array","k","Number"],"mappings":"AAmCA,OAAO,SAASA,eAAT,CACLC,IADK,EAELC,OAFK,EAGgB;AACrB,QAAMC,eAAe,GAAGD,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEC,eAAjC;;AACA,MAAIA,eAAe,KAAKC,SAAxB,EAAmC;AACjC,WAAOC,gBAAgB,CAACJ,IAAD,EAAOE,eAAP,CAAvB;AACD;;AACD,SAAOG,aAAa,CAACL,IAAD,EAAOC,OAAP,aAAOA,OAAP,uBAAOA,OAAO,CAAEK,IAAhB,CAApB;AACD;AAGD,OAAO,SAASC,eAAT,CACLP,IADK,EAELM,IAFK,EAGLE,MAA8B,GAAG,SAH5B,EAIiB;AACtB,UAAQA,MAAR;AACE,SAAK,SAAL;AACE,aAAOH,aAAa,CAACL,IAAD,EAAyBM,IAAzB,CAApB;;AACF,SAAK,UAAL;AACE,aAAOG,gBAAgB,CAACT,IAAD,CAAvB;;AACF;AACE,YAAM,IAAIU,KAAJ,CAAUF,MAAV,CAAN;AANJ;AAQD;;AAOD,SAASJ,gBAAT,CAA0BJ,IAA1B,EAAgDE,eAAhD,EAAkF;AAChF,QAAMS,SAAS,GAAGC,cAAc,CAACZ,IAAD,CAAhC;;AACA,OAAK,MAAMA,IAAX,IAAmBW,SAAnB,EAA8B;AAC5B,QAAIE,SAAS,GAAG,CAAhB;AACA,QAAIC,SAAS,GAAGd,IAAI,CAACe,UAAL,CAAgBC,KAAhB,CAAsB,CAAtB,CAAhB;;AAGA,SAAK,IA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Features,\n BinaryLineFeatures,\n BinaryPolygonFeatures,\n BinaryAttribute\n} from '@loaders.gl/schema';\nimport type {Feature, Geometry, Position, GeoJsonProperties} from '@loaders.gl/schema';\nimport type {\n Point,\n MultiPoint,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon\n} from '@loaders.gl/schema';\n\n// Note:L We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.\n// type FeatureGeometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;\n\ntype BinaryToGeoJsonOptions = {\n type?: BinaryGeometryType;\n globalFeatureId?: number;\n};\n\n/**\n * Convert binary geometry representation to GeoJSON\n * @param data geometry data in binary representation\n * @param options\n * @param options.type Input data type: Point, LineString, or Polygon\n * @param options.featureId Global feature id. If specified, only a single feature is extracted\n * @return GeoJSON objects\n */\nexport function binaryToGeojson(\n data: BinaryFeatures,\n options?: BinaryToGeoJsonOptions\n): Feature[] | Feature {\n const globalFeatureId = options?.globalFeatureId;\n if (globalFeatureId !== undefined) {\n return getSingleFeature(data, globalFeatureId);\n }\n return parseFeatures(data, options?.type);\n}\n\n/** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead */\nexport function binaryToGeoJson(\n data: BinaryGeometry | BinaryFeatures,\n type?: BinaryGeometryType,\n format: 'feature' | 'geometry' = 'feature'\n): Geometry | Feature[] {\n switch (format) {\n case 'feature':\n return parseFeatures(data as BinaryFeatures, type);\n case 'geometry':\n return binaryToGeometry(data as BinaryGeometry);\n default:\n throw new Error(format);\n }\n}\n\n/**\n * Return a single feature from a binary geometry representation as GeoJSON\n * @param data geometry data in binary representation\n * @return GeoJSON feature\n */\nfunction getSingleFeature(data: BinaryFeatures, globalFeatureId: number): Feature {\n const dataArray = normalizeInput(data);\n for (const data of dataArray) {\n let lastIndex = 0;\n let lastValue = data.featureIds.value[0];\n\n // Scan through data until we find matching feature\n for (let i = 0; i < data.featureIds.value.length; i++) {\n const currValue = data.featureIds.value[i];\n if (currValue === lastValue) {\n // eslint-disable-next-line no-continue\n continue;\n }\n if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {\n return parseFeature(data, lastIndex, i);\n }\n lastIndex = i;\n lastValue = currValue;\n }\n\n if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {\n return parseFeature(data, lastIndex, data.featureIds.value.length);\n }\n }\n\n throw new Error(`featureId:${globalFeatureId} not found`);\n}\n\nfunction parseFeatures(data: BinaryFeatures, type?: BinaryGeometryType): Feature[] {\n const dataArray = normalizeInput(data, type);\n return parseFeatureCollection(dataArray);\n}\n\n/** Parse input binary data and return a valid GeoJSON geometry object */\nexport function binaryToGeometry(\n data: BinaryGeometry,\n startIndex?: number,\n endIndex?: number\n): Geometry {\n switch (data.type) {\n case 'Point':\n return pointToGeoJson(data, startIndex, endIndex);\n case 'LineString':\n return lineStringToGeoJson(data, startIndex, endIndex);\n case 'Polygon':\n return polygonToGeoJson(data, startIndex, endIndex);\n default:\n const unexpectedInput: never = data;\n throw new Error(`Unsupported geometry type: ${(unexpectedInput as any)?.type}`);\n }\n}\n\ntype BinaryFeature = BinaryPointFeatures | BinaryLineFeatures | BinaryPolygonFeatures;\ntype BinaryFeaturesArray = BinaryFeature[];\n\n// Normalize features\n// Return an array of data objects, each of which have a type key\nfunction normalizeInput(data: BinaryFeatures, type?: BinaryGeometryType): BinaryFeaturesArray {\n const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons);\n\n if (!isHeterogeneousType) {\n // @ts-expect-error This is a legacy check which allowed `data` to be an instance of the values\n // here. Aka the new data.points, data.lines, or data.polygons.\n data.type = type || parseType(data);\n return [data] as BinaryFeaturesArray;\n }\n\n const features: BinaryFeaturesArray = [];\n if (data.points) {\n data.points.type = 'Point';\n features.push(data.points);\n }\n if (data.lines) {\n data.lines.type = 'LineString';\n features.push(data.lines);\n }\n if (data.polygons) {\n data.polygons.type = 'Polygon';\n features.push(data.polygons);\n }\n\n return features;\n}\n\n/** Parse input binary data and return an array of GeoJSON Features */\nfunction parseFeatureCollection(dataArray): Feature[] {\n const features: Feature[] = [];\n for (const data of dataArray) {\n if (data.featureIds.value.length === 0) {\n // eslint-disable-next-line no-continue\n continue;\n }\n let lastIndex = 0;\n let lastValue = data.featureIds.value[0];\n\n // Need to deduce start, end indices of each feature\n for (let i = 0; i < data.featureIds.value.length; i++) {\n const currValue = data.featureIds.value[i];\n if (currValue === lastValue) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n features.push(parseFeature(data, lastIndex, i));\n lastIndex = i;\n lastValue = currValue;\n }\n\n // Last feature\n features.push(parseFeature(data, lastIndex, data.featureIds.value.length));\n }\n return features;\n}\n\n/** Parse input binary data and return a single GeoJSON Feature */\nfunction parseFeature(data, startIndex?: number, endIndex?: number): Feature {\n const geometry = binaryToGeometry(data, startIndex, endIndex);\n const properties = parseProperties(data, startIndex, endIndex);\n const fields = parseFields(data, startIndex, endIndex);\n return {type: 'Feature', geometry, properties, ...fields};\n}\n\n/** Parse input binary data and return an object of fields */\nfunction parseFields(data, startIndex: number = 0, endIndex?: number): GeoJsonProperties {\n return data.fields && data.fields[data.featureIds.value[startIndex]];\n}\n\n/** Parse input binary data and return an object of properties */\nfunction parseProperties(data, startIndex: number = 0, endIndex?: number): GeoJsonProperties {\n const properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);\n for (const key in data.numericProps) {\n properties[key] = data.numericProps[key].value[startIndex];\n }\n return properties;\n}\n\n/** Parse binary data of type Polygon */\nfunction polygonToGeoJson(\n data,\n startIndex: number = -Infinity,\n endIndex: number = Infinity\n): Polygon | MultiPolygon {\n const {positions} = data;\n const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);\n const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(\n (x) => x >= startIndex && x <= endIndex\n );\n const multi = polygonIndices.length > 2;\n\n // Polygon\n if (!multi) {\n const coordinates: Position[][] = [];\n for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {\n const startRingIndex = primitivePolygonIndices[i];\n const endRingIndex = primitivePolygonIndices[i + 1];\n const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);\n coordinates.push(ringCoordinates);\n }\n\n return {type: 'Polygon', coordinates};\n }\n\n // MultiPolygon\n const coordinates: Position[][][] = [];\n for (let i = 0; i < polygonIndices.length - 1; i++) {\n const startPolygonIndex = polygonIndices[i];\n const endPolygonIndex = polygonIndices[i + 1];\n const polygonCoordinates = polygonToGeoJson(\n data,\n startPolygonIndex,\n endPolygonIndex\n ).coordinates;\n coordinates.push(polygonCoordinates as Position[][]);\n }\n\n return {type: 'MultiPolygon', coordinates};\n}\n\n/** Parse binary data of type LineString */\nfunction lineStringToGeoJson(\n data,\n startIndex: number = -Infinity,\n endIndex: number = Infinity\n): LineString | MultiLineString {\n const {positions} = data;\n const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);\n const multi = pathIndices.length > 2;\n\n if (!multi) {\n const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);\n return {type: 'LineString', coordinates};\n }\n\n const coordinates: Position[][] = [];\n for (let i = 0; i < pathIndices.length - 1; i++) {\n const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);\n coordinates.push(ringCoordinates);\n }\n\n return {type: 'MultiLineString', coordinates};\n}\n\n/** Parse binary data of type Point */\nfunction pointToGeoJson(data, startIndex, endIndex): Point | MultiPoint {\n const {positions} = data;\n const coordinates = ringToGeoJson(positions, startIndex, endIndex);\n const multi = coordinates.length > 1;\n\n if (multi) {\n return {type: 'MultiPoint', coordinates};\n }\n\n return {type: 'Point', coordinates: coordinates[0]};\n}\n\n/**\n * Parse a linear ring of positions to a GeoJSON linear ring\n *\n * @param positions Positions TypedArray\n * @param startIndex Start index to include in ring\n * @param endIndex End index to include in ring\n * @returns GeoJSON ring\n */\nfunction ringToGeoJson(\n positions: BinaryAttribute,\n startIndex?: number,\n endIndex?: number\n): Position[] {\n startIndex = startIndex || 0;\n endIndex = endIndex || positions.value.length / positions.size;\n\n const ringCoordinates: Position[] = [];\n for (let j = startIndex; j < endIndex; j++) {\n const coord = Array<number>();\n for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {\n coord.push(Number(positions.value[k]));\n }\n ringCoordinates.push(coord);\n }\n return ringCoordinates;\n}\n\n// Deduce geometry type of data object\nfunction parseType(data) {\n if (data.pathIndices) {\n return 'LineString';\n }\n\n if (data.polygonIndices) {\n return 'Polygon';\n }\n\n return 'Point';\n}\n"],"file":"binary-to-geojson.js"}
@@ -1,105 +0,0 @@
1
- export function extractGeometryInfo(features) {
2
- let pointPositionsCount = 0;
3
- let pointFeaturesCount = 0;
4
- let linePositionsCount = 0;
5
- let linePathsCount = 0;
6
- let lineFeaturesCount = 0;
7
- let polygonPositionsCount = 0;
8
- let polygonObjectsCount = 0;
9
- let polygonRingsCount = 0;
10
- let polygonFeaturesCount = 0;
11
- const coordLengths = new Set();
12
-
13
- for (const feature of features) {
14
- const geometry = feature.geometry;
15
-
16
- switch (geometry.type) {
17
- case 'Point':
18
- pointFeaturesCount++;
19
- pointPositionsCount++;
20
- coordLengths.add(geometry.coordinates.length);
21
- break;
22
-
23
- case 'MultiPoint':
24
- pointFeaturesCount++;
25
- pointPositionsCount += geometry.coordinates.length;
26
-
27
- for (const point of geometry.coordinates) {
28
- coordLengths.add(point.length);
29
- }
30
-
31
- break;
32
-
33
- case 'LineString':
34
- lineFeaturesCount++;
35
- linePositionsCount += geometry.coordinates.length;
36
- linePathsCount++;
37
-
38
- for (const coord of geometry.coordinates) {
39
- coordLengths.add(coord.length);
40
- }
41
-
42
- break;
43
-
44
- case 'MultiLineString':
45
- lineFeaturesCount++;
46
-
47
- for (const line of geometry.coordinates) {
48
- linePositionsCount += line.length;
49
- linePathsCount++;
50
-
51
- for (const coord of line) {
52
- coordLengths.add(coord.length);
53
- }
54
- }
55
-
56
- break;
57
-
58
- case 'Polygon':
59
- polygonFeaturesCount++;
60
- polygonObjectsCount++;
61
- polygonRingsCount += geometry.coordinates.length;
62
- const flattened = geometry.coordinates.flat();
63
- polygonPositionsCount += flattened.length;
64
-
65
- for (const coord of flattened) {
66
- coordLengths.add(coord.length);
67
- }
68
-
69
- break;
70
-
71
- case 'MultiPolygon':
72
- polygonFeaturesCount++;
73
-
74
- for (const polygon of geometry.coordinates) {
75
- polygonObjectsCount++;
76
- polygonRingsCount += polygon.length;
77
- const flattened = polygon.flat();
78
- polygonPositionsCount += flattened.length;
79
-
80
- for (const coord of flattened) {
81
- coordLengths.add(coord.length);
82
- }
83
- }
84
-
85
- break;
86
-
87
- default:
88
- throw new Error("Unsupported geometry type: ".concat(geometry.type));
89
- }
90
- }
91
-
92
- return {
93
- coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
94
- pointPositionsCount,
95
- pointFeaturesCount,
96
- linePositionsCount,
97
- linePathsCount,
98
- lineFeaturesCount,
99
- polygonPositionsCount,
100
- polygonObjectsCount,
101
- polygonRingsCount,
102
- polygonFeaturesCount
103
- };
104
- }
105
- //# sourceMappingURL=extract-geometry-info.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/extract-geometry-info.ts"],"names":["extractGeometryInfo","features","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLengths","Set","feature","geometry","type","add","coordinates","length","point","coord","line","flattened","flat","polygon","Error","coordLength","size","Math","max"],"mappings":"AAQA,OAAO,SAASA,mBAAT,CAA6BC,QAA7B,EAAuE;AAE5E,MAAIC,mBAAmB,GAAG,CAA1B;AACA,MAAIC,kBAAkB,GAAG,CAAzB;AACA,MAAIC,kBAAkB,GAAG,CAAzB;AACA,MAAIC,cAAc,GAAG,CAArB;AACA,MAAIC,iBAAiB,GAAG,CAAxB;AACA,MAAIC,qBAAqB,GAAG,CAA5B;AACA,MAAIC,mBAAmB,GAAG,CAA1B;AACA,MAAIC,iBAAiB,GAAG,CAAxB;AACA,MAAIC,oBA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AACG,WAAT,CAAqBC,MAA1C;AACA,cAAMI,SAAS,GAAGR,QAAQ,CAACG,WAAT,CAAqBM,IAArB,EAAlB;AACAhB,QAAAA,qBAAqB,IAAIe,SAAS,CAACJ,MAAnC;;AAEA,aAAK,MAAME,KAAX,IAAoBE,SAApB,EAA+B;AAC7BX,UAAAA,YAAY,CAACK,GAAb,CAAiBI,KAAK,CAACF,MAAvB;AACD;;AACD;;AACF,WAAK,cAAL;AACER,QAAAA,oBAAoB;;AACpB,aAAK,MAAMc,OAAX,IAAsBV,QAAQ,CAACG,WAA/B,EAA4C;AAC1CT,UAAAA,mBAAmB;AACnBC,UAAAA,iBAAiB,IAAIe,OAAO,CAACN,MAA7B;AACA,gBAAMI,SAAS,GAAGE,OAAO,CAACD,IAAR,EAAlB;AACAhB,UAAAA,qBAAqB,IAAIe,SAAS,CAACJ,MAAnC;;AAGA,eAAK,MAAME,KAAX,IAAoBE,SAApB,EAA+B;AAC7BX,YAAAA,YAAY,CAACK,GAAb,CAAiBI,KAAK,CAACF,MAAvB;AACD;AACF;;AACD;;AACF;AACE,cAAM,IAAIO,KAAJ,sCAAwCX,QAAQ,CAACC,IAAjD,EAAN;AA5DJ;AA8DD;;AAED,SAAO;AACLW,IAAAA,WAAW,EAAEf,YAAY,CAACgB,IAAb,GAAoB,CAApB,GAAwBC,IAAI,CAACC,GAAL,CAAS,GAAGlB,YAAZ,CAAxB,GAAoD,CAD5D;AAGLT,IAAAA,mBAHK;AAILC,IAAAA,kBAJK;AAKLC,IAAAA,kBALK;AAMLC,IAAAA,cANK;AAOLC,IAAAA,iBAPK;AAQLC,IAAAA,qBARK;AASLC,IAAAA,mBATK;AAULC,IAAAA,iBAVK;AAWLC,IAAAA;AAXK,GAAP;AAaD","sourcesContent":["import {Feature, GeojsonGeometryInfo} from '@loaders.gl/schema';\n\n/**\n * Initial scan over GeoJSON features\n * Counts number of coordinates of each geometry type and\n * keeps track of the max coordinate dimensions\n */\n// eslint-disable-next-line complexity, max-statements\nexport function extractGeometryInfo(features: Feature[]): GeojsonGeometryInfo {\n // Counts the number of _positions_, so [x, y, z] counts as one\n let pointPositionsCount = 0;\n let pointFeaturesCount = 0;\n let linePositionsCount = 0;\n let linePathsCount = 0;\n let lineFeaturesCount = 0;\n let polygonPositionsCount = 0;\n let polygonObjectsCount = 0;\n let polygonRingsCount = 0;\n let polygonFeaturesCount = 0;\n const coordLengths = new Set<number>();\n\n for (const feature of features) {\n const geometry = feature.geometry;\n switch (geometry.type) {\n case 'Point':\n pointFeaturesCount++;\n pointPositionsCount++;\n coordLengths.add(geometry.coordinates.length);\n break;\n case 'MultiPoint':\n pointFeaturesCount++;\n pointPositionsCount += geometry.coordinates.length;\n for (const point of geometry.coordinates) {\n coordLengths.add(point.length);\n }\n break;\n case 'LineString':\n lineFeaturesCount++;\n linePositionsCount += geometry.coordinates.length;\n linePathsCount++;\n\n for (const coord of geometry.coordinates) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiLineString':\n lineFeaturesCount++;\n for (const line of geometry.coordinates) {\n linePositionsCount += line.length;\n linePathsCount++;\n\n // eslint-disable-next-line max-depth\n for (const coord of line) {\n coordLengths.add(coord.length);\n }\n }\n break;\n case 'Polygon':\n polygonFeaturesCount++;\n polygonObjectsCount++;\n polygonRingsCount += geometry.coordinates.length;\n const flattened = geometry.coordinates.flat();\n polygonPositionsCount += flattened.length;\n\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiPolygon':\n polygonFeaturesCount++;\n for (const polygon of geometry.coordinates) {\n polygonObjectsCount++;\n polygonRingsCount += polygon.length;\n const flattened = polygon.flat();\n polygonPositionsCount += flattened.length;\n\n // eslint-disable-next-line max-depth\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n }\n break;\n default:\n throw new Error(`Unsupported geometry type: ${geometry.type}`);\n }\n }\n\n return {\n coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,\n\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n };\n}\n"],"file":"extract-geometry-info.js"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=flat-geojson-to-binary-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"flat-geojson-to-binary-types.js"}