@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
|
@@ -1,274 +1,233 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.binaryToGeometry = exports.binaryToGeoJson = exports.binaryToGeojson = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Convert binary geometry representation to GeoJSON
|
|
6
|
+
* @param data geometry data in binary representation
|
|
7
|
+
* @param options
|
|
8
|
+
* @param options.type Input data type: Point, LineString, or Polygon
|
|
9
|
+
* @param options.featureId Global feature id. If specified, only a single feature is extracted
|
|
10
|
+
* @return GeoJSON objects
|
|
11
|
+
*/
|
|
12
|
+
function binaryToGeojson(data, options) {
|
|
13
|
+
const globalFeatureId = options?.globalFeatureId;
|
|
14
|
+
if (globalFeatureId !== undefined) {
|
|
15
|
+
return getSingleFeature(data, globalFeatureId);
|
|
16
|
+
}
|
|
17
|
+
return parseFeatures(data, options?.type);
|
|
9
18
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
exports.binaryToGeojson = binaryToGeojson;
|
|
20
|
+
/** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead */
|
|
21
|
+
function binaryToGeoJson(data, type, format = 'feature') {
|
|
22
|
+
switch (format) {
|
|
23
|
+
case 'feature':
|
|
24
|
+
return parseFeatures(data, type);
|
|
25
|
+
case 'geometry':
|
|
26
|
+
return binaryToGeometry(data);
|
|
27
|
+
default:
|
|
28
|
+
throw new Error(format);
|
|
29
|
+
}
|
|
21
30
|
}
|
|
22
|
-
|
|
31
|
+
exports.binaryToGeoJson = binaryToGeoJson;
|
|
32
|
+
/**
|
|
33
|
+
* Return a single feature from a binary geometry representation as GeoJSON
|
|
34
|
+
* @param data geometry data in binary representation
|
|
35
|
+
* @return GeoJSON feature
|
|
36
|
+
*/
|
|
23
37
|
function getSingleFeature(data, globalFeatureId) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {
|
|
46
|
-
return parseFeature(data, lastIndex, data.featureIds.value.length);
|
|
38
|
+
const dataArray = normalizeInput(data);
|
|
39
|
+
for (const data of dataArray) {
|
|
40
|
+
let lastIndex = 0;
|
|
41
|
+
let lastValue = data.featureIds.value[0];
|
|
42
|
+
// Scan through data until we find matching feature
|
|
43
|
+
for (let i = 0; i < data.featureIds.value.length; i++) {
|
|
44
|
+
const currValue = data.featureIds.value[i];
|
|
45
|
+
if (currValue === lastValue) {
|
|
46
|
+
// eslint-disable-next-line no-continue
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {
|
|
50
|
+
return parseFeature(data, lastIndex, i);
|
|
51
|
+
}
|
|
52
|
+
lastIndex = i;
|
|
53
|
+
lastValue = currValue;
|
|
54
|
+
}
|
|
55
|
+
if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {
|
|
56
|
+
return parseFeature(data, lastIndex, data.featureIds.value.length);
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
throw new Error("featureId:".concat(globalFeatureId, " not found"));
|
|
59
|
+
throw new Error(`featureId:${globalFeatureId} not found`);
|
|
51
60
|
}
|
|
52
|
-
|
|
53
61
|
function parseFeatures(data, type) {
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
const dataArray = normalizeInput(data, type);
|
|
63
|
+
return parseFeatureCollection(dataArray);
|
|
56
64
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const unexpectedInput = data;
|
|
71
|
-
throw new Error("Unsupported geometry type: ".concat(unexpectedInput === null || unexpectedInput === void 0 ? void 0 : unexpectedInput.type));
|
|
72
|
-
}
|
|
65
|
+
/** Parse input binary data and return a valid GeoJSON geometry object */
|
|
66
|
+
function binaryToGeometry(data, startIndex, endIndex) {
|
|
67
|
+
switch (data.type) {
|
|
68
|
+
case 'Point':
|
|
69
|
+
return pointToGeoJson(data, startIndex, endIndex);
|
|
70
|
+
case 'LineString':
|
|
71
|
+
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
72
|
+
case 'Polygon':
|
|
73
|
+
return polygonToGeoJson(data, startIndex, endIndex);
|
|
74
|
+
default:
|
|
75
|
+
const unexpectedInput = data;
|
|
76
|
+
throw new Error(`Unsupported geometry type: ${unexpectedInput?.type}`);
|
|
77
|
+
}
|
|
73
78
|
}
|
|
74
|
-
|
|
79
|
+
exports.binaryToGeometry = binaryToGeometry;
|
|
80
|
+
// Normalize features
|
|
81
|
+
// Return an array of data objects, each of which have a type key
|
|
75
82
|
function normalizeInput(data, type) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
features.push(data.polygons);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return features;
|
|
83
|
+
const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons);
|
|
84
|
+
if (!isHeterogeneousType) {
|
|
85
|
+
// @ts-expect-error This is a legacy check which allowed `data` to be an instance of the values
|
|
86
|
+
// here. Aka the new data.points, data.lines, or data.polygons.
|
|
87
|
+
data.type = type || parseType(data);
|
|
88
|
+
return [data];
|
|
89
|
+
}
|
|
90
|
+
const features = [];
|
|
91
|
+
if (data.points) {
|
|
92
|
+
data.points.type = 'Point';
|
|
93
|
+
features.push(data.points);
|
|
94
|
+
}
|
|
95
|
+
if (data.lines) {
|
|
96
|
+
data.lines.type = 'LineString';
|
|
97
|
+
features.push(data.lines);
|
|
98
|
+
}
|
|
99
|
+
if (data.polygons) {
|
|
100
|
+
data.polygons.type = 'Polygon';
|
|
101
|
+
features.push(data.polygons);
|
|
102
|
+
}
|
|
103
|
+
return features;
|
|
101
104
|
}
|
|
102
|
-
|
|
105
|
+
/** Parse input binary data and return an array of GeoJSON Features */
|
|
103
106
|
function parseFeatureCollection(dataArray) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
107
|
+
const features = [];
|
|
108
|
+
for (const data of dataArray) {
|
|
109
|
+
if (data.featureIds.value.length === 0) {
|
|
110
|
+
// eslint-disable-next-line no-continue
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
let lastIndex = 0;
|
|
114
|
+
let lastValue = data.featureIds.value[0];
|
|
115
|
+
// Need to deduce start, end indices of each feature
|
|
116
|
+
for (let i = 0; i < data.featureIds.value.length; i++) {
|
|
117
|
+
const currValue = data.featureIds.value[i];
|
|
118
|
+
if (currValue === lastValue) {
|
|
119
|
+
// eslint-disable-next-line no-continue
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
features.push(parseFeature(data, lastIndex, i));
|
|
123
|
+
lastIndex = i;
|
|
124
|
+
lastValue = currValue;
|
|
125
|
+
}
|
|
126
|
+
// Last feature
|
|
127
|
+
features.push(parseFeature(data, lastIndex, data.featureIds.value.length));
|
|
124
128
|
}
|
|
125
|
-
|
|
126
|
-
features.push(parseFeature(data, lastIndex, data.featureIds.value.length));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return features;
|
|
129
|
+
return features;
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
/** Parse input binary data and return a single GeoJSON Feature */
|
|
132
132
|
function parseFeature(data, startIndex, endIndex) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
type: 'Feature',
|
|
138
|
-
geometry,
|
|
139
|
-
properties,
|
|
140
|
-
...fields
|
|
141
|
-
};
|
|
133
|
+
const geometry = binaryToGeometry(data, startIndex, endIndex);
|
|
134
|
+
const properties = parseProperties(data, startIndex, endIndex);
|
|
135
|
+
const fields = parseFields(data, startIndex, endIndex);
|
|
136
|
+
return { type: 'Feature', geometry, properties, ...fields };
|
|
142
137
|
}
|
|
143
|
-
|
|
138
|
+
/** Parse input binary data and return an object of fields */
|
|
144
139
|
function parseFields(data, startIndex = 0, endIndex) {
|
|
145
|
-
|
|
140
|
+
return data.fields && data.fields[data.featureIds.value[startIndex]];
|
|
146
141
|
}
|
|
147
|
-
|
|
142
|
+
/** Parse input binary data and return an object of properties */
|
|
148
143
|
function parseProperties(data, startIndex = 0, endIndex) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return properties;
|
|
144
|
+
const properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);
|
|
145
|
+
for (const key in data.numericProps) {
|
|
146
|
+
properties[key] = data.numericProps[key].value[startIndex];
|
|
147
|
+
}
|
|
148
|
+
return properties;
|
|
156
149
|
}
|
|
157
|
-
|
|
150
|
+
/** Parse binary data of type Polygon */
|
|
158
151
|
function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
152
|
+
const { positions } = data;
|
|
153
|
+
const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
154
|
+
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
155
|
+
const multi = polygonIndices.length > 2;
|
|
156
|
+
// Polygon
|
|
157
|
+
if (!multi) {
|
|
158
|
+
const coordinates = [];
|
|
159
|
+
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
160
|
+
const startRingIndex = primitivePolygonIndices[i];
|
|
161
|
+
const endRingIndex = primitivePolygonIndices[i + 1];
|
|
162
|
+
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
163
|
+
coordinates.push(ringCoordinates);
|
|
164
|
+
}
|
|
165
|
+
return { type: 'Polygon', coordinates };
|
|
166
|
+
}
|
|
167
|
+
// MultiPolygon
|
|
167
168
|
const coordinates = [];
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
coordinates.push(ringCoordinates);
|
|
169
|
+
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
170
|
+
const startPolygonIndex = polygonIndices[i];
|
|
171
|
+
const endPolygonIndex = polygonIndices[i + 1];
|
|
172
|
+
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
173
|
+
coordinates.push(polygonCoordinates);
|
|
174
174
|
}
|
|
175
|
-
|
|
176
|
-
return {
|
|
177
|
-
type: 'Polygon',
|
|
178
|
-
coordinates
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const coordinates = [];
|
|
183
|
-
|
|
184
|
-
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
185
|
-
const startPolygonIndex = polygonIndices[i];
|
|
186
|
-
const endPolygonIndex = polygonIndices[i + 1];
|
|
187
|
-
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
188
|
-
coordinates.push(polygonCoordinates);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return {
|
|
192
|
-
type: 'MultiPolygon',
|
|
193
|
-
coordinates
|
|
194
|
-
};
|
|
175
|
+
return { type: 'MultiPolygon', coordinates };
|
|
195
176
|
}
|
|
196
|
-
|
|
177
|
+
/** Parse binary data of type LineString */
|
|
197
178
|
function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const coordinates =
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const coordinates = [];
|
|
213
|
-
|
|
214
|
-
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
215
|
-
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
216
|
-
coordinates.push(ringCoordinates);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return {
|
|
220
|
-
type: 'MultiLineString',
|
|
221
|
-
coordinates
|
|
222
|
-
};
|
|
179
|
+
const { positions } = data;
|
|
180
|
+
const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
181
|
+
const multi = pathIndices.length > 2;
|
|
182
|
+
if (!multi) {
|
|
183
|
+
const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
184
|
+
return { type: 'LineString', coordinates };
|
|
185
|
+
}
|
|
186
|
+
const coordinates = [];
|
|
187
|
+
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
188
|
+
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
189
|
+
coordinates.push(ringCoordinates);
|
|
190
|
+
}
|
|
191
|
+
return { type: 'MultiLineString', coordinates };
|
|
223
192
|
}
|
|
224
|
-
|
|
193
|
+
/** Parse binary data of type Point */
|
|
225
194
|
function pointToGeoJson(data, startIndex, endIndex) {
|
|
226
|
-
|
|
227
|
-
positions
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return {
|
|
234
|
-
type: 'MultiPoint',
|
|
235
|
-
coordinates
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return {
|
|
240
|
-
type: 'Point',
|
|
241
|
-
coordinates: coordinates[0]
|
|
242
|
-
};
|
|
195
|
+
const { positions } = data;
|
|
196
|
+
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
197
|
+
const multi = coordinates.length > 1;
|
|
198
|
+
if (multi) {
|
|
199
|
+
return { type: 'MultiPoint', coordinates };
|
|
200
|
+
}
|
|
201
|
+
return { type: 'Point', coordinates: coordinates[0] };
|
|
243
202
|
}
|
|
244
|
-
|
|
203
|
+
/**
|
|
204
|
+
* Parse a linear ring of positions to a GeoJSON linear ring
|
|
205
|
+
*
|
|
206
|
+
* @param positions Positions TypedArray
|
|
207
|
+
* @param startIndex Start index to include in ring
|
|
208
|
+
* @param endIndex End index to include in ring
|
|
209
|
+
* @returns GeoJSON ring
|
|
210
|
+
*/
|
|
245
211
|
function ringToGeoJson(positions, startIndex, endIndex) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
212
|
+
startIndex = startIndex || 0;
|
|
213
|
+
endIndex = endIndex || positions.value.length / positions.size;
|
|
214
|
+
const ringCoordinates = [];
|
|
215
|
+
for (let j = startIndex; j < endIndex; j++) {
|
|
216
|
+
const coord = Array();
|
|
217
|
+
for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
218
|
+
coord.push(Number(positions.value[k]));
|
|
219
|
+
}
|
|
220
|
+
ringCoordinates.push(coord);
|
|
255
221
|
}
|
|
256
|
-
|
|
257
|
-
ringCoordinates.push(coord);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return ringCoordinates;
|
|
222
|
+
return ringCoordinates;
|
|
261
223
|
}
|
|
262
|
-
|
|
224
|
+
// Deduce geometry type of data object
|
|
263
225
|
function parseType(data) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return 'Point';
|
|
226
|
+
if (data.pathIndices) {
|
|
227
|
+
return 'LineString';
|
|
228
|
+
}
|
|
229
|
+
if (data.polygonIndices) {
|
|
230
|
+
return 'Polygon';
|
|
231
|
+
}
|
|
232
|
+
return 'Point';
|
|
273
233
|
}
|
|
274
|
-
//# sourceMappingURL=binary-to-geojson.js.map
|
|
@@ -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,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractGeometryInfo = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Initial scan over GeoJSON features
|
|
6
|
+
* Counts number of coordinates of each geometry type and
|
|
7
|
+
* keeps track of the max coordinate dimensions
|
|
8
|
+
*/
|
|
9
|
+
// eslint-disable-next-line complexity, max-statements
|
|
10
|
+
function extractGeometryInfo(features) {
|
|
11
|
+
// Counts the number of _positions_, so [x, y, z] counts as one
|
|
12
|
+
let pointPositionsCount = 0;
|
|
13
|
+
let pointFeaturesCount = 0;
|
|
14
|
+
let linePositionsCount = 0;
|
|
15
|
+
let linePathsCount = 0;
|
|
16
|
+
let lineFeaturesCount = 0;
|
|
17
|
+
let polygonPositionsCount = 0;
|
|
18
|
+
let polygonObjectsCount = 0;
|
|
19
|
+
let polygonRingsCount = 0;
|
|
20
|
+
let polygonFeaturesCount = 0;
|
|
21
|
+
const coordLengths = new Set();
|
|
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
|
+
for (const coord of geometry.coordinates) {
|
|
42
|
+
coordLengths.add(coord.length);
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case 'MultiLineString':
|
|
46
|
+
lineFeaturesCount++;
|
|
47
|
+
for (const line of geometry.coordinates) {
|
|
48
|
+
linePositionsCount += line.length;
|
|
49
|
+
linePathsCount++;
|
|
50
|
+
// eslint-disable-next-line max-depth
|
|
51
|
+
for (const coord of line) {
|
|
52
|
+
coordLengths.add(coord.length);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 'Polygon':
|
|
57
|
+
polygonFeaturesCount++;
|
|
58
|
+
polygonObjectsCount++;
|
|
59
|
+
polygonRingsCount += geometry.coordinates.length;
|
|
60
|
+
const flattened = geometry.coordinates.flat();
|
|
61
|
+
polygonPositionsCount += flattened.length;
|
|
62
|
+
for (const coord of flattened) {
|
|
63
|
+
coordLengths.add(coord.length);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case 'MultiPolygon':
|
|
67
|
+
polygonFeaturesCount++;
|
|
68
|
+
for (const polygon of geometry.coordinates) {
|
|
69
|
+
polygonObjectsCount++;
|
|
70
|
+
polygonRingsCount += polygon.length;
|
|
71
|
+
const flattened = polygon.flat();
|
|
72
|
+
polygonPositionsCount += flattened.length;
|
|
73
|
+
// eslint-disable-next-line max-depth
|
|
74
|
+
for (const coord of flattened) {
|
|
75
|
+
coordLengths.add(coord.length);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
85
|
+
pointPositionsCount,
|
|
86
|
+
pointFeaturesCount,
|
|
87
|
+
linePositionsCount,
|
|
88
|
+
linePathsCount,
|
|
89
|
+
lineFeaturesCount,
|
|
90
|
+
polygonPositionsCount,
|
|
91
|
+
polygonObjectsCount,
|
|
92
|
+
polygonRingsCount,
|
|
93
|
+
polygonFeaturesCount
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
exports.extractGeometryInfo = extractGeometryInfo;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { TypedArray } from '@loaders.gl/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Permissable constructor for numeric props
|
|
4
|
+
*/
|
|
5
|
+
export type PropArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor | ArrayConstructor;
|
|
6
|
+
/**
|
|
7
|
+
* Collection type for holding intermediate binary data before conversion to `BinaryPointGeometry`
|
|
8
|
+
*/
|
|
9
|
+
export 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 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 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,MAAM,MAAM,oBAAoB,GAC5B,uBAAuB,GACvB,uBAAuB,GACvB,gBAAgB,CAAC;AAErB;;GAEG;AACH,MAAM,MAAM,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,MAAM,MAAM,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,MAAM,MAAM,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"}
|