@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,116 @@
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));
7
+ }
8
+
9
+ 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
+ }
16
+ }
17
+
18
+ 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);
26
+ }
27
+ }
28
+ }
29
+
30
+ 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;
43
+ }
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
+ }
55
+
56
+ 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
113
+ }
114
+ };
115
+ }
116
+ //# sourceMappingURL=geojson-to-flat-geojson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/geojson-to-flat-geojson.ts"],"names":["getPolygonSignedArea","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,SAAQA,oBAAR,QAAmC,kBAAnC;AA0BA,OAAO,SAASC,oBAAT,CACLC,QADK,EAELC,OAAoC,GAAG;AAACC,EAAAA,WAAW,EAAE,CAAd;AAAiBC,EAAAA,cAAc,EAAE;AAAjC,CAFlC,EAGU;AACf,SAAOH,QAAQ,CAACI,GAAT,CAAcC,OAAD,IAAaC,cAAc,CAACD,OAAD,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C,OAAV,EAAmBT,OAAnB,CAA5C;AACA;;AACF,SAAK,YAAL;AACE6B,MAAAA,IAAI,GAAG,YAAP;AACAhB,MAAAA,iBAAiB,CAACe,QAAQ,CAACrB,WAAV,EAAuBC,IAAvB,EAA6BC,OAA7B,EAAsCT,OAAtC,CAAjB;AACA;;AACF,SAAK,iBAAL;AACE6B,MAAAA,IAAI,GAAG,YAAP;AACAD,MAAAA,QAAQ,CAACrB,WAAT,CAAqBJ,GAArB,CAA0BW,CAAD,IAAOD,iBAAiB,CAACC,CAAD,EAAIN,IAAJ,EAAUC,OAAV,EAAmBT,OAAnB,CAAjD;AACA;;AACF,SAAK,SAAL;AACE6B,MAAAA,IAAI,GAAG,SAAP;AACAb,MAAAA,KAAK,GAAG,EAAR;AACAD,MAAAA,cAAc,CAACa,QAAQ,CAACrB,WAAV,EAAuBC,IAAvB,EAA6BC,OAA7B,EAAsCO,KAAtC,EAA6ChB,OAA7C,CAAd;AACA;;AACF,SAAK,cAAL;AACE6B,MAAAA,IAAI,GAAG,SAAP;AACAb,MAAAA,KAAK,GAAG,EAAR;AACAY,MAAAA,QAAQ,CAACrB,WAAT,CAAqBJ,GAArB,CAA0BW,CAAD,IAAOC,cAAc,CAACD,CAAD,EAAIN,IAAJ,EAAUC,OAAV,EAAmBO,KAAnB,EAA0BhB,OAA1B,CAA9C;AACA;;AACF;AACE,YAAM,IAAI8B,KAAJ,yBAA2BD,IAA3B,EAAN;AA5BJ;;AA+BA,SAAO,EAAC,GAAGzB,OAAJ;AAAawB,IAAAA,QAAQ,EAAE;AAACC,MAAAA,IAAD;AAAOpB,MAAAA,OAAP;AAAgBD,MAAAA,IAAhB;AAAsBQ,MAAAA;AAAtB;AAAvB,GAAP;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"}
@@ -0,0 +1,19 @@
1
+ import type { BinaryFeatures } from '@loaders.gl/schema';
2
+ declare type TransformCoordinate = (coord: number[]) => number[];
3
+ /**
4
+ * Apply transformation to every coordinate of binary features
5
+ * @param binaryFeatures binary features
6
+ * @param transformCoordinate Function to call on each coordinate
7
+ * @return Transformed binary features
8
+ */
9
+ export declare function transformBinaryCoords(binaryFeatures: BinaryFeatures, transformCoordinate: TransformCoordinate): BinaryFeatures;
10
+ /**
11
+ * Apply transformation to every coordinate of GeoJSON features
12
+ *
13
+ * @param features Array of GeoJSON features
14
+ * @param fn Function to call on each coordinate
15
+ * @return Transformed GeoJSON features
16
+ */
17
+ export declare function transformGeoJsonCoords(features: object[], fn: (coord: number[]) => number[]): object[];
18
+ export {};
19
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +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"}
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.4",
4
+ "version": "4.0.0-alpha.5",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -14,7 +14,7 @@
14
14
  "geometry",
15
15
  "GeoJSON"
16
16
  ],
17
- "types": "src/index.ts",
17
+ "types": "dist/index.d.ts",
18
18
  "main": "dist/index.js",
19
19
  "module": "dist/index.js",
20
20
  "sideEffects": false,
@@ -24,13 +24,14 @@
24
24
  "README.md"
25
25
  ],
26
26
  "dependencies": {
27
- "@loaders.gl/loader-utils": "4.0.0-alpha.4",
28
- "@loaders.gl/schema": "4.0.0-alpha.4",
27
+ "@loaders.gl/loader-utils": "4.0.0-alpha.5",
28
+ "@loaders.gl/schema": "4.0.0-alpha.5",
29
29
  "@mapbox/vector-tile": "^1.3.1",
30
+ "@math.gl/polygon": "^3.5.1",
30
31
  "pbf": "^3.2.1"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@math.gl/proj4": "^3.5.1"
34
35
  },
35
- "gitHead": "53026061b3c8871f7e96d3a5826125cc6613bddc"
36
+ "gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
36
37
  }
package/src/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  // Types from `@loaders.gl/schema`
2
2
 
3
3
  // Functions
4
+ export {flatGeojsonToBinary} from './lib/flat-geojson-to-binary';
4
5
  export {geojsonToBinary} from './lib/geojson-to-binary';
