@loaders.gl/gis 3.1.0-alpha.2 → 3.1.0-beta.1
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 +4 -6
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +48 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/binary-to-geojson.js +284 -0
- package/dist/es5/lib/binary-to-geojson.js.map +1 -0
- package/dist/es5/lib/geojson-to-binary.js +417 -0
- package/dist/es5/lib/geojson-to-binary.js.map +1 -0
- package/dist/es5/lib/transform.js +58 -0
- package/dist/es5/lib/transform.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/binary-to-geojson.js +274 -0
- package/dist/esm/lib/binary-to-geojson.js.map +1 -0
- package/dist/esm/lib/geojson-to-binary.js +407 -0
- package/dist/esm/lib/geojson-to-binary.js.map +1 -0
- package/dist/esm/lib/transform.js +50 -0
- package/dist/esm/lib/transform.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -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/geojson-to-binary.d.ts +39 -0
- package/dist/lib/geojson-to-binary.d.ts.map +1 -0
- package/dist/lib/geojson-to-binary.js +324 -369
- 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 +7 -7
- package/src/bundle.ts +2 -3
- 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
|
@@ -1,407 +1,362 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TEST_EXPORTS = exports.geojsonToBinary = void 0;
|
|
4
|
+
/** Convert GeoJSON features to flat binary arrays */
|
|
5
|
+
function geojsonToBinary(features, options = {}) {
|
|
6
|
+
const firstPassData = firstPass(features);
|
|
7
|
+
return secondPass(features, firstPassData, {
|
|
8
|
+
coordLength: options.coordLength || firstPassData.coordLength,
|
|
9
|
+
numericPropKeys: options.numericPropKeys || firstPassData.numericPropKeys,
|
|
10
|
+
PositionDataType: options.PositionDataType || Float32Array
|
|
11
|
+
});
|
|
8
12
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
exports.geojsonToBinary = geojsonToBinary;
|
|
14
|
+
exports.TEST_EXPORTS = {
|
|
15
|
+
firstPass,
|
|
16
|
+
secondPass
|
|
12
17
|
};
|
|
13
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Initial scan over GeoJSON features
|
|
20
|
+
* Counts number of coordinates of each geometry type and
|
|
21
|
+
* keeps track of the max coordinate dimensions
|
|
22
|
+
*/
|
|
23
|
+
// eslint-disable-next-line complexity, max-statements
|
|
14
24
|
function firstPass(features) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
// Counts the number of _positions_, so [x, y, z] counts as one
|
|
26
|
+
let pointPositionsCount = 0;
|
|
27
|
+
let pointFeaturesCount = 0;
|
|
28
|
+
let linePositionsCount = 0;
|
|
29
|
+
let linePathsCount = 0;
|
|
30
|
+
let lineFeaturesCount = 0;
|
|
31
|
+
let polygonPositionsCount = 0;
|
|
32
|
+
let polygonObjectsCount = 0;
|
|
33
|
+
let polygonRingsCount = 0;
|
|
34
|
+
let polygonFeaturesCount = 0;
|
|
35
|
+
const coordLengths = new Set();
|
|
36
|
+
const numericPropKeys = {};
|
|
37
|
+
for (const feature of features) {
|
|
38
|
+
const geometry = feature.geometry;
|
|
39
|
+
switch (geometry.type) {
|
|
40
|
+
case 'Point':
|
|
41
|
+
pointFeaturesCount++;
|
|
42
|
+
pointPositionsCount++;
|
|
43
|
+
coordLengths.add(geometry.coordinates.length);
|
|
44
|
+
break;
|
|
45
|
+
case 'MultiPoint':
|
|
46
|
+
pointFeaturesCount++;
|
|
47
|
+
pointPositionsCount += geometry.coordinates.length;
|
|
48
|
+
for (const point of geometry.coordinates) {
|
|
49
|
+
coordLengths.add(point.length);
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
case 'LineString':
|
|
53
|
+
lineFeaturesCount++;
|
|
54
|
+
linePositionsCount += geometry.coordinates.length;
|
|
55
|
+
linePathsCount++;
|
|
56
|
+
for (const coord of geometry.coordinates) {
|
|
57
|
+
coordLengths.add(coord.length);
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
case 'MultiLineString':
|
|
61
|
+
lineFeaturesCount++;
|
|
62
|
+
for (const line of geometry.coordinates) {
|
|
63
|
+
linePositionsCount += line.length;
|
|
64
|
+
linePathsCount++;
|
|
65
|
+
// eslint-disable-next-line max-depth
|
|
66
|
+
for (const coord of line) {
|
|
67
|
+
coordLengths.add(coord.length);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
case 'Polygon':
|
|
72
|
+
polygonFeaturesCount++;
|
|
73
|
+
polygonObjectsCount++;
|
|
74
|
+
polygonRingsCount += geometry.coordinates.length;
|
|
75
|
+
polygonPositionsCount += flatten(geometry.coordinates).length;
|
|
76
|
+
for (const coord of flatten(geometry.coordinates)) {
|
|
77
|
+
coordLengths.add(coord.length);
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case 'MultiPolygon':
|
|
81
|
+
polygonFeaturesCount++;
|
|
82
|
+
for (const polygon of geometry.coordinates) {
|
|
83
|
+
polygonObjectsCount++;
|
|
84
|
+
polygonRingsCount += polygon.length;
|
|
85
|
+
polygonPositionsCount += flatten(polygon).length;
|
|
86
|
+
// eslint-disable-next-line max-depth
|
|
87
|
+
for (const coord of flatten(polygon)) {
|
|
88
|
+
coordLengths.add(coord.length);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
43
94
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
95
|
+
if (feature.properties) {
|
|
96
|
+
for (const key in feature.properties) {
|
|
97
|
+
const val = feature.properties[key];
|
|
98
|
+
// If property has not been seen before, or if property has been numeric
|
|
99
|
+
// in all previous features, check if numeric in this feature
|
|
100
|
+
// If not numeric, false is stored to prevent rechecking in the future
|
|
101
|
+
numericPropKeys[key] =
|
|
102
|
+
numericPropKeys[key] || numericPropKeys[key] === undefined
|
|
103
|
+
? isNumeric(val)
|
|
104
|
+
: numericPropKeys[key];
|
|
105
|
+
}
|
|
54
106
|
}
|
|
55
|
-
|
|
56
|
-
break;
|
|
57
|
-
|
|
58
|
-
case 'MultiLineString':
|
|
59
|
-
lineFeaturesCount++;
|
|
60
|
-
|
|
61
|
-
for (const line of geometry.coordinates) {
|
|
62
|
-
linePositionsCount += line.length;
|
|
63
|
-
linePathsCount++;
|
|
64
|
-
|
|
65
|
-
for (const coord of line) {
|
|
66
|
-
coordLengths.add(coord.length);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
break;
|
|
71
|
-
|
|
72
|
-
case 'Polygon':
|
|
73
|
-
polygonFeaturesCount++;
|
|
74
|
-
polygonObjectsCount++;
|
|
75
|
-
polygonRingsCount += geometry.coordinates.length;
|
|
76
|
-
polygonPositionsCount += flatten(geometry.coordinates).length;
|
|
77
|
-
|
|
78
|
-
for (const coord of flatten(geometry.coordinates)) {
|
|
79
|
-
coordLengths.add(coord.length);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
break;
|
|
83
|
-
|
|
84
|
-
case 'MultiPolygon':
|
|
85
|
-
polygonFeaturesCount++;
|
|
86
|
-
|
|
87
|
-
for (const polygon of geometry.coordinates) {
|
|
88
|
-
polygonObjectsCount++;
|
|
89
|
-
polygonRingsCount += polygon.length;
|
|
90
|
-
polygonPositionsCount += flatten(polygon).length;
|
|
91
|
-
|
|
92
|
-
for (const coord of flatten(polygon)) {
|
|
93
|
-
coordLengths.add(coord.length);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
break;
|
|
98
|
-
|
|
99
|
-
default:
|
|
100
|
-
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (feature.properties) {
|
|
104
|
-
for (const key in feature.properties) {
|
|
105
|
-
const val = feature.properties[key];
|
|
106
|
-
numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === undefined ? isNumeric(val) : numericPropKeys[key];
|
|
107
|
-
}
|
|
108
107
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
};
|
|
108
|
+
return {
|
|
109
|
+
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
110
|
+
pointPositionsCount,
|
|
111
|
+
pointFeaturesCount,
|
|
112
|
+
linePositionsCount,
|
|
113
|
+
linePathsCount,
|
|
114
|
+
lineFeaturesCount,
|
|
115
|
+
polygonPositionsCount,
|
|
116
|
+
polygonObjectsCount,
|
|
117
|
+
polygonRingsCount,
|
|
118
|
+
polygonFeaturesCount,
|
|
119
|
+
// Array of keys whose values are always numeric
|
|
120
|
+
numericPropKeys: Object.keys(numericPropKeys).filter((k) => numericPropKeys[k])
|
|
121
|
+
};
|
|
124
122
|
}
|
|
125
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Second scan over GeoJSON features
|
|
125
|
+
* Fills coordinates into pre-allocated typed arrays
|
|
126
|
+
*/
|
|
127
|
+
// eslint-disable-next-line complexity
|
|
126
128
|
function secondPass(features, firstPassData, options) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
for (const
|
|
174
|
-
|
|
129
|
+
const { pointPositionsCount, pointFeaturesCount, linePositionsCount, linePathsCount, lineFeaturesCount, polygonPositionsCount, polygonObjectsCount, polygonRingsCount, polygonFeaturesCount } = firstPassData;
|
|
130
|
+
const { coordLength, numericPropKeys, PositionDataType = Float32Array } = options;
|
|
131
|
+
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
132
|
+
const points = {
|
|
133
|
+
// @ts-ignore Typescript doesn't like dynamic constructors
|
|
134
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
135
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
136
|
+
featureIds: pointFeaturesCount > 65535
|
|
137
|
+
? new Uint32Array(pointPositionsCount)
|
|
138
|
+
: new Uint16Array(pointPositionsCount),
|
|
139
|
+
numericProps: {},
|
|
140
|
+
properties: Array(),
|
|
141
|
+
fields: Array()
|
|
142
|
+
};
|
|
143
|
+
const lines = {
|
|
144
|
+
// @ts-ignore Typescript doesn't like dynamic constructors
|
|
145
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
146
|
+
pathIndices: linePositionsCount > 65535
|
|
147
|
+
? new Uint32Array(linePathsCount + 1)
|
|
148
|
+
: new Uint16Array(linePathsCount + 1),
|
|
149
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
150
|
+
featureIds: lineFeaturesCount > 65535
|
|
151
|
+
? new Uint32Array(linePositionsCount)
|
|
152
|
+
: new Uint16Array(linePositionsCount),
|
|
153
|
+
numericProps: {},
|
|
154
|
+
properties: Array(),
|
|
155
|
+
fields: Array()
|
|
156
|
+
};
|
|
157
|
+
const polygons = {
|
|
158
|
+
// @ts-ignore Typescript doesn't like dynamic constructors
|
|
159
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
160
|
+
polygonIndices: polygonPositionsCount > 65535
|
|
161
|
+
? new Uint32Array(polygonObjectsCount + 1)
|
|
162
|
+
: new Uint16Array(polygonObjectsCount + 1),
|
|
163
|
+
primitivePolygonIndices: polygonPositionsCount > 65535
|
|
164
|
+
? new Uint32Array(polygonRingsCount + 1)
|
|
165
|
+
: new Uint16Array(polygonRingsCount + 1),
|
|
166
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
167
|
+
featureIds: polygonFeaturesCount > 65535
|
|
168
|
+
? new Uint32Array(polygonPositionsCount)
|
|
169
|
+
: new Uint16Array(polygonPositionsCount),
|
|
170
|
+
numericProps: {},
|
|
171
|
+
properties: Array(),
|
|
172
|
+
fields: Array()
|
|
173
|
+
};
|
|
174
|
+
// Instantiate numeric properties arrays; one value per vertex
|
|
175
|
+
for (const object of [points, lines, polygons]) {
|
|
176
|
+
for (const propName of numericPropKeys || []) {
|
|
177
|
+
// If property has been numeric in all previous features in which the property existed, check
|
|
178
|
+
// if numeric in this feature
|
|
179
|
+
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
|
|
180
|
+
}
|
|
175
181
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
231
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
232
|
-
indexMap.polygonFeature++;
|
|
233
|
-
break;
|
|
234
|
-
|
|
235
|
-
default:
|
|
236
|
-
throw new Error('Invalid geometry type');
|
|
182
|
+
// Set last element of path/polygon indices as positions length
|
|
183
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
184
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
185
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
186
|
+
const indexMap = {
|
|
187
|
+
pointPosition: 0,
|
|
188
|
+
pointFeature: 0,
|
|
189
|
+
linePosition: 0,
|
|
190
|
+
linePath: 0,
|
|
191
|
+
lineFeature: 0,
|
|
192
|
+
polygonPosition: 0,
|
|
193
|
+
polygonObject: 0,
|
|
194
|
+
polygonRing: 0,
|
|
195
|
+
polygonFeature: 0,
|
|
196
|
+
feature: 0
|
|
197
|
+
};
|
|
198
|
+
for (const feature of features) {
|
|
199
|
+
const geometry = feature.geometry;
|
|
200
|
+
const properties = feature.properties || {};
|
|
201
|
+
switch (geometry.type) {
|
|
202
|
+
case 'Point':
|
|
203
|
+
handlePoint(geometry.coordinates, points, indexMap, coordLength, properties);
|
|
204
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
205
|
+
indexMap.pointFeature++;
|
|
206
|
+
break;
|
|
207
|
+
case 'MultiPoint':
|
|
208
|
+
handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
|
|
209
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
210
|
+
indexMap.pointFeature++;
|
|
211
|
+
break;
|
|
212
|
+
case 'LineString':
|
|
213
|
+
handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
|
|
214
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
215
|
+
indexMap.lineFeature++;
|
|
216
|
+
break;
|
|
217
|
+
case 'MultiLineString':
|
|
218
|
+
handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
|
|
219
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
220
|
+
indexMap.lineFeature++;
|
|
221
|
+
break;
|
|
222
|
+
case 'Polygon':
|
|
223
|
+
handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
224
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
225
|
+
indexMap.polygonFeature++;
|
|
226
|
+
break;
|
|
227
|
+
case 'MultiPolygon':
|
|
228
|
+
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
229
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
230
|
+
indexMap.polygonFeature++;
|
|
231
|
+
break;
|
|
232
|
+
default:
|
|
233
|
+
throw new Error('Invalid geometry type');
|
|
234
|
+
}
|
|
235
|
+
indexMap.feature++;
|
|
237
236
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
237
|
+
// Wrap each array in an accessor object with value and size keys
|
|
238
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
243
239
|
}
|
|
244
|
-
|
|
240
|
+
/** Fills Point coordinates into points object of arrays */
|
|
245
241
|
function handlePoint(coords, points, indexMap, coordLength, properties) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
242
|
+
points.positions.set(coords, indexMap.pointPosition * coordLength);
|
|
243
|
+
points.globalFeatureIds[indexMap.pointPosition] = indexMap.feature;
|
|
244
|
+
points.featureIds[indexMap.pointPosition] = indexMap.pointFeature;
|
|
245
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, 1);
|
|
246
|
+
indexMap.pointPosition++;
|
|
251
247
|
}
|
|
252
|
-
|
|
248
|
+
/** Fills MultiPoint coordinates into points object of arrays */
|
|
253
249
|
function handleMultiPoint(coords, points, indexMap, coordLength, properties) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
250
|
+
for (const point of coords) {
|
|
251
|
+
handlePoint(point, points, indexMap, coordLength, properties);
|
|
252
|
+
}
|
|
257
253
|
}
|
|
258
|
-
|
|
254
|
+
/** Fills LineString coordinates into lines object of arrays */
|
|
259
255
|
function handleLineString(coords, lines, indexMap, coordLength, properties) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
256
|
+
lines.pathIndices[indexMap.linePath] = indexMap.linePosition;
|
|
257
|
+
indexMap.linePath++;
|
|
258
|
+
fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);
|
|
259
|
+
const nPositions = coords.length;
|
|
260
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
261
|
+
lines.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.linePosition);
|
|
262
|
+
lines.featureIds.set(new Uint32Array(nPositions).fill(indexMap.lineFeature), indexMap.linePosition);
|
|
263
|
+
indexMap.linePosition += nPositions;
|
|
268
264
|
}
|
|
269
|
-
|
|
265
|
+
/** Fills MultiLineString coordinates into lines object of arrays */
|
|
270
266
|
function handleMultiLineString(coords, lines, indexMap, coordLength, properties) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
267
|
+
for (const line of coords) {
|
|
268
|
+
handleLineString(line, lines, indexMap, coordLength, properties);
|
|
269
|
+
}
|
|
274
270
|
}
|
|
275
|
-
|
|
271
|
+
/** Fills Polygon coordinates into polygons object of arrays */
|
|
276
272
|
function handlePolygon(coords, polygons, indexMap, coordLength, properties) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
273
|
+
polygons.polygonIndices[indexMap.polygonObject] = indexMap.polygonPosition;
|
|
274
|
+
indexMap.polygonObject++;
|
|
275
|
+
for (const ring of coords) {
|
|
276
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition;
|
|
277
|
+
indexMap.polygonRing++;
|
|
278
|
+
fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength);
|
|
279
|
+
const nPositions = ring.length;
|
|
280
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
281
|
+
polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition);
|
|
282
|
+
polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition);
|
|
283
|
+
indexMap.polygonPosition += nPositions;
|
|
284
|
+
}
|
|
290
285
|
}
|
|
291
|
-
|
|
286
|
+
/** Fills MultiPolygon coordinates into polygons object of arrays */
|
|
292
287
|
function handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
288
|
+
for (const polygon of coords) {
|
|
289
|
+
handlePolygon(polygon, polygons, indexMap, coordLength, properties);
|
|
290
|
+
}
|
|
296
291
|
}
|
|
297
|
-
|
|
292
|
+
/** Wrap each array in an accessor object with value and size keys */
|
|
298
293
|
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
type: 'LineString'
|
|
333
|
-
},
|
|
334
|
-
polygons: { ...polygons,
|
|
335
|
-
polygonIndices: {
|
|
336
|
-
value: polygons.polygonIndices,
|
|
337
|
-
size: 1
|
|
338
|
-
},
|
|
339
|
-
primitivePolygonIndices: {
|
|
340
|
-
value: polygons.primitivePolygonIndices,
|
|
341
|
-
size: 1
|
|
342
|
-
},
|
|
343
|
-
positions: {
|
|
344
|
-
value: polygons.positions,
|
|
345
|
-
size: coordLength
|
|
346
|
-
},
|
|
347
|
-
globalFeatureIds: {
|
|
348
|
-
value: polygons.globalFeatureIds,
|
|
349
|
-
size: 1
|
|
350
|
-
},
|
|
351
|
-
featureIds: {
|
|
352
|
-
value: polygons.featureIds,
|
|
353
|
-
size: 1
|
|
354
|
-
},
|
|
355
|
-
type: 'Polygon'
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
for (const geomType in returnObj) {
|
|
360
|
-
for (const numericProp in returnObj[geomType].numericProps) {
|
|
361
|
-
returnObj[geomType].numericProps[numericProp] = {
|
|
362
|
-
value: returnObj[geomType].numericProps[numericProp],
|
|
363
|
-
size: 1
|
|
364
|
-
};
|
|
294
|
+
const returnObj = {
|
|
295
|
+
points: {
|
|
296
|
+
...points,
|
|
297
|
+
positions: { value: points.positions, size: coordLength },
|
|
298
|
+
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
299
|
+
featureIds: { value: points.featureIds, size: 1 },
|
|
300
|
+
type: 'Point'
|
|
301
|
+
},
|
|
302
|
+
lines: {
|
|
303
|
+
...lines,
|
|
304
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
305
|
+
positions: { value: lines.positions, size: coordLength },
|
|
306
|
+
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
307
|
+
featureIds: { value: lines.featureIds, size: 1 },
|
|
308
|
+
type: 'LineString'
|
|
309
|
+
},
|
|
310
|
+
polygons: {
|
|
311
|
+
...polygons,
|
|
312
|
+
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
313
|
+
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
314
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
315
|
+
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
316
|
+
featureIds: { value: polygons.featureIds, size: 1 },
|
|
317
|
+
type: 'Polygon'
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
for (const geomType in returnObj) {
|
|
321
|
+
for (const numericProp in returnObj[geomType].numericProps) {
|
|
322
|
+
returnObj[geomType].numericProps[numericProp] = {
|
|
323
|
+
value: returnObj[geomType].numericProps[numericProp],
|
|
324
|
+
size: 1
|
|
325
|
+
};
|
|
326
|
+
}
|
|
365
327
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return returnObj;
|
|
328
|
+
return returnObj;
|
|
369
329
|
}
|
|
370
|
-
|
|
330
|
+
/** Add numeric properties to object */
|
|
371
331
|
function fillNumericProperties(object, properties, index, length) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
332
|
+
for (const numericPropName in object.numericProps) {
|
|
333
|
+
if (numericPropName in properties) {
|
|
334
|
+
object.numericProps[numericPropName].set(new Array(length).fill(properties[numericPropName]), index);
|
|
335
|
+
}
|
|
375
336
|
}
|
|
376
|
-
}
|
|
377
337
|
}
|
|
378
|
-
|
|
338
|
+
/** Keep string properties in object */
|
|
379
339
|
function keepStringProperties(properties, numericKeys) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
340
|
+
const props = {};
|
|
341
|
+
for (const key in properties) {
|
|
342
|
+
if (!numericKeys.includes(key)) {
|
|
343
|
+
props[key] = properties[key];
|
|
344
|
+
}
|
|
385
345
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
return props;
|
|
346
|
+
return props;
|
|
389
347
|
}
|
|
390
|
-
|
|
348
|
+
/** @param coords is expected to be a list of arrays, each with length 2-3 */
|
|
391
349
|
function fillCoords(array, coords, startVertex, coordLength) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}
|
|
350
|
+
let index = startVertex * coordLength;
|
|
351
|
+
for (const coord of coords) {
|
|
352
|
+
array.set(coord, index);
|
|
353
|
+
index += coordLength;
|
|
354
|
+
}
|
|
398
355
|
}
|
|
399
|
-
|
|
356
|
+
// TODO - how does this work? Different `coordinates` have different nesting
|
|
400
357
|
function flatten(arrays) {
|
|
401
|
-
|
|
358
|
+
return [].concat(...arrays);
|
|
402
359
|
}
|
|
403
|
-
|
|
404
360
|
function isNumeric(x) {
|
|
405
|
-
|
|
361
|
+
return Number.isFinite(x);
|
|
406
362
|
}
|
|
407
|
-
//# sourceMappingURL=geojson-to-binary.js.map
|