@loaders.gl/gis 4.0.0-alpha.4 → 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 (37) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/index.d.ts +6 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +2 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/lib/binary-to-geojson.d.ts +21 -0
  8. package/dist/lib/binary-to-geojson.d.ts.map +1 -0
  9. package/dist/lib/extract-geometry-info.d.ts +8 -0
  10. package/dist/lib/extract-geometry-info.d.ts.map +1 -0
  11. package/dist/lib/extract-geometry-info.js +105 -0
  12. package/dist/lib/extract-geometry-info.js.map +1 -0
  13. package/dist/lib/flat-geojson-to-binary-types.d.ts +58 -0
  14. package/dist/lib/flat-geojson-to-binary-types.d.ts.map +1 -0
  15. package/dist/lib/flat-geojson-to-binary-types.js +2 -0
  16. package/dist/lib/flat-geojson-to-binary-types.js.map +1 -0
  17. package/dist/lib/flat-geojson-to-binary.d.ts +37 -0
  18. package/dist/lib/flat-geojson-to-binary.d.ts.map +1 -0
  19. package/dist/lib/flat-geojson-to-binary.js +339 -0
  20. package/dist/lib/flat-geojson-to-binary.js.map +1 -0
  21. package/dist/lib/geojson-to-binary.d.ts +19 -0
  22. package/dist/lib/geojson-to-binary.d.ts.map +1 -0
  23. package/dist/lib/geojson-to-binary.js +17 -403
  24. package/dist/lib/geojson-to-binary.js.map +1 -1
  25. package/dist/lib/geojson-to-flat-geojson.d.ts +17 -0
  26. package/dist/lib/geojson-to-flat-geojson.d.ts.map +1 -0
  27. package/dist/lib/geojson-to-flat-geojson.js +116 -0
  28. package/dist/lib/geojson-to-flat-geojson.js.map +1 -0
  29. package/dist/lib/transform.d.ts +19 -0
  30. package/dist/lib/transform.d.ts.map +1 -0
  31. package/package.json +6 -5
  32. package/src/index.ts +2 -0
  33. package/src/lib/extract-geometry-info.ts +101 -0
  34. package/src/lib/flat-geojson-to-binary-types.ts +58 -0
  35. package/src/lib/flat-geojson-to-binary.ts +564 -0
  36. package/src/lib/geojson-to-binary.ts +24 -450
  37. package/src/lib/geojson-to-flat-geojson.ts +171 -0
@@ -0,0 +1,2 @@
1
+ declare const moduleExports: any;
2
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
@@ -0,0 +1,6 @@
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.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAC,oBAAoB,EAAC,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAC,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAC,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAC,qBAAqB,EAAE,sBAAsB,EAAC,MAAM,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
+ export { flatGeojsonToBinary } from './lib/flat-geojson-to-binary';
1
2
  export { geojsonToBinary } from './lib/geojson-to-binary';
3
+ export { geojsonToFlatGeojson } from './lib/geojson-to-flat-geojson';
2
4
  export { binaryToGeojson, binaryToGeoJson, binaryToGeometry } from './lib/binary-to-geojson';
3
5
  export { transformBinaryCoords, transformGeoJsonCoords } from './lib/transform';
