@loaders.gl/gis 4.2.0-alpha.4 → 4.2.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.
- package/dist/index.cjs +35 -92
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/lib/binary-features/binary-to-geojson.js +175 -171
- package/dist/lib/binary-features/extract-geometry-info.js +88 -80
- package/dist/lib/binary-features/flat-geojson-to-binary-types.js +0 -1
- package/dist/lib/binary-features/flat-geojson-to-binary.d.ts +1 -1
- package/dist/lib/binary-features/flat-geojson-to-binary.d.ts.map +1 -1
- package/dist/lib/binary-features/flat-geojson-to-binary.js +346 -281
- package/dist/lib/binary-features/geojson-to-binary.js +17 -20
- package/dist/lib/binary-features/geojson-to-flat-geojson.js +111 -84
- package/dist/lib/binary-features/transform.js +44 -30
- package/dist/lib/geo/geoarrow-metadata.js +61 -34
- package/dist/lib/geo/geoparquet-metadata-schema.js +64 -71
- package/dist/lib/geo/geoparquet-metadata.js +96 -77
- package/dist/lib/tables/convert-table-to-geojson.js +38 -42
- package/package.json +7 -4
- package/dist/index.js.map +0 -1
- package/dist/lib/binary-features/binary-to-geojson.js.map +0 -1
- package/dist/lib/binary-features/extract-geometry-info.js.map +0 -1
- package/dist/lib/binary-features/flat-geojson-to-binary-types.js.map +0 -1
- package/dist/lib/binary-features/flat-geojson-to-binary.js.map +0 -1
- package/dist/lib/binary-features/geojson-to-binary.js.map +0 -1
- package/dist/lib/binary-features/geojson-to-flat-geojson.js.map +0 -1
- package/dist/lib/binary-features/transform.js.map +0 -1
- package/dist/lib/geo/geoarrow-metadata.js.map +0 -1
- package/dist/lib/geo/geoparquet-metadata-schema.js.map +0 -1
- package/dist/lib/geo/geoparquet-metadata-schema.json +0 -60
- package/dist/lib/geo/geoparquet-metadata.js.map +0 -1
- package/dist/lib/tables/convert-table-to-geojson.js.map +0 -1
|
@@ -1,198 +1,202 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
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
|
+
*/
|
|
1
12
|
export function binaryToGeojson(data, options) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
13
|
+
const globalFeatureId = options?.globalFeatureId;
|
|
14
|
+
if (globalFeatureId !== undefined) {
|
|
15
|
+
return getSingleFeature(data, globalFeatureId);
|
|
16
|
+
}
|
|
17
|
+
return parseFeatures(data, options?.type);
|
|
7
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Return a single feature from a binary geometry representation as GeoJSON
|
|
21
|
+
* @param data geometry data in binary representation
|
|
22
|
+
* @return GeoJSON feature
|
|
23
|
+
*/
|
|
8
24
|
function getSingleFeature(data, globalFeatureId) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
const dataArray = normalizeInput(data);
|
|
26
|
+
for (const data of dataArray) {
|
|
27
|
+
let lastIndex = 0;
|
|
28
|
+
let lastValue = data.featureIds.value[0];
|
|
29
|
+
// Scan through data until we find matching feature
|
|
30
|
+
for (let i = 0; i < data.featureIds.value.length; i++) {
|
|
31
|
+
const currValue = data.featureIds.value[i];
|
|
32
|
+
if (currValue === lastValue) {
|
|
33
|
+
// eslint-disable-next-line no-continue
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {
|
|
37
|
+
return parseFeature(data, lastIndex, i);
|
|
38
|
+
}
|
|
39
|
+
lastIndex = i;
|
|
40
|
+
lastValue = currValue;
|
|
41
|
+
}
|
|
42
|
+
if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {
|
|
43
|
+
return parseFeature(data, lastIndex, data.featureIds.value.length);
|
|
44
|
+
}
|
|
26
45
|
}
|
|
27
|
-
|
|
28
|
-
throw new Error(`featureId:${globalFeatureId} not found`);
|
|
46
|
+
throw new Error(`featureId:${globalFeatureId} not found`);
|
|
29
47
|
}
|
|
30
48
|
function parseFeatures(data, type) {
|
|
31
|
-
|
|
32
|
-
|
|
49
|
+
const dataArray = normalizeInput(data, type);
|
|
50
|
+
return parseFeatureCollection(dataArray);
|
|
33
51
|
}
|
|
52
|
+
/** Parse input binary data and return a valid GeoJSON geometry object */
|
|
34
53
|
export function binaryToGeometry(data, startIndex, endIndex) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
switch (data.type) {
|
|
55
|
+
case 'Point':
|
|
56
|
+
return pointToGeoJson(data, startIndex, endIndex);
|
|
57
|
+
case 'LineString':
|
|
58
|
+
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
59
|
+
case 'Polygon':
|
|
60
|
+
return polygonToGeoJson(data, startIndex, endIndex);
|
|
61
|
+
default:
|
|
62
|
+
const unexpectedInput = data;
|
|
63
|
+
throw new Error(`Unsupported geometry type: ${unexpectedInput?.type}`);
|
|
64
|
+
}
|
|
46
65
|
}
|
|
66
|
+
// Normalize features
|
|
67
|
+
// Return an array of data objects, each of which have a type key
|
|
47
68
|
function normalizeInput(data, type) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
69
|
+
const features = [];
|
|
70
|
+
if (data.points) {
|
|
71
|
+
data.points.type = 'Point';
|
|
72
|
+
features.push(data.points);
|
|
73
|
+
}
|
|
74
|
+
if (data.lines) {
|
|
75
|
+
data.lines.type = 'LineString';
|
|
76
|
+
features.push(data.lines);
|
|
77
|
+
}
|
|
78
|
+
if (data.polygons) {
|
|
79
|
+
data.polygons.type = 'Polygon';
|
|
80
|
+
features.push(data.polygons);
|
|
81
|
+
}
|
|
82
|
+
return features;
|
|
62
83
|
}
|
|
84
|
+
/** Parse input binary data and return an array of GeoJSON Features */
|
|
63
85
|
function parseFeatureCollection(dataArray) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
const features = [];
|
|
87
|
+
for (const data of dataArray) {
|
|
88
|
+
if (data.featureIds.value.length === 0) {
|
|
89
|
+
// eslint-disable-next-line no-continue
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
let lastIndex = 0;
|
|
93
|
+
let lastValue = data.featureIds.value[0];
|
|
94
|
+
// Need to deduce start, end indices of each feature
|
|
95
|
+
for (let i = 0; i < data.featureIds.value.length; i++) {
|
|
96
|
+
const currValue = data.featureIds.value[i];
|
|
97
|
+
if (currValue === lastValue) {
|
|
98
|
+
// eslint-disable-next-line no-continue
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
features.push(parseFeature(data, lastIndex, i));
|
|
102
|
+
lastIndex = i;
|
|
103
|
+
lastValue = currValue;
|
|
104
|
+
}
|
|
105
|
+
// Last feature
|
|
106
|
+
features.push(parseFeature(data, lastIndex, data.featureIds.value.length));
|
|
79
107
|
}
|
|
80
|
-
features
|
|
81
|
-
}
|
|
82
|
-
return features;
|
|
108
|
+
return features;
|
|
83
109
|
}
|
|
110
|
+
/** Parse input binary data and return a single GeoJSON Feature */
|
|
84
111
|
function parseFeature(data, startIndex, endIndex) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
type: 'Feature',
|
|
90
|
-
geometry,
|
|
91
|
-
properties,
|
|
92
|
-
...fields
|
|
93
|
-
};
|
|
112
|
+
const geometry = binaryToGeometry(data, startIndex, endIndex);
|
|
113
|
+
const properties = parseProperties(data, startIndex, endIndex);
|
|
114
|
+
const fields = parseFields(data, startIndex, endIndex);
|
|
115
|
+
return { type: 'Feature', geometry, properties, ...fields };
|
|
94
116
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return data.fields && data.fields[data.featureIds.value[startIndex]];
|
|
117
|
+
/** Parse input binary data and return an object of fields */
|
|
118
|
+
function parseFields(data, startIndex = 0, endIndex) {
|
|
119
|
+
return data.fields && data.fields[data.featureIds.value[startIndex]];
|
|
99
120
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return properties;
|
|
121
|
+
/** Parse input binary data and return an object of properties */
|
|
122
|
+
function parseProperties(data, startIndex = 0, endIndex) {
|
|
123
|
+
const properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);
|
|
124
|
+
for (const key in data.numericProps) {
|
|
125
|
+
properties[key] = data.numericProps[key].value[startIndex];
|
|
126
|
+
}
|
|
127
|
+
return properties;
|
|
108
128
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
/** Parse binary data of type Polygon */
|
|
130
|
+
function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
131
|
+
const { positions } = data;
|
|
132
|
+
const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
133
|
+
const primitivePolygonIndices = data.primitivePolygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
134
|
+
const multi = polygonIndices.length > 2;
|
|
135
|
+
// Polygon
|
|
136
|
+
if (!multi) {
|
|
137
|
+
const coordinates = [];
|
|
138
|
+
for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
139
|
+
const startRingIndex = primitivePolygonIndices[i];
|
|
140
|
+
const endRingIndex = primitivePolygonIndices[i + 1];
|
|
141
|
+
const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
142
|
+
coordinates.push(ringCoordinates);
|
|
143
|
+
}
|
|
144
|
+
return { type: 'Polygon', coordinates };
|
|
145
|
+
}
|
|
146
|
+
// MultiPolygon
|
|
119
147
|
const coordinates = [];
|
|
120
|
-
for (let i = 0; i <
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
148
|
+
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
149
|
+
const startPolygonIndex = polygonIndices[i];
|
|
150
|
+
const endPolygonIndex = polygonIndices[i + 1];
|
|
151
|
+
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
152
|
+
coordinates.push(polygonCoordinates);
|
|
125
153
|
}
|
|
126
|
-
return {
|
|
127
|
-
type: 'Polygon',
|
|
128
|
-
coordinates
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
const coordinates = [];
|
|
132
|
-
for (let i = 0; i < polygonIndices.length - 1; i++) {
|
|
133
|
-
const startPolygonIndex = polygonIndices[i];
|
|
134
|
-
const endPolygonIndex = polygonIndices[i + 1];
|
|
135
|
-
const polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
136
|
-
coordinates.push(polygonCoordinates);
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
type: 'MultiPolygon',
|
|
140
|
-
coordinates
|
|
141
|
-
};
|
|
154
|
+
return { type: 'MultiPolygon', coordinates };
|
|
142
155
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const coordinates =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const coordinates = [];
|
|
159
|
-
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
160
|
-
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
161
|
-
coordinates.push(ringCoordinates);
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
type: 'MultiLineString',
|
|
165
|
-
coordinates
|
|
166
|
-
};
|
|
156
|
+
/** Parse binary data of type LineString */
|
|
157
|
+
function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
|
|
158
|
+
const { positions } = data;
|
|
159
|
+
const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
|
|
160
|
+
const multi = pathIndices.length > 2;
|
|
161
|
+
if (!multi) {
|
|
162
|
+
const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
163
|
+
return { type: 'LineString', coordinates };
|
|
164
|
+
}
|
|
165
|
+
const coordinates = [];
|
|
166
|
+
for (let i = 0; i < pathIndices.length - 1; i++) {
|
|
167
|
+
const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
168
|
+
coordinates.push(ringCoordinates);
|
|
169
|
+
}
|
|
170
|
+
return { type: 'MultiLineString', coordinates };
|
|
167
171
|
}
|
|
172
|
+
/** Parse binary data of type Point */
|
|
168
173
|
function pointToGeoJson(data, startIndex, endIndex) {
|
|
169
|
-
|
|
170
|
-
positions
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return {
|
|
176
|
-
type: 'MultiPoint',
|
|
177
|
-
coordinates
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
type: 'Point',
|
|
182
|
-
coordinates: coordinates[0]
|
|
183
|
-
};
|
|
174
|
+
const { positions } = data;
|
|
175
|
+
const coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
176
|
+
const multi = coordinates.length > 1;
|
|
177
|
+
if (multi) {
|
|
178
|
+
return { type: 'MultiPoint', coordinates };
|
|
179
|
+
}
|
|
180
|
+
return { type: 'Point', coordinates: coordinates[0] };
|
|
184
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Parse a linear ring of positions to a GeoJSON linear ring
|
|
184
|
+
*
|
|
185
|
+
* @param positions Positions TypedArray
|
|
186
|
+
* @param startIndex Start index to include in ring
|
|
187
|
+
* @param endIndex End index to include in ring
|
|
188
|
+
* @returns GeoJSON ring
|
|
189
|
+
*/
|
|
185
190
|
function ringToGeoJson(positions, startIndex, endIndex) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
startIndex = startIndex || 0;
|
|
192
|
+
endIndex = endIndex || positions.value.length / positions.size;
|
|
193
|
+
const ringCoordinates = [];
|
|
194
|
+
for (let j = startIndex; j < endIndex; j++) {
|
|
195
|
+
const coord = Array();
|
|
196
|
+
for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
197
|
+
coord.push(Number(positions.value[k]));
|
|
198
|
+
}
|
|
199
|
+
ringCoordinates.push(coord);
|
|
193
200
|
}
|
|
194
|
-
ringCoordinates
|
|
195
|
-
}
|
|
196
|
-
return ringCoordinates;
|
|
201
|
+
return ringCoordinates;
|
|
197
202
|
}
|
|
198
|
-
//# sourceMappingURL=binary-to-geojson.js.map
|
|
@@ -1,84 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initial scan over GeoJSON features
|
|
3
|
+
* Counts number of coordinates of each geometry type and
|
|
4
|
+
* keeps track of the max coordinate dimensions
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line complexity, max-statements
|
|
1
7
|
export function extractGeometryInfo(features) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
// Counts the number of _positions_, so [x, y, z] counts as one
|
|
9
|
+
let pointPositionsCount = 0;
|
|
10
|
+
let pointFeaturesCount = 0;
|
|
11
|
+
let linePositionsCount = 0;
|
|
12
|
+
let linePathsCount = 0;
|
|
13
|
+
let lineFeaturesCount = 0;
|
|
14
|
+
let polygonPositionsCount = 0;
|
|
15
|
+
let polygonObjectsCount = 0;
|
|
16
|
+
let polygonRingsCount = 0;
|
|
17
|
+
let polygonFeaturesCount = 0;
|
|
18
|
+
const coordLengths = new Set();
|
|
19
|
+
for (const feature of features) {
|
|
20
|
+
const geometry = feature.geometry;
|
|
21
|
+
switch (geometry.type) {
|
|
22
|
+
case 'Point':
|
|
23
|
+
pointFeaturesCount++;
|
|
24
|
+
pointPositionsCount++;
|
|
25
|
+
coordLengths.add(geometry.coordinates.length);
|
|
26
|
+
break;
|
|
27
|
+
case 'MultiPoint':
|
|
28
|
+
pointFeaturesCount++;
|
|
29
|
+
pointPositionsCount += geometry.coordinates.length;
|
|
30
|
+
for (const point of geometry.coordinates) {
|
|
31
|
+
coordLengths.add(point.length);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case 'LineString':
|
|
35
|
+
lineFeaturesCount++;
|
|
36
|
+
linePositionsCount += geometry.coordinates.length;
|
|
37
|
+
linePathsCount++;
|
|
38
|
+
for (const coord of geometry.coordinates) {
|
|
39
|
+
coordLengths.add(coord.length);
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
case 'MultiLineString':
|
|
43
|
+
lineFeaturesCount++;
|
|
44
|
+
for (const line of geometry.coordinates) {
|
|
45
|
+
linePositionsCount += line.length;
|
|
46
|
+
linePathsCount++;
|
|
47
|
+
// eslint-disable-next-line max-depth
|
|
48
|
+
for (const coord of line) {
|
|
49
|
+
coordLengths.add(coord.length);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case 'Polygon':
|
|
54
|
+
polygonFeaturesCount++;
|
|
55
|
+
polygonObjectsCount++;
|
|
56
|
+
polygonRingsCount += geometry.coordinates.length;
|
|
57
|
+
const flattened = geometry.coordinates.flat();
|
|
58
|
+
polygonPositionsCount += flattened.length;
|
|
59
|
+
for (const coord of flattened) {
|
|
60
|
+
coordLengths.add(coord.length);
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case 'MultiPolygon':
|
|
64
|
+
polygonFeaturesCount++;
|
|
65
|
+
for (const polygon of geometry.coordinates) {
|
|
66
|
+
polygonObjectsCount++;
|
|
67
|
+
polygonRingsCount += polygon.length;
|
|
68
|
+
const flattened = polygon.flat();
|
|
69
|
+
polygonPositionsCount += flattened.length;
|
|
70
|
+
// eslint-disable-next-line max-depth
|
|
71
|
+
for (const coord of flattened) {
|
|
72
|
+
coordLengths.add(coord.length);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
25
78
|
}
|
|
26
|
-
break;
|
|
27
|
-
case 'LineString':
|
|
28
|
-
lineFeaturesCount++;
|
|
29
|
-
linePositionsCount += geometry.coordinates.length;
|
|
30
|
-
linePathsCount++;
|
|
31
|
-
for (const coord of geometry.coordinates) {
|
|
32
|
-
coordLengths.add(coord.length);
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
35
|
-
case 'MultiLineString':
|
|
36
|
-
lineFeaturesCount++;
|
|
37
|
-
for (const line of geometry.coordinates) {
|
|
38
|
-
linePositionsCount += line.length;
|
|
39
|
-
linePathsCount++;
|
|
40
|
-
for (const coord of line) {
|
|
41
|
-
coordLengths.add(coord.length);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
break;
|
|
45
|
-
case 'Polygon':
|
|
46
|
-
polygonFeaturesCount++;
|
|
47
|
-
polygonObjectsCount++;
|
|
48
|
-
polygonRingsCount += geometry.coordinates.length;
|
|
49
|
-
const flattened = geometry.coordinates.flat();
|
|
50
|
-
polygonPositionsCount += flattened.length;
|
|
51
|
-
for (const coord of flattened) {
|
|
52
|
-
coordLengths.add(coord.length);
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
case 'MultiPolygon':
|
|
56
|
-
polygonFeaturesCount++;
|
|
57
|
-
for (const polygon of geometry.coordinates) {
|
|
58
|
-
polygonObjectsCount++;
|
|
59
|
-
polygonRingsCount += polygon.length;
|
|
60
|
-
const flattened = polygon.flat();
|
|
61
|
-
polygonPositionsCount += flattened.length;
|
|
62
|
-
for (const coord of flattened) {
|
|
63
|
-
coordLengths.add(coord.length);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
break;
|
|
67
|
-
default:
|
|
68
|
-
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
69
79
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
80
|
+
return {
|
|
81
|
+
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
82
|
+
pointPositionsCount,
|
|
83
|
+
pointFeaturesCount,
|
|
84
|
+
linePositionsCount,
|
|
85
|
+
linePathsCount,
|
|
86
|
+
lineFeaturesCount,
|
|
87
|
+
polygonPositionsCount,
|
|
88
|
+
polygonObjectsCount,
|
|
89
|
+
polygonRingsCount,
|
|
90
|
+
polygonFeaturesCount
|
|
91
|
+
};
|
|
83
92
|
}
|
|
84
|
-
//# sourceMappingURL=extract-geometry-info.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BinaryFeatureCollection, FlatFeature, GeojsonGeometryInfo } from '@loaders.gl/schema';
|
|
2
|
-
import { PropArrayConstructor } from
|
|
2
|
+
import { PropArrayConstructor } from "./flat-geojson-to-binary-types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Convert binary features to flat binary arrays. Similar to
|
|
5
5
|
* `geojsonToBinary` helper function, except that it expects
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flat-geojson-to-binary.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-features/flat-geojson-to-binary.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,uBAAuB,EAEvB,WAAW,EAIX,mBAAmB,EAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,oBAAoB,EAA0B,
|
|
1
|
+
{"version":3,"file":"flat-geojson-to-binary.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-features/flat-geojson-to-binary.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,uBAAuB,EAEvB,WAAW,EAIX,mBAAmB,EAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,oBAAoB,EAA0B,0CAAuC;AAE7F;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,WAAW,EAAE,EACvB,YAAY,EAAE,mBAAmB,EACjC,OAAO,CAAC,EAAE,0BAA0B,2BAgBrC;AAED;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,uBAAuB,GAAG,uBAAuB,CAAC;IACrE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,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"}
|