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

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 (68) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/es5/bundle.js +6 -0
  3. package/dist/es5/bundle.js.map +1 -0
  4. package/dist/es5/index.js +59 -0
  5. package/dist/es5/index.js.map +1 -0
  6. package/dist/es5/lib/binary-to-geojson.js +255 -0
  7. package/dist/es5/lib/binary-to-geojson.js.map +1 -0
  8. package/dist/es5/lib/extract-geometry-info.js +167 -0
  9. package/dist/es5/lib/extract-geometry-info.js.map +1 -0
  10. package/dist/es5/lib/flat-geojson-to-binary-types.js +2 -0
  11. package/dist/es5/lib/flat-geojson-to-binary-types.js.map +1 -0
  12. package/dist/es5/lib/flat-geojson-to-binary.js +344 -0
  13. package/dist/es5/lib/flat-geojson-to-binary.js.map +1 -0
  14. package/dist/es5/lib/geojson-to-binary.js +26 -0
  15. package/dist/es5/lib/geojson-to-binary.js.map +1 -0
  16. package/dist/es5/lib/geojson-to-flat-geojson.js +136 -0
  17. package/dist/es5/lib/geojson-to-flat-geojson.js.map +1 -0
  18. package/dist/es5/lib/transform.js +57 -0
  19. package/dist/es5/lib/transform.js.map +1 -0
  20. package/dist/esm/bundle.js +4 -0
  21. package/dist/esm/bundle.js.map +1 -0
  22. package/dist/esm/index.js +6 -0
  23. package/dist/esm/index.js.map +1 -0
  24. package/dist/esm/lib/binary-to-geojson.js +223 -0
  25. package/dist/esm/lib/binary-to-geojson.js.map +1 -0
  26. package/dist/esm/lib/extract-geometry-info.js +84 -0
  27. package/dist/esm/lib/extract-geometry-info.js.map +1 -0
  28. package/dist/esm/lib/flat-geojson-to-binary-types.js +2 -0
  29. package/dist/esm/lib/flat-geojson-to-binary-types.js.map +1 -0
  30. package/dist/esm/lib/flat-geojson-to-binary.js +305 -0
  31. package/dist/esm/lib/flat-geojson-to-binary.js.map +1 -0
  32. package/dist/esm/lib/geojson-to-binary.js +22 -0
  33. package/dist/esm/lib/geojson-to-binary.js.map +1 -0
  34. package/dist/esm/lib/geojson-to-flat-geojson.js +97 -0
  35. package/dist/esm/lib/geojson-to-flat-geojson.js.map +1 -0
  36. package/dist/esm/lib/transform.js +40 -0
  37. package/dist/esm/lib/transform.js.map +1 -0
  38. package/dist/index.js +18 -6
  39. package/dist/lib/binary-to-geojson.d.ts +1 -1
  40. package/dist/lib/binary-to-geojson.d.ts.map +1 -1
  41. package/dist/lib/binary-to-geojson.js +201 -242
  42. package/dist/lib/extract-geometry-info.js +93 -102
  43. package/dist/lib/flat-geojson-to-binary-types.d.ts +4 -4
  44. package/dist/lib/flat-geojson-to-binary-types.d.ts.map +1 -1
  45. package/dist/lib/flat-geojson-to-binary-types.js +2 -2
  46. package/dist/lib/flat-geojson-to-binary.d.ts +1 -1
  47. package/dist/lib/flat-geojson-to-binary.d.ts.map +1 -1
  48. package/dist/lib/flat-geojson-to-binary.js +346 -309
  49. package/dist/lib/geojson-to-binary.d.ts +1 -1
  50. package/dist/lib/geojson-to-binary.d.ts.map +1 -1
  51. package/dist/lib/geojson-to-binary.js +23 -20
  52. package/dist/lib/geojson-to-flat-geojson.d.ts +1 -1
  53. package/dist/lib/geojson-to-flat-geojson.d.ts.map +1 -1
  54. package/dist/lib/geojson-to-flat-geojson.js +116 -104
  55. package/dist/lib/transform.d.ts +1 -1
  56. package/dist/lib/transform.d.ts.map +1 -1
  57. package/dist/lib/transform.js +51 -42
  58. package/package.json +6 -6
  59. package/src/lib/flat-geojson-to-binary.ts +1 -0
  60. package/dist/bundle.js.map +0 -1
  61. package/dist/index.js.map +0 -1
  62. package/dist/lib/binary-to-geojson.js.map +0 -1
  63. package/dist/lib/extract-geometry-info.js.map +0 -1
  64. package/dist/lib/flat-geojson-to-binary-types.js.map +0 -1
  65. package/dist/lib/flat-geojson-to-binary.js.map +0 -1
  66. package/dist/lib/geojson-to-binary.js.map +0 -1
  67. package/dist/lib/geojson-to-flat-geojson.js.map +0 -1
  68. package/dist/lib/transform.js.map +0 -1