4
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["geojsonToBinary","binaryToGeojson","binaryToGeoJson","binaryToGeometry","transformBinaryCoords","transformGeoJsonCoords"],"mappings":"AAGA,SAAQA,eAAR,QAA8B,yBAA9B;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 {geojsonToBinary} from './lib/geojson-to-binary';\nexport {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"file":"index.js"}
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"}
@@ -0,0 +1,21 @@
1
+ import type { BinaryGeometry, BinaryFeatures, BinaryGeometryType } from '@loaders.gl/schema';
2
+ import type { Feature, Geometry } from '@loaders.gl/schema';
3
+ declare type BinaryToGeoJsonOptions = {
4
+ type?: BinaryGeometryType;
5
+ globalFeatureId?: number;
6
+ };
7
+ /**
8
+ * Convert binary geometry representation to GeoJSON
9
+ * @param data geometry data in binary representation
10
+ * @param options
11
+ * @param options.type Input data type: Point, LineString, or Polygon
12
+ * @param options.featureId Global feature id. If specified, only a single feature is extracted
13
+ * @return GeoJSON objects
14
+ */
15
+ export declare function binaryToGeojson(data: BinaryFeatures, options?: BinaryToGeoJsonOptions): Feature[] | Feature;
16
+ /** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead */
17
+ export declare function binaryToGeoJson(data: BinaryGeometry | BinaryFeatures, type?: BinaryGeometryType, format?: 'feature' | 'geometry'): Geometry | Feature[];
18
+ /** Parse input binary data and return a valid GeoJSON geometry object */
19
+ export declare function binaryToGeometry(data: BinaryGeometry, startIndex?: number, endIndex?: number): Geometry;
20
+ export {};
21
+ //# sourceMappingURL=binary-to-geojson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-to-geojson.d.ts","sourceRoot":"","sources":["../../src/lib/binary-to-geojson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,kBAAkB,EAKnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAC,OAAO,EAAE,QAAQ,EAA8B,MAAM,oBAAoB,CAAC;AAavF,aAAK,sBAAsB,GAAG;IAC5B,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,EAAE,GAAG,OAAO,CAMrB;AAED,sEAAsE;AACtE,wBAAgB,eAAe,CAC7B,IAAI,EAAE,cAAc,GAAG,cAAc,EACrC,IAAI,CAAC,EAAE,kBAAkB,EACzB,MAAM,GAAE,SAAS,GAAG,UAAsB,GACzC,QAAQ,GAAG,OAAO,EAAE,CAStB;AAwCD,yEAAyE;AACzE,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,cAAc,EACpB,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,GAChB,QAAQ,CAYV"}
@@ -0,0 +1,8 @@
1
+ import { Feature, GeojsonGeometryInfo } from '@loaders.gl/schema';
2
+ /**
3
+ * Initial scan over GeoJSON features
4
+ * Counts number of coordinates of each geometry type and
5
+ * keeps track of the max coordinate dimensions
6
+ */
7
+ export declare function extractGeometryInfo(features: Feature[]): GeojsonGeometryInfo;
8
+ //# sourceMappingURL=extract-geometry-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-geometry-info.d.ts","sourceRoot":"","sources":["../../src/lib/extract-geometry-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAEhE;;;;GAIG;AAEH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,mBAAmB,CA4F5E"}
@@ -0,0 +1,105 @@
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
@@ -0,0 +1 @@
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":"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","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"}
@@ -0,0 +1,58 @@
1
+ import type { TypedArray } from '@loaders.gl/schema';
2
+ /**
3
+ * Permissable constructor for numeric props
4
+ */
5
+ export declare type PropArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor | ArrayConstructor;
6
+ /**
7
+ * Collection type for holding intermediate binary data before conversion to `BinaryPointGeometry`
8
+ */
9
+ export declare type Points = {
10
+ type: 'Point';
11
+ positions: Float32Array | Float64Array;
12
+ globalFeatureIds: Uint16Array | Uint32Array;
13
+ featureIds: Uint16Array | Uint32Array;
14
+ numericProps: {
15
+ [key: string]: TypedArray;
16
+ };
17
+ properties: {}[];
18
+ fields: {
19
+ id?: string | number;
20
+ }[];
21
+ };
22
+ /**
23
+ * Collection type for holding intermediate binary data before conversion to `BinaryLineStringGeometry`
24
+ */
25
+ export declare type Lines = {
26
+ type: 'LineString';
27
+ positions: Float32Array | Float64Array;
28
+ pathIndices: Uint16Array | Uint32Array;
29
+ globalFeatureIds: Uint16Array | Uint32Array;
30
+ featureIds: Uint16Array | Uint32Array;
31
+ numericProps: {
32
+ [key: string]: TypedArray;
33
+ };
34
+ properties: {}[];
35
+ fields: {
36
+ id?: string | number;
37
+ }[];
38
+ };
39
+ /**
40
+ * Collection type for holding intermediate binary data before conversion to `BinaryPolygonGeometry`
41
+ */
42
+ export declare type Polygons = {
43
+ type: 'Polygon';
44
+ positions: Float32Array | Float64Array;
45
+ polygonIndices: Uint16Array | Uint32Array;
46
+ primitivePolygonIndices: Uint16Array | Uint32Array;
47
+ triangles: number[];
48
+ globalFeatureIds: Uint16Array | Uint32Array;
49
+ featureIds: Uint16Array | Uint32Array;
50
+ numericProps: {
51
+ [key: string]: TypedArray;
52
+ };
53
+ properties: {}[];
54
+ fields: {
55
+ id?: string | number;
56
+ }[];
57
+ };
58
+ //# sourceMappingURL=flat-geojson-to-binary-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flat-geojson-to-binary-types.d.ts","sourceRoot":"","sources":["../../src/lib/flat-geojson-to-binary-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,oBAAY,oBAAoB,GAC5B,uBAAuB,GACvB,uBAAuB,GACvB,gBAAgB,CAAC;AAErB;;GAEG;AACH,oBAAY,MAAM,GAAG;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,YAAY,GAAG,YAAY,CAAC;IACvC,gBAAgB,EAAE,WAAW,GAAG,WAAW,CAAC;IAC5C,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC;IACtC,YAAY,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;KAAC,CAAC;IAC1C,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,MAAM,EAAE;QACN,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;KACtB,EAAE,CAAC;CACL,CAAC;AAEF;;GAEG;AACH,oBAAY,KAAK,GAAG;IAClB,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,YAAY,GAAG,YAAY,CAAC;IACvC,WAAW,EAAE,WAAW,GAAG,WAAW,CAAC;IACvC,gBAAgB,EAAE,WAAW,GAAG,WAAW,CAAC;IAC5C,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC;IACtC,YAAY,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;KAAC,CAAC;IAC1C,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,MAAM,EAAE;QACN,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;KACtB,EAAE,CAAC;CACL,CAAC;AAEF;;GAEG;AACH,oBAAY,QAAQ,GAAG;IACrB,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,EAAE,YAAY,GAAG,YAAY,CAAC;IACvC,cAAc,EAAE,WAAW,GAAG,WAAW,CAAC;IAC1C,uBAAuB,EAAE,WAAW,GAAG,WAAW,CAAC;IACnD,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,gBAAgB,EAAE,WAAW,GAAG,WAAW,CAAC;IAC5C,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC;IACtC,YAAY,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;KAAC,CAAC;IAC1C,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,MAAM,EAAE;QACN,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;KACtB,EAAE,CAAC;CACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=flat-geojson-to-binary-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"flat-geojson-to-binary-types.js"}
@@ -0,0 +1,37 @@
1
+ import type { BinaryFeatures, FlatFeature, GeojsonGeometryInfo } from '@loaders.gl/schema';
2
+ import { PropArrayConstructor } from './flat-geojson-to-binary-types';
3
+ /**
4
+ * Convert binary features to flat binary arrays. Similar to
5
+ * `geojsonToBinary` helper function, except that it expects
6
+ * a binary representation of the feature data, which enables
7
+ * 2X-3X speed increase in parse speed, compared to using
8
+ * geoJSON. See `binary-vector-tile/VectorTileFeature` for
9
+ * data format detais
10
+ *
11
+ * @param features
12
+ * @param geometryInfo
13
+ * @param options
14
+ * @returns filled arrays
15
+ */
16
+ export declare function flatGeojsonToBinary(features: FlatFeature[], geometryInfo: GeojsonGeometryInfo, options?: FlatGeojsonToBinaryOptions): BinaryFeatures;
17
+ /**
18
+ * Options for `flatGeojsonToBinary`
19
+ */
20
+ export declare type FlatGeojsonToBinaryOptions = {
21
+ numericPropKeys?: string[];
22
+ PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;
23
+ };
24
+ export declare const TEST_EXPORTS: {
25
+ extractNumericPropTypes: typeof extractNumericPropTypes;
26
+ };
27
+ /**
28
+ * Extracts properties that are always numeric
29
+ *
30
+ * @param features
31
+ * @returns object with numeric types
32
+ */
33
+ declare function extractNumericPropTypes(features: FlatFeature[]): {
34
+ [key: string]: PropArrayConstructor;
35
+ };
36
+ export {};
37
+ //# sourceMappingURL=flat-geojson-to-binary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flat-geojson-to-binary.d.ts","sourceRoot":"","sources":["../../src/lib/flat-geojson-to-binary.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,cAAc,EACd,WAAW,EAIX,mBAAmB,EAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,oBAAoB,EAA0B,MAAM,gCAAgC,CAAC;AAE7F;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,WAAW,EAAE,EACvB,YAAY,EAAE,mBAAmB,EACjC,OAAO,CAAC,EAAE,0BAA0B,kBAerC;AAED;;GAEG;AACH,oBAAY,0BAA0B,GAAG;IACvC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,uBAAuB,GAAG,uBAAuB,CAAC;CACtE,CAAC;AAEF,eAAO,MAAM,YAAY;;CAExB,CAAC;AAEF;;;;;GAKG;AACH,iBAAS,uBAAuB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG;IACzD,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB,CAAC;CACrC,CAgBA"}
@@ -0,0 +1,339 @@
1
+ import { earcut } from '@math.gl/polygon';
2
+ export function flatGeojsonToBinary(features, geometryInfo, options) {
3
+ const propArrayTypes = extractNumericPropTypes(features);
4
+ const numericPropKeys = Object.keys(propArrayTypes).filter(k => propArrayTypes[k] !== Array);
5
+ return fillArrays(features, {
6
+ propArrayTypes,
7
+ ...geometryInfo
8
+ }, {
9
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
10
+ PositionDataType: options ? options.PositionDataType : Float32Array
11
+ });
12
+ }
13
+ export const TEST_EXPORTS = {
14
+ extractNumericPropTypes
15
+ };
16
+
17
+ function extractNumericPropTypes(features) {
18
+ const propArrayTypes = {};
19
+
20
+ for (const feature of features) {
21
+ if (feature.properties) {
22
+ for (const key in feature.properties) {
23
+ const val = feature.properties[key];
24
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
25
+ }
26
+ }
27
+ }
28
+
29
+ return propArrayTypes;
30
+ }
31
+
32
+ function fillArrays(features, geometryInfo, options) {
33
+ const {
34
+ pointPositionsCount,
35
+ pointFeaturesCount,
36
+ linePositionsCount,
37
+ linePathsCount,
38
+ lineFeaturesCount,
39
+ polygonPositionsCount,
40
+ polygonObjectsCount,
41
+ polygonRingsCount,
42
+ polygonFeaturesCount,
43
+ propArrayTypes,
44
+ coordLength
45
+ } = geometryInfo;
46
+ const {
47
+ numericPropKeys = [],
48
+ PositionDataType = Float32Array
49
+ } = options;
50
+ const hasGlobalId = features[0] && 'id' in features[0];
51
+ const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
52
+ const points = {
53
+ type: 'Point',
54
+ positions: new PositionDataType(pointPositionsCount * coordLength),
55
+ globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
56
+ featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
57
+ numericProps: {},
58
+ properties: [],
59
+ fields: []
60
+ };
61
+ const lines = {
62
+ type: 'LineString',
63
+ pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
64
+ positions: new PositionDataType(linePositionsCount * coordLength),
65
+ globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
66
+ featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
67
+ numericProps: {},
68
+ properties: [],
69
+ fields: []
70
+ };
71
+ const polygons = {
72
+ type: 'Polygon',
73
+ polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
74
+ primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
75
+ positions: new PositionDataType(polygonPositionsCount * coordLength),
76
+ triangles: [],
77
+ globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
78
+ featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
79
+ numericProps: {},
80
+ properties: [],
81
+ fields: []
82
+ };
83
+
84
+ for (const object of [points, lines, polygons]) {
85
+ for (const propName of numericPropKeys) {
86
+ const T = propArrayTypes[propName];
87
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
88
+ }
89
+ }
90
+
91
+ lines.pathIndices[linePathsCount] = linePositionsCount;
92
+ polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
93
+ polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
94
+ const indexMap = {
95
+ pointPosition: 0,
96
+ pointFeature: 0,
97
+ linePosition: 0,
98
+ linePath: 0,
99
+ lineFeature: 0,
100
+ polygonPosition: 0,
101
+ polygonObject: 0,
102
+ polygonRing: 0,
103
+ polygonFeature: 0,
104
+ feature: 0
105
+ };
106
+
107
+ for (const feature of features) {
108
+ const geometry = feature.geometry;
109
+ const properties = feature.properties || {};
110
+
111
+ switch (geometry.type) {
112
+ case 'Point':
113
+ handlePoint(geometry, points, indexMap, coordLength, properties);
114
+ points.properties.push(keepStringProperties(properties, numericPropKeys));
115
+
116
+ if (hasGlobalId) {
117
+ points.fields.push({
118
+ id: feature.id
119
+ });
120
+ }
121
+
122
+ indexMap.pointFeature++;
123
+ break;
124
+
125
+ case 'LineString':
126
+ handleLineString(geometry, lines, indexMap, coordLength, properties);
127
+ lines.properties.push(keepStringProperties(properties, numericPropKeys));
128
+
129
+ if (hasGlobalId) {
130
+ lines.fields.push({
131
+ id: feature.id
132
+ });
133
+ }
134
+
135
+ indexMap.lineFeature++;
136
+ break;
137
+
138
+ case 'Polygon':
139
+ handlePolygon(geometry, polygons, indexMap, coordLength, properties);
140
+ polygons.properties.push(keepStringProperties(properties, numericPropKeys));
141
+
142
+ if (hasGlobalId) {
143
+ polygons.fields.push({
144
+ id: feature.id
145
+ });
146
+ }
147
+
148
+ indexMap.polygonFeature++;
149
+ break;
150
+
151
+ default:
152
+ throw new Error('Invalid geometry type');
153
+ }
154
+
155
+ indexMap.feature++;
156
+ }
157
+
158
+ return makeAccessorObjects(points, lines, polygons, coordLength);
159
+ }
160
+
161
+ function handlePoint(geometry, points, indexMap, coordLength, properties) {
162
+ points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
163
+ const nPositions = geometry.data.length / coordLength;
164
+ fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
165
+ points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
166
+ points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
167
+ indexMap.pointPosition += nPositions;
168
+ }
169
+
170
+ function handleLineString(geometry, lines, indexMap, coordLength, properties) {
171
+ lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
172
+ const nPositions = geometry.data.length / coordLength;
173
+ fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
174
+ lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
175
+ lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
176
+
177
+ for (let i = 0, il = geometry.indices.length; i < il; ++i) {
178
+ const start = geometry.indices[i];
179
+ const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
180
+ lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
181
+ indexMap.linePosition += (end - start) / coordLength;
182
+ }
183
+ }
184
+
185
+ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
186
+ polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
187
+ const nPositions = geometry.data.length / coordLength;
188
+ fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
189
+ polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
190
+ polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
191
+
192
+ for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
193
+ const startPosition = indexMap.polygonPosition;
194
+ polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
195
+ const areas = geometry.areas[l];
196
+ const indices = geometry.indices[l];
197
+ const nextIndices = geometry.indices[l + 1];
198
+
199
+ for (let i = 0, il = indices.length; i < il; ++i) {
200
+ const start = indices[i];
201
+ const end = i === il - 1 ? nextIndices === undefined ? geometry.data.length : nextIndices[0] : indices[i + 1];
202
+ polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
203
+ indexMap.polygonPosition += (end - start) / coordLength;
204
+ }
205
+
206
+ const endPosition = indexMap.polygonPosition;
207
+ triangulatePolygon(polygons, areas, indices, {
208
+ startPosition,
209
+ endPosition,
210
+ coordLength
211
+ });
212
+ }
213
+ }
214
+
215
+ function triangulatePolygon(polygons, areas, indices, {
216
+ startPosition,
217
+ endPosition,
218
+ coordLength
219
+ }) {
220
+ const start = startPosition * coordLength;
221
+ const end = endPosition * coordLength;
222
+ const polygonPositions = polygons.positions.subarray(start, end);
223
+ const offset = indices[0];
224
+ const holes = indices.slice(1).map(n => (n - offset) / coordLength);
225
+ const triangles = earcut(polygonPositions, holes, coordLength, areas);
226
+
227
+ for (let t = 0, tl = triangles.length; t < tl; ++t) {
228
+ polygons.triangles.push(startPosition + triangles[t]);
229
+ }
230
+ }
231
+
232
+ function wrapProps(obj, size) {
233
+ const returnObj = {};
234
+
235
+ for (const key in obj) {
236
+ returnObj[key] = {
237
+ value: obj[key],
238
+ size
239
+ };
240
+ }
241
+
242
+ return returnObj;
243
+ }
244
+
245
+ function makeAccessorObjects(points, lines, polygons, coordLength) {
246
+ return {
247
+ points: { ...points,
248
+ positions: {
249
+ value: points.positions,
250
+ size: coordLength
251
+ },
252
+ globalFeatureIds: {
253
+ value: points.globalFeatureIds,
254
+ size: 1
255
+ },
256
+ featureIds: {
257
+ value: points.featureIds,
258
+ size: 1
259
+ },
260
+ numericProps: wrapProps(points.numericProps, 1)
261
+ },
262
+ lines: { ...lines,
263
+ positions: {
264
+ value: lines.positions,
265
+ size: coordLength
266
+ },
267
+ pathIndices: {
268
+ value: lines.pathIndices,
269
+ size: 1
270
+ },
271
+ globalFeatureIds: {
272
+ value: lines.globalFeatureIds,
273
+ size: 1
274
+ },
275
+ featureIds: {
276
+ value: lines.featureIds,
277
+ size: 1
278
+ },
279
+ numericProps: wrapProps(lines.numericProps, 1)
280
+ },
281
+ polygons: { ...polygons,
282
+ positions: {
283
+ value: polygons.positions,
284
+ size: coordLength
285
+ },
286
+ polygonIndices: {
287
+ value: polygons.polygonIndices,
288
+ size: 1
289
+ },
290
+ primitivePolygonIndices: {
291
+ value: polygons.primitivePolygonIndices,
292
+ size: 1
293
+ },
294
+ triangles: {
295
+ value: new Uint32Array(polygons.triangles),
296
+ size: 1
297
+ },
298
+ globalFeatureIds: {
299
+ value: polygons.globalFeatureIds,
300
+ size: 1
301
+ },
302
+ featureIds: {
303
+ value: polygons.featureIds,
304
+ size: 1
305
+ },
306
+ numericProps: wrapProps(polygons.numericProps, 1)
307
+ }
308
+ };
309
+ }
310
+
311
+ function fillNumericProperties(object, properties, index, length) {
312
+ for (const numericPropName in object.numericProps) {
313
+ if (numericPropName in properties) {
314
+ const value = properties[numericPropName];
315
+ object.numericProps[numericPropName].fill(value, index, index + length);
316
+ }
317
+ }
318
+ }
319
+
320
+ function keepStringProperties(properties, numericKeys) {
321
+ const props = {};
322
+
323
+ for (const key in properties) {
324
+ if (!numericKeys.includes(key)) {
325
+ props[key] = properties[key];
326
+ }
327
+ }
328
+
329
+ return props;
330
+ }
331
+
332
+ function deduceArrayType(x, constructor) {
333
+ if (constructor === Array || !Number.isFinite(x)) {
334
+ return Array;
335
+ }
336
+
337
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
338
+ }
339
+ //# sourceMappingURL=flat-geojson-to-binary.js.map