6
+ export {geojsonToFlatGeojson} from './lib/geojson-to-flat-geojson';
5
7
  export {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';
6
8
  export {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';
@@ -0,0 +1,101 @@
1
+ import {Feature, GeojsonGeometryInfo} from '@loaders.gl/schema';
2
+
3
+ /**
4
+ * Initial scan over GeoJSON features
5
+ * Counts number of coordinates of each geometry type and
6
+ * keeps track of the max coordinate dimensions
7
+ */
8
+ // eslint-disable-next-line complexity, max-statements
9
+ export function extractGeometryInfo(features: Feature[]): GeojsonGeometryInfo {
10
+ // Counts the number of _positions_, so [x, y, z] counts as one
11
+ let pointPositionsCount = 0;
12
+ let pointFeaturesCount = 0;
13
+ let linePositionsCount = 0;
14
+ let linePathsCount = 0;
15
+ let lineFeaturesCount = 0;
16
+ let polygonPositionsCount = 0;
17
+ let polygonObjectsCount = 0;
18
+ let polygonRingsCount = 0;
19
+ let polygonFeaturesCount = 0;
20
+ const coordLengths = new Set<number>();
21
+
22
+ for (const feature of features) {
23
+ const geometry = feature.geometry;
24
+ switch (geometry.type) {
25
+ case 'Point':
26
+ pointFeaturesCount++;
27
+ pointPositionsCount++;
28
+ coordLengths.add(geometry.coordinates.length);
29
+ break;
30
+ case 'MultiPoint':
31
+ pointFeaturesCount++;
32
+ pointPositionsCount += geometry.coordinates.length;
33
+ for (const point of geometry.coordinates) {
34
+ coordLengths.add(point.length);
35
+ }
36
+ break;
37
+ case 'LineString':
38
+ lineFeaturesCount++;
39
+ linePositionsCount += geometry.coordinates.length;
40
+ linePathsCount++;
41
+
42
+ for (const coord of geometry.coordinates) {
43
+ coordLengths.add(coord.length);
44
+ }
45
+ break;
46
+ case 'MultiLineString':
47
+ lineFeaturesCount++;
48
+ for (const line of geometry.coordinates) {
49
+ linePositionsCount += line.length;
50
+ linePathsCount++;
51
+
52
+ // eslint-disable-next-line max-depth
53
+ for (const coord of line) {
54
+ coordLengths.add(coord.length);
55
+ }
56
+ }
57
+ break;
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
+ break;
69
+ case 'MultiPolygon':
70
+ polygonFeaturesCount++;
71
+ for (const polygon of geometry.coordinates) {
72
+ polygonObjectsCount++;
73
+ polygonRingsCount += polygon.length;
74
+ const flattened = polygon.flat();
75
+ polygonPositionsCount += flattened.length;
76
+
77
+ // eslint-disable-next-line max-depth
78
+ for (const coord of flattened) {
79
+ coordLengths.add(coord.length);
80
+ }
81
+ }
82
+ break;
83
+ default:
84
+ throw new Error(`Unsupported geometry type: ${geometry.type}`);
85
+ }
86
+ }
87
+
88
+ return {
89
+ coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
90
+
91
+ pointPositionsCount,
92
+ pointFeaturesCount,
93
+ linePositionsCount,
94
+ linePathsCount,
95
+ lineFeaturesCount,
96
+ polygonPositionsCount,
97
+ polygonObjectsCount,
98
+ polygonRingsCount,
99
+ polygonFeaturesCount
100
+ };
101
+ }
@@ -0,0 +1,58 @@
1
+ import type {TypedArray} from '@loaders.gl/schema';
2
+
3
+ /**
4
+ * Permissable constructor for numeric props
5
+ */
6
+ export type PropArrayConstructor =
7
+ | Float32ArrayConstructor
8
+ | Float64ArrayConstructor
9
+ | ArrayConstructor;
10
+
11
+ /**
12
+ * Collection type for holding intermediate binary data before conversion to `BinaryPointGeometry`
13
+ */
14
+ export type Points = {
15
+ type: 'Point';
16
+ positions: Float32Array | Float64Array;
17
+ globalFeatureIds: Uint16Array | Uint32Array;
18
+ featureIds: Uint16Array | Uint32Array;
19
+ numericProps: {[key: string]: TypedArray};
20
+ properties: {}[];
21
+ fields: {
22
+ id?: string | number;
23
+ }[];
24
+ };
25
+
26
+ /**
27
+ * Collection type for holding intermediate binary data before conversion to `BinaryLineStringGeometry`
28
+ */
29
+ export type Lines = {
30
+ type: 'LineString';
31
+ positions: Float32Array | Float64Array;
32
+ pathIndices: Uint16Array | Uint32Array;
33
+ globalFeatureIds: Uint16Array | Uint32Array;
34
+ featureIds: Uint16Array | Uint32Array;
35
+ numericProps: {[key: string]: TypedArray};
36
+ properties: {}[];
37
+ fields: {
38
+ id?: string | number;
39
+ }[];
40
+ };
41
+
42
+ /**
43
+ * Collection type for holding intermediate binary data before conversion to `BinaryPolygonGeometry`
44
+ */
45
+ export type Polygons = {
46
+ type: 'Polygon';
47
+ positions: Float32Array | Float64Array;
48
+ polygonIndices: Uint16Array | Uint32Array;
49
+ primitivePolygonIndices: Uint16Array | Uint32Array;
50
+ triangles: number[];
51
+ globalFeatureIds: Uint16Array | Uint32Array;
52
+ featureIds: Uint16Array | Uint32Array;
53
+ numericProps: {[key: string]: TypedArray};
54
+ properties: {}[];
55
+ fields: {
56
+ id?: string | number;
57
+ }[];
58
+ };