@loaders.gl/gis 4.0.0-alpha.4 → 4.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +59 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/binary-to-geojson.js +255 -0
- package/dist/es5/lib/binary-to-geojson.js.map +1 -0
- package/dist/es5/lib/extract-geometry-info.js +167 -0
- package/dist/es5/lib/extract-geometry-info.js.map +1 -0
- package/dist/es5/lib/flat-geojson-to-binary-types.js +2 -0
- package/dist/es5/lib/flat-geojson-to-binary-types.js.map +1 -0
- package/dist/es5/lib/flat-geojson-to-binary.js +344 -0
- package/dist/es5/lib/flat-geojson-to-binary.js.map +1 -0
- package/dist/es5/lib/geojson-to-binary.js +26 -0
- package/dist/es5/lib/geojson-to-binary.js.map +1 -0
- package/dist/es5/lib/geojson-to-flat-geojson.js +136 -0
- package/dist/es5/lib/geojson-to-flat-geojson.js.map +1 -0
- package/dist/es5/lib/transform.js +57 -0
- package/dist/es5/lib/transform.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/binary-to-geojson.js +223 -0
- package/dist/esm/lib/binary-to-geojson.js.map +1 -0
- package/dist/esm/lib/extract-geometry-info.js +84 -0
- package/dist/esm/lib/extract-geometry-info.js.map +1 -0
- package/dist/esm/lib/flat-geojson-to-binary-types.js +2 -0
- package/dist/esm/lib/flat-geojson-to-binary-types.js.map +1 -0
- package/dist/esm/lib/flat-geojson-to-binary.js +305 -0
- package/dist/esm/lib/flat-geojson-to-binary.js.map +1 -0
- package/dist/esm/lib/geojson-to-binary.js +22 -0
- package/dist/esm/lib/geojson-to-binary.js.map +1 -0
- package/dist/esm/lib/geojson-to-flat-geojson.js +97 -0
- package/dist/esm/lib/geojson-to-flat-geojson.js.map +1 -0
- package/dist/esm/lib/transform.js +40 -0
- package/dist/esm/lib/transform.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -4
- package/dist/lib/binary-to-geojson.d.ts +21 -0
- package/dist/lib/binary-to-geojson.d.ts.map +1 -0
- package/dist/lib/binary-to-geojson.js +201 -242
- package/dist/lib/extract-geometry-info.d.ts +8 -0
- package/dist/lib/extract-geometry-info.d.ts.map +1 -0
- package/dist/lib/extract-geometry-info.js +96 -0
- package/dist/lib/flat-geojson-to-binary-types.d.ts +58 -0
- package/dist/lib/flat-geojson-to-binary-types.d.ts.map +1 -0
- package/dist/lib/flat-geojson-to-binary-types.js +2 -0
- package/dist/lib/flat-geojson-to-binary.d.ts +37 -0
- package/dist/lib/flat-geojson-to-binary.d.ts.map +1 -0
- package/dist/lib/flat-geojson-to-binary.js +376 -0
- package/dist/lib/geojson-to-binary.d.ts +19 -0
- package/dist/lib/geojson-to-binary.d.ts.map +1 -0
- package/dist/lib/geojson-to-binary.js +24 -407
- package/dist/lib/geojson-to-flat-geojson.d.ts +17 -0
- package/dist/lib/geojson-to-flat-geojson.d.ts.map +1 -0
- package/dist/lib/geojson-to-flat-geojson.js +128 -0
- package/dist/lib/transform.d.ts +19 -0
- package/dist/lib/transform.d.ts.map +1 -0
- package/dist/lib/transform.js +51 -42
- package/package.json +8 -7
- package/src/index.ts +2 -0
- package/src/lib/extract-geometry-info.ts +101 -0
- package/src/lib/flat-geojson-to-binary-types.ts +58 -0
- package/src/lib/flat-geojson-to-binary.ts +565 -0
- package/src/lib/geojson-to-binary.ts +24 -450
- package/src/lib/geojson-to-flat-geojson.ts +171 -0
- package/dist/bundle.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/binary-to-geojson.js.map +0 -1
- package/dist/lib/geojson-to-binary.js.map +0 -1
- package/dist/lib/transform.js.map +0 -1
package/dist/lib/transform.js
CHANGED
|
@@ -1,50 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
positions
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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.
|
|
4
|
+
"version": "4.0.0-alpha.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"geometry",
|
|
15
15
|
"GeoJSON"
|
|
16
16
|
],
|
|
17
|
-
"types": "
|
|
18
|
-
"main": "dist/index.js",
|
|
19
|
-
"module": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"main": "dist/es5/index.js",
|
|
19
|
+
"module": "dist/esm/index.js",
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"files": [
|
|
22
22
|
"src",
|
|
@@ -24,13 +24,14 @@
|
|
|
24
24
|
"README.md"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
28
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
27
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.6",
|
|
28
|
+
"@loaders.gl/schema": "4.0.0-alpha.6",
|
|
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": "
|
|
36
|
+
"gitHead": "acc1985050dfaa0f1f0c066f8da5bce7454a046c"
|
|
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
|
+
};
|