@@ -3,7 +3,7 @@ import type { BinaryFeatures } from '@loaders.gl/schema';
3
3
  /**
4
4
  * Options for `geojsonToBinary`
5
5
  */
6
- export declare type GeojsonToBinaryOptions = {
6
+ export type GeojsonToBinaryOptions = {
7
7
  fixRingWinding: boolean;
8
8
  numericPropKeys?: string[];
9
9
  PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;
@@ -1 +1 @@
1
- {"version":3,"file":"geojson-to-binary.d.ts","sourceRoot":"","sources":["../../src/lib/geojson-to-binary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAMvD;;GAEG;AACH,oBAAY,sBAAsB,GAAG;IACnC,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,uBAAuB,GAAG,uBAAuB,CAAC;CACtE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,sBAA+C,GACvD,cAAc,CAShB"}
1
+ {"version":3,"file":"geojson-to-binary.d.ts","sourceRoot":"","sources":["../../src/lib/geojson-to-binary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAMvD;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,uBAAuB,GAAG,uBAAuB,CAAC;CACtE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,sBAA+C,GACvD,cAAc,CAShB"}
@@ -1,21 +1,24 @@
1
- import { extractGeometryInfo } from './extract-geometry-info';
2
- import { geojsonToFlatGeojson } from './geojson-to-flat-geojson';
3
- import { flatGeojsonToBinary } from './flat-geojson-to-binary';
4
- export function geojsonToBinary(features, options = {
5
- fixRingWinding: true
6
- }) {
7
- const geometryInfo = extractGeometryInfo(features);
8
- const coordLength = geometryInfo.coordLength;
9
- const {
10
- fixRingWinding
11
- } = options;
12
- const flatFeatures = geojsonToFlatGeojson(features, {
13
- coordLength,
14
- fixRingWinding
15
- });
16
- return flatGeojsonToBinary(flatFeatures, geometryInfo, {
17
- numericPropKeys: options.numericPropKeys,
18
- PositionDataType: options.PositionDataType || Float32Array
19
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.geojsonToBinary = void 0;
4
+ const extract_geometry_info_1 = require("./extract-geometry-info");
5
+ const geojson_to_flat_geojson_1 = require("./geojson-to-flat-geojson");
6
+ const flat_geojson_to_binary_1 = require("./flat-geojson-to-binary");
7
+ /**
8
+ * Convert GeoJSON features to flat binary arrays
9
+ *
10
+ * @param features
11
+ * @param options
12
+ * @returns features in binary format, grouped by geometry type
13
+ */
14
+ function geojsonToBinary(features, options = { fixRingWinding: true }) {
15
+ const geometryInfo = (0, extract_geometry_info_1.extractGeometryInfo)(features);
16
+ const coordLength = geometryInfo.coordLength;
17
+ const { fixRingWinding } = options;
18
+ const flatFeatures = (0, geojson_to_flat_geojson_1.geojsonToFlatGeojson)(features, { coordLength, fixRingWinding });
19
+ return (0, flat_geojson_to_binary_1.flatGeojsonToBinary)(flatFeatures, geometryInfo, {
20
+ numericPropKeys: options.numericPropKeys,
21
+ PositionDataType: options.PositionDataType || Float32Array
22
+ });
20
23
  }
21
- //# sourceMappingURL=geojson-to-binary.js.map
24
+ exports.geojsonToBinary = geojsonToBinary;
@@ -2,7 +2,7 @@ import { Feature, FlatFeature } from '@loaders.gl/schema';
2
2
  /**
3
3
  * Options for `geojsonToFlatGeojson`
4
4
  */
5
- export declare type GeojsonToFlatGeojsonOptions = {
5
+ export type GeojsonToFlatGeojsonOptions = {
6
6
  coordLength: number;
7
7
  fixRingWinding: boolean;
8
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"geojson-to-flat-geojson.d.ts","sourceRoot":"","sources":["../../src/lib/geojson-to-flat-geojson.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAY,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAElE;;GAEG;AACH,oBAAY,2BAA2B,GAAG;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AASF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,2BAAoE,GAC5E,WAAW,EAAE,CAEf"}
1
+ {"version":3,"file":"geojson-to-flat-geojson.d.ts","sourceRoot":"","sources":["../../src/lib/geojson-to-flat-geojson.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAY,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AASF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,2BAAoE,GAC5E,WAAW,EAAE,CAEf"}
@@ -1,116 +1,128 @@
1
- import { getPolygonSignedArea } from '@math.gl/polygon';
2
- export function geojsonToFlatGeojson(features, options = {
3
- coordLength: 2,
4
- fixRingWinding: true
5
- }) {
6
- return features.map(feature => flattenFeature(feature, options));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.geojsonToFlatGeojson = void 0;
4
+ const polygon_1 = require("@math.gl/polygon");
5
+ /**
6
+ * Convert GeoJSON features to Flat GeoJSON features
7
+ *
8
+ * @param features
9
+ * @param options
10
+ * @returns an Array of Flat GeoJSON features
11
+ */
12
+ function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
13
+ return features.map((feature) => flattenFeature(feature, options));
7
14
  }
8
-
15
+ exports.geojsonToFlatGeojson = geojsonToFlatGeojson;
16
+ /**
17
+ * Helper function to copy Point values from `coordinates` into `data` & `indices`
18
+ *
19
+ * @param coordinates
20
+ * @param data
21
+ * @param indices
22
+ * @param options
23
+ */
9
24
  function flattenPoint(coordinates, data, indices, options) {
10
- indices.push(data.length);
11
- data.push(...coordinates);
12
-
13
- for (let i = coordinates.length; i < options.coordLength; i++) {
14
- data.push(0);
15
- }
25
+ indices.push(data.length);
26
+ data.push(...coordinates);
27
+ // Pad up to coordLength
28
+ for (let i = coordinates.length; i < options.coordLength; i++) {
29
+ data.push(0);
30
+ }
16
31
  }
17
-
32
+ /**
33
+ * Helper function to copy LineString values from `coordinates` into `data` & `indices`
34
+ *
35
+ * @param coordinates
36
+ * @param data
37
+ * @param indices
38
+ * @param options
39
+ */
18
40
  function flattenLineString(coordinates, data, indices, options) {
19
- indices.push(data.length);
20
-
21
- for (const c of coordinates) {
22
- data.push(...c);
23
-
24
- for (let i = c.length; i < options.coordLength; i++) {
25
- data.push(0);
41
+ indices.push(data.length);
42
+ for (const c of coordinates) {
43
+ data.push(...c);
44
+ // Pad up to coordLength
45
+ for (let i = c.length; i < options.coordLength; i++) {
46
+ data.push(0);
47
+ }
26
48
  }
27
- }
28
49
  }
29
-
50
+ /**
51
+ * Helper function to copy Polygon values from `coordinates` into `data` & `indices` & `areas`
52
+ *
53
+ * @param coordinates
54
+ * @param data
55
+ * @param indices
56
+ * @param areas
57
+ * @param options
58
+ */
30
59
  function flattenPolygon(coordinates, data, indices, areas, options) {
31
- let count = 0;
32
- const ringAreas = [];
33
- const polygons = [];
34
-
35
- for (const lineString of coordinates) {
36
- const lineString2d = lineString.map(p => p.slice(0, 2));
37
- let area = getPolygonSignedArea(lineString2d.flat());
38
- const ccw = area < 0;
39
-
40
- if (options.fixRingWinding && (count === 0 && !ccw || count > 0 && ccw)) {
41
- lineString.reverse();
42
- area = -area;
60
+ let count = 0;
61
+ const ringAreas = [];
62
+ const polygons = [];
63
+ for (const lineString of coordinates) {
64
+ const lineString2d = lineString.map((p) => p.slice(0, 2));
65
+ let area = (0, polygon_1.getPolygonSignedArea)(lineString2d.flat());
66
+ const ccw = area < 0;
67
+ // Exterior ring must be CCW and interior rings CW
68
+ if (options.fixRingWinding && ((count === 0 && !ccw) || (count > 0 && ccw))) {
69
+ lineString.reverse();
70
+ area = -area;
71
+ }
72
+ ringAreas.push(area);
73
+ flattenLineString(lineString, data, polygons, options);
74
+ count++;
75
+ }
76
+ if (count > 0) {
77
+ areas.push(ringAreas);
78
+ indices.push(polygons);
43
79
  }
44
-
45
- ringAreas.push(area);
46
- flattenLineString(lineString, data, polygons, options);
47
- count++;
48
- }
49
-
50
- if (count > 0) {
51
- areas.push(ringAreas);
52
- indices.push(polygons);
53
- }
54
80
  }
55
-
81
+ /**
82
+ * Flatten single GeoJSON feature into Flat GeoJSON
83
+ *
84
+ * @param feature
85
+ * @param options
86
+ * @returns A Flat GeoJSON feature
87
+ */
56
88
  function flattenFeature(feature, options) {
57
- const {
58
- geometry
59
- } = feature;
60
-
61
- if (geometry.type === 'GeometryCollection') {
62
- throw new Error('GeometryCollection type not supported');
63
- }
64
-
65
- const data = [];
66
- const indices = [];
67
- let areas;
68
- let type;
69
-
70
- switch (geometry.type) {
71
- case 'Point':
72
- type = 'Point';
73
- flattenPoint(geometry.coordinates, data, indices, options);
74
- break;
75
-
76
- case 'MultiPoint':
77
- type = 'Point';
78
- geometry.coordinates.map(c => flattenPoint(c, data, indices, options));
79
- break;
80
-
81
- case 'LineString':
82
- type = 'LineString';
83
- flattenLineString(geometry.coordinates, data, indices, options);
84
- break;
85
-
86
- case 'MultiLineString':
87
- type = 'LineString';
88
- geometry.coordinates.map(c => flattenLineString(c, data, indices, options));
89
- break;
90
-
91
- case 'Polygon':
92
- type = 'Polygon';
93
- areas = [];
94
- flattenPolygon(geometry.coordinates, data, indices, areas, options);
95
- break;
96
-
97
- case 'MultiPolygon':
98
- type = 'Polygon';
99
- areas = [];
100
- geometry.coordinates.map(c => flattenPolygon(c, data, indices, areas, options));
101
- break;
102
-
103
- default:
104
- throw new Error("Unknown type: ".concat(type));
105
- }
106
-
107
- return { ...feature,
108
- geometry: {
109
- type,
110
- indices,
111
- data,
112
- areas
89
+ const { geometry } = feature;
90
+ if (geometry.type === 'GeometryCollection') {
91
+ throw new Error('GeometryCollection type not supported');
92
+ }
93
+ const data = [];
94
+ const indices = [];
95
+ let areas;
96
+ let type;
97
+ switch (geometry.type) {
98
+ case 'Point':
99
+ type = 'Point';
100
+ flattenPoint(geometry.coordinates, data, indices, options);
101
+ break;
102
+ case 'MultiPoint':
103
+ type = 'Point';
104
+ geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));
105
+ break;
106
+ case 'LineString':
107
+ type = 'LineString';
108
+ flattenLineString(geometry.coordinates, data, indices, options);
109
+ break;
110
+ case 'MultiLineString':
111
+ type = 'LineString';
112
+ geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));
113
+ break;
114
+ case 'Polygon':
115
+ type = 'Polygon';
116
+ areas = [];
117
+ flattenPolygon(geometry.coordinates, data, indices, areas, options);
118
+ break;
119
+ case 'MultiPolygon':
120
+ type = 'Polygon';
121
+ areas = [];
122
+ geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));
123
+ break;
124
+ default:
125
+ throw new Error(`Unknown type: ${type}`);
113
126
  }
114
- };
127
+ return { ...feature, geometry: { type, indices, data, areas } };
115
128
  }
116
- //# sourceMappingURL=geojson-to-flat-geojson.js.map
@@ -1,5 +1,5 @@
1
1
  import type { BinaryFeatures } from '@loaders.gl/schema';
2
- declare type TransformCoordinate = (coord: number[]) => number[];
2
+ type TransformCoordinate = (coord: number[]) => number[];
3
3
  /**
4
4
  * Apply transformation to every coordinate of binary features
5
5
  * @param binaryFeatures binary features
@@ -1 +1 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/lib/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,EAAiB,MAAM,oBAAoB,CAAC;AAEvE,aAAK,mBAAmB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,cAAc,EAC9B,mBAAmB,EAAE,mBAAmB,GACvC,cAAc,CAWhB;AAcD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAAE,EAClB,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,GAChC,MAAM,EAAE,CAMV"}
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/lib/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,EAAiB,MAAM,oBAAoB,CAAC;AAEvE,KAAK,mBAAmB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,cAAc,EAC9B,mBAAmB,EAAE,mBAAmB,GACvC,cAAc,CAWhB;AAcD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAAE,EAClB,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,GAChC,MAAM,EAAE,CAMV"}
@@ -1,50 +1,59 @@
1
- export function transformBinaryCoords(binaryFeatures, transformCoordinate) {
2
- if (binaryFeatures.points) {
3
- transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);
4
- }
5
-
6
- if (binaryFeatures.lines) {
7
- transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);
8
- }
9
-
10
- if (binaryFeatures.polygons) {
11
- transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);
12
- }
13
-
14
- return binaryFeatures;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformGeoJsonCoords = exports.transformBinaryCoords = void 0;
4
+ /**
5
+ * Apply transformation to every coordinate of binary features
6
+ * @param binaryFeatures binary features
7
+ * @param transformCoordinate Function to call on each coordinate
8
+ * @return Transformed binary features
9
+ */
10
+ function transformBinaryCoords(binaryFeatures, transformCoordinate) {
11
+ if (binaryFeatures.points) {
12
+ transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);
13
+ }
14
+ if (binaryFeatures.lines) {
15
+ transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);
16
+ }
17
+ if (binaryFeatures.polygons) {
18
+ transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);
19
+ }
20
+ return binaryFeatures;
15
21
  }
16
-
22
+ exports.transformBinaryCoords = transformBinaryCoords;
23
+ /** Transform one binary geometry */
17
24
  function transformBinaryGeometryPositions(binaryGeometry, fn) {
18
- const {
19
- positions
20
- } = binaryGeometry;
21
-
22
- for (let i = 0; i < positions.value.length; i += positions.size) {
23
- const coord = Array.from(positions.value.subarray(i, i + positions.size));
24
- const transformedCoord = fn(coord);
25
- positions.value.set(transformedCoord, i);
26
- }
25
+ const { positions } = binaryGeometry;
26
+ for (let i = 0; i < positions.value.length; i += positions.size) {
27
+ // @ts-ignore inclusion of bigint causes problems
28
+ const coord = Array.from(positions.value.subarray(i, i + positions.size));
29
+ const transformedCoord = fn(coord);
30
+ // @ts-ignore typescript typing for .set seems to require bigint?
31
+ positions.value.set(transformedCoord, i);
32
+ }
27
33
  }
28
-
29
- export function transformGeoJsonCoords(features, fn) {
30
- for (const feature of features) {
31
- feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);
32
- }
33
-
34
- return features;
34
+ /**
35
+ * Apply transformation to every coordinate of GeoJSON features
36
+ *
37
+ * @param features Array of GeoJSON features
38
+ * @param fn Function to call on each coordinate
39
+ * @return Transformed GeoJSON features
40
+ */
41
+ function transformGeoJsonCoords(features, fn) {
42
+ for (const feature of features) {
43
+ // @ts-ignore
44
+ feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);
45
+ }
46
+ return features;
35
47
  }
36
-
48
+ exports.transformGeoJsonCoords = transformGeoJsonCoords;
37
49
  function coordMap(array, fn) {
38
- if (isCoord(array)) {
39
- return fn(array);
40
- }
41
-
42
- return array.map(item => {
43
- return coordMap(item, fn);
44
- });
50
+ if (isCoord(array)) {
51
+ return fn(array);
52
+ }
53
+ return array.map((item) => {
54
+ return coordMap(item, fn);
55
+ });
45
56
  }
46
-
47
57
  function isCoord(array) {
48
- return Number.isFinite(array[0]) && Number.isFinite(array[1]);
58
+ return Number.isFinite(array[0]) && Number.isFinite(array[1]);
49
59
  }
50
- //# sourceMappingURL=transform.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loaders.gl/gis",
3
3
  "description": "Helpers for GIS category data",
4
- "version": "4.0.0-alpha.5",
4
+ "version": "4.0.0-alpha.7",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -15,8 +15,8 @@
15
15
  "GeoJSON"
16
16
  ],
17
17
  "types": "dist/index.d.ts",
18
- "main": "dist/index.js",
19
- "module": "dist/index.js",
18
+ "main": "dist/es5/index.js",
19
+ "module": "dist/esm/index.js",
20
20
  "sideEffects": false,
21
21
  "files": [
22
22
  "src",
@@ -24,8 +24,8 @@
24
24
  "README.md"
25
25
  ],
26
26
  "dependencies": {
27
- "@loaders.gl/loader-utils": "4.0.0-alpha.5",
28
- "@loaders.gl/schema": "4.0.0-alpha.5",
27
+ "@loaders.gl/loader-utils": "4.0.0-alpha.7",
28
+ "@loaders.gl/schema": "4.0.0-alpha.7",
29
29
  "@mapbox/vector-tile": "^1.3.1",
30
30
  "@math.gl/polygon": "^3.5.1",
31
31
  "pbf": "^3.2.1"
@@ -33,5 +33,5 @@
33
33
  "devDependencies": {
34
34
  "@math.gl/proj4": "^3.5.1"
35
35
  },
36
- "gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
36
+ "gitHead": "afb59c4d8e5d8ebb9c28f111cb0c96c5527d0ffd"
37
37
  }
@@ -434,6 +434,7 @@ function triangulatePolygon(
434
434
  const holes = indices.slice(1).map((n: number) => (n - offset) / coordLength);
435
435
 
436
436
  // Compute triangulation
437
+ // @ts-expect-error TODO can earcut handle binary arrays? Add tests?
437
438
  const triangles = earcut(polygonPositions, holes, coordLength, areas);
438
439
 
439
440
  // Indices returned by triangulation are relative to start
@@ -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/index.js.map DELETED
@@ -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 +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,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iCI,CAAC,GAAG,CAACH,CAAC,GAAG,CAAL,IAAUhB,SAAS,CAACe,IAAzD,EAA+DI,CAAC,EAAhE,EAAoE;AAClEF,MAAAA,KAAK,CAAC5B,IAAN,CAAW+B,MAAM,CAACpB,SAAS,CAAC/B,KAAV,CAAgBkD,CAAhB,CAAD,CAAjB;AACD;;AACDV,IAAAA,eAAe,CAACpB,IAAhB,CAAqB4B,KAArB;AACD;;AACD,SAAOR,eAAP;AACD;;AAGD,SAAStB,SAAT,CAAmBlC,IAAnB,EAAyB;AACvB,MAAIA,IAAI,CAAC6D,WAAT,EAAsB;AACpB,WAAO,YAAP;AACD;;AAED,MAAI7D,IAAI,CAACgD,cAAT,EAAyB;AACvB,WAAO,SAAP;AACD;;AAED,SAAO,OAAP;AACD","sourcesContent":["import type {\n BinaryGeometry,\n BinaryFeatures,\n BinaryGeometryType,\n BinaryPointFeatures,\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 +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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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 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"flat-geojson-to-binary-types.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/lib/flat-geojson-to-binary.ts"],"names":["earcut","flatGeojsonToBinary","features","geometryInfo","options","propArrayTypes","extractNumericPropTypes","numericPropKeys","Object","keys","filter","k","Array","fillArrays","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","val","deduceArrayType","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLength","hasGlobalId","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","type","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","T","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","indices","start","end","l","ll","startPosition","areas","nextIndices","undefined","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","t","tl","wrapProps","obj","size","returnObj","value","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"mappings":"AACA,SAAQA,MAAR,QAAqB,kBAArB;AA0B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qC7B,IAArC,CAA0C2B,KAA1C,EAAiDC,KAAjD,EAAwDA,KAAK,GAAGtE,MAAhE;AACD;AACF;AACF;;AASD,SAASgC,oBAAT,CACEhD,UADF,EAEEwF,WAFF,EAGE;AACA,QAAMC,KAAK,GAAG,EAAd;;AACA,OAAK,MAAMxF,GAAX,IAAkBD,UAAlB,EAA8B;AAC5B,QAAI,CAACwF,WAAW,CAACE,QAAZ,CAAqBzF,GAArB,CAAL,EAAgC;AAC9BwF,MAAAA,KAAK,CAACxF,GAAD,CAAL,GAAaD,UAAU,CAACC,GAAD,CAAvB;AACD;AACF;;AACD,SAAOwF,KAAP;AACD;;AAUD,SAAStF,eAAT,CAAyBwF,CAAzB,EAAiCC,WAAjC,EAA0F;AACxF,MAAIA,WAAW,KAAKlG,KAAhB,IAAyB,CAACmG,MAAM,CAACC,QAAP,CAAgBH,CAAhB,CAA9B,EAAkD;AAChD,WAAOjG,KAAP;AACD;;AAGD,SAAOkG,WAAW,KAAKG,YAAhB,IAAgCC,IAAI,CAACC,MAAL,CAAYN,CAAZ,MAAmBA,CAAnD,GAAuDI,YAAvD,GAAsElG,YAA7E;AACD","sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport type {\n BinaryAttribute,\n BinaryFeatures,\n FlatFeature,\n FlatPoint,\n FlatLineString,\n FlatPolygon,\n GeojsonGeometryInfo,\n TypedArray\n} from '@loaders.gl/schema';\nimport {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-binary-types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param geometryInfo\n * @param options\n * @returns filled arrays\n */\nexport function flatGeojsonToBinary(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo,\n options?: FlatGeojsonToBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(\n features,\n {\n propArrayTypes,\n ...geometryInfo\n },\n {\n numericPropKeys: (options && options.numericPropKeys) || numericPropKeys,\n PositionDataType: options ? options.PositionDataType : Float32Array\n }\n );\n}\n\n/**\n * Options for `flatGeojsonToBinary`\n */\nexport type FlatGeojsonToBinaryOptions = {\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\nexport const TEST_EXPORTS = {\n extractNumericPropTypes\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: FlatFeature[]): {\n [key: string]: PropArrayConstructor;\n} {\n const propArrayTypes = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, Array is stored to prevent rechecking in the future\n // Additionally, detects if 64 bit precision is required\n const val = feature.properties[key];\n propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);\n }\n }\n }\n\n return propArrayTypes;\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param geometryInfo\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo & {\n propArrayTypes: {[key: string]: PropArrayConstructor};\n },\n options: FlatGeojsonToBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount,\n propArrayTypes,\n coordLength\n } = geometryInfo;\n const {numericPropKeys = [], PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: Points = {\n type: 'Point',\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: Lines = {\n type: 'LineString',\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: Polygons = {\n type: 'Polygon',\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n const T = propArrayTypes[propName];\n object.numericProps[propName] = new T(object.positions.length / coordLength) as TypedArray;\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: FlatPoint,\n points: Points,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: FlatLineString,\n lines: Lines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.indices.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.indices[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.indices[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: FlatPolygon,\n polygons: Polygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.indices is a 2D array\n for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas[l];\n const indices = geometry.indices[l];\n const nextIndices = geometry.indices[l + 1];\n\n for (let i = 0, il = indices.length; i < il; ++i) {\n const start = indices[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextIndices === undefined\n ? geometry.data.length // end of data (no next indices)\n : nextIndices[0] // start of first line in nextIndices\n : indices[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, indices, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param indices\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: Polygons,\n areas: number[],\n indices: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = indices[0];\n const holes = indices.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const triangles = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = triangles.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + triangles[t]);\n }\n}\n\n/**\n * Wraps an object containing array into accessors\n *\n * @param obj\n * @param size\n */\nfunction wrapProps(\n obj: {[key: string]: TypedArray},\n size: number\n): {[key: string]: BinaryAttribute} {\n const returnObj = {};\n for (const key in obj) {\n returnObj[key] = {value: obj[key], size};\n }\n return returnObj;\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: Points,\n lines: Lines,\n polygons: Polygons,\n coordLength: number\n): BinaryFeatures {\n return {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1},\n numericProps: wrapProps(points.numericProps, 1)\n },\n lines: {\n ...lines,\n positions: {value: lines.positions, size: coordLength},\n pathIndices: {value: lines.pathIndices, size: 1},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1},\n numericProps: wrapProps(lines.numericProps, 1)\n },\n polygons: {\n ...polygons,\n positions: {value: polygons.positions, size: coordLength},\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1},\n numericProps: wrapProps(polygons.numericProps, 1)\n }\n };\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: Points | Lines | Polygons,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n const value = properties[numericPropName] as number;\n object.numericProps[numericPropName].fill(value, index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\n/**\n *\n * Deduce correct array constructor to use for a given value\n *\n * @param x value to test\n * @param constructor previous constructor deduced\n * @returns PropArrayConstructor\n */\nfunction deduceArrayType(x: any, constructor: PropArrayConstructor): PropArrayConstructor {\n if (constructor === Array || !Number.isFinite(x)) {\n return Array;\n }\n\n // If this or previous value required 64bits use Float64Array\n return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;\n}\n"],"file":"flat-geojson-to-binary.js"}