@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
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.TEST_EXPORTS = void 0;
|
|
8
|
+
exports.flatGeojsonToBinary = flatGeojsonToBinary;
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _polygon = require("@math.gl/polygon");
|
|
11
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
16
|
+
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
17
|
+
var propArrayTypes = extractNumericPropTypes(features);
|
|
18
|
+
var numericPropKeys = Object.keys(propArrayTypes).filter(function (k) {
|
|
19
|
+
return propArrayTypes[k] !== Array;
|
|
20
|
+
});
|
|
21
|
+
return fillArrays(features, _objectSpread({
|
|
22
|
+
propArrayTypes: propArrayTypes
|
|
23
|
+
}, geometryInfo), {
|
|
24
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
25
|
+
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
var TEST_EXPORTS = {
|
|
29
|
+
extractNumericPropTypes: extractNumericPropTypes
|
|
30
|
+
};
|
|
31
|
+
exports.TEST_EXPORTS = TEST_EXPORTS;
|
|
32
|
+
function extractNumericPropTypes(features) {
|
|
33
|
+
var propArrayTypes = {};
|
|
34
|
+
var _iterator = _createForOfIteratorHelper(features),
|
|
35
|
+
_step;
|
|
36
|
+
try {
|
|
37
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
38
|
+
var feature = _step.value;
|
|
39
|
+
if (feature.properties) {
|
|
40
|
+
for (var _key in feature.properties) {
|
|
41
|
+
var val = feature.properties[_key];
|
|
42
|
+
propArrayTypes[_key] = deduceArrayType(val, propArrayTypes[_key]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
_iterator.e(err);
|
|
48
|
+
} finally {
|
|
49
|
+
_iterator.f();
|
|
50
|
+
}
|
|
51
|
+
return propArrayTypes;
|
|
52
|
+
}
|
|
53
|
+
function fillArrays(features, geometryInfo, options) {
|
|
54
|
+
var pointPositionsCount = geometryInfo.pointPositionsCount,
|
|
55
|
+
pointFeaturesCount = geometryInfo.pointFeaturesCount,
|
|
56
|
+
linePositionsCount = geometryInfo.linePositionsCount,
|
|
57
|
+
linePathsCount = geometryInfo.linePathsCount,
|
|
58
|
+
lineFeaturesCount = geometryInfo.lineFeaturesCount,
|
|
59
|
+
polygonPositionsCount = geometryInfo.polygonPositionsCount,
|
|
60
|
+
polygonObjectsCount = geometryInfo.polygonObjectsCount,
|
|
61
|
+
polygonRingsCount = geometryInfo.polygonRingsCount,
|
|
62
|
+
polygonFeaturesCount = geometryInfo.polygonFeaturesCount,
|
|
63
|
+
propArrayTypes = geometryInfo.propArrayTypes,
|
|
64
|
+
coordLength = geometryInfo.coordLength;
|
|
65
|
+
var _options$numericPropK = options.numericPropKeys,
|
|
66
|
+
numericPropKeys = _options$numericPropK === void 0 ? [] : _options$numericPropK,
|
|
67
|
+
_options$PositionData = options.PositionDataType,
|
|
68
|
+
PositionDataType = _options$PositionData === void 0 ? Float32Array : _options$PositionData;
|
|
69
|
+
var hasGlobalId = features[0] && 'id' in features[0];
|
|
70
|
+
var GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
71
|
+
var points = {
|
|
72
|
+
type: 'Point',
|
|
73
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
74
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
75
|
+
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
76
|
+
numericProps: {},
|
|
77
|
+
properties: [],
|
|
78
|
+
fields: []
|
|
79
|
+
};
|
|
80
|
+
var lines = {
|
|
81
|
+
type: 'LineString',
|
|
82
|
+
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
83
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
84
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
85
|
+
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
86
|
+
numericProps: {},
|
|
87
|
+
properties: [],
|
|
88
|
+
fields: []
|
|
89
|
+
};
|
|
90
|
+
var polygons = {
|
|
91
|
+
type: 'Polygon',
|
|
92
|
+
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
93
|
+
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
94
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
95
|
+
triangles: [],
|
|
96
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
97
|
+
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
98
|
+
numericProps: {},
|
|
99
|
+
properties: [],
|
|
100
|
+
fields: []
|
|
101
|
+
};
|
|
102
|
+
for (var _i = 0, _arr = [points, lines, polygons]; _i < _arr.length; _i++) {
|
|
103
|
+
var object = _arr[_i];
|
|
104
|
+
var _iterator2 = _createForOfIteratorHelper(numericPropKeys),
|
|
105
|
+
_step2;
|
|
106
|
+
try {
|
|
107
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
108
|
+
var propName = _step2.value;
|
|
109
|
+
var T = propArrayTypes[propName];
|
|
110
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
111
|
+
}
|
|
112
|
+
} catch (err) {
|
|
113
|
+
_iterator2.e(err);
|
|
114
|
+
} finally {
|
|
115
|
+
_iterator2.f();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
119
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
120
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
121
|
+
var indexMap = {
|
|
122
|
+
pointPosition: 0,
|
|
123
|
+
pointFeature: 0,
|
|
124
|
+
linePosition: 0,
|
|
125
|
+
linePath: 0,
|
|
126
|
+
lineFeature: 0,
|
|
127
|
+
polygonPosition: 0,
|
|
128
|
+
polygonObject: 0,
|
|
129
|
+
polygonRing: 0,
|
|
130
|
+
polygonFeature: 0,
|
|
131
|
+
feature: 0
|
|
132
|
+
};
|
|
133
|
+
var _iterator3 = _createForOfIteratorHelper(features),
|
|
134
|
+
_step3;
|
|
135
|
+
try {
|
|
136
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
137
|
+
var feature = _step3.value;
|
|
138
|
+
var geometry = feature.geometry;
|
|
139
|
+
var properties = feature.properties || {};
|
|
140
|
+
switch (geometry.type) {
|
|
141
|
+
case 'Point':
|
|
142
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
143
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
144
|
+
if (hasGlobalId) {
|
|
145
|
+
points.fields.push({
|
|
146
|
+
id: feature.id
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
indexMap.pointFeature++;
|
|
150
|
+
break;
|
|
151
|
+
case 'LineString':
|
|
152
|
+
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
153
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
154
|
+
if (hasGlobalId) {
|
|
155
|
+
lines.fields.push({
|
|
156
|
+
id: feature.id
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
indexMap.lineFeature++;
|
|
160
|
+
break;
|
|
161
|
+
case 'Polygon':
|
|
162
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
163
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
164
|
+
if (hasGlobalId) {
|
|
165
|
+
polygons.fields.push({
|
|
166
|
+
id: feature.id
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
indexMap.polygonFeature++;
|
|
170
|
+
break;
|
|
171
|
+
default:
|
|
172
|
+
throw new Error('Invalid geometry type');
|
|
173
|
+
}
|
|
174
|
+
indexMap.feature++;
|
|
175
|
+
}
|
|
176
|
+
} catch (err) {
|
|
177
|
+
_iterator3.e(err);
|
|
178
|
+
} finally {
|
|
179
|
+
_iterator3.f();
|
|
180
|
+
}
|
|
181
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
182
|
+
}
|
|
183
|
+
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
184
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
185
|
+
var nPositions = geometry.data.length / coordLength;
|
|
186
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
187
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
188
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
189
|
+
indexMap.pointPosition += nPositions;
|
|
190
|
+
}
|
|
191
|
+
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
192
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
193
|
+
var nPositions = geometry.data.length / coordLength;
|
|
194
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
195
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
196
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
197
|
+
for (var i = 0, il = geometry.indices.length; i < il; ++i) {
|
|
198
|
+
var start = geometry.indices[i];
|
|
199
|
+
var end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
|
|
200
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
201
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
205
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
206
|
+
var nPositions = geometry.data.length / coordLength;
|
|
207
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
208
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
209
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
210
|
+
for (var l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
211
|
+
var startPosition = indexMap.polygonPosition;
|
|
212
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
213
|
+
var areas = geometry.areas[l];
|
|
214
|
+
var indices = geometry.indices[l];
|
|
215
|
+
var nextIndices = geometry.indices[l + 1];
|
|
216
|
+
for (var i = 0, il = indices.length; i < il; ++i) {
|
|
217
|
+
var start = indices[i];
|
|
218
|
+
var end = i === il - 1 ? nextIndices === undefined ? geometry.data.length : nextIndices[0] : indices[i + 1];
|
|
219
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
220
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
221
|
+
}
|
|
222
|
+
var endPosition = indexMap.polygonPosition;
|
|
223
|
+
triangulatePolygon(polygons, areas, indices, {
|
|
224
|
+
startPosition: startPosition,
|
|
225
|
+
endPosition: endPosition,
|
|
226
|
+
coordLength: coordLength
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function triangulatePolygon(polygons, areas, indices, _ref) {
|
|
231
|
+
var startPosition = _ref.startPosition,
|
|
232
|
+
endPosition = _ref.endPosition,
|
|
233
|
+
coordLength = _ref.coordLength;
|
|
234
|
+
var start = startPosition * coordLength;
|
|
235
|
+
var end = endPosition * coordLength;
|
|
236
|
+
var polygonPositions = polygons.positions.subarray(start, end);
|
|
237
|
+
var offset = indices[0];
|
|
238
|
+
var holes = indices.slice(1).map(function (n) {
|
|
239
|
+
return (n - offset) / coordLength;
|
|
240
|
+
});
|
|
241
|
+
var triangles = (0, _polygon.earcut)(polygonPositions, holes, coordLength, areas);
|
|
242
|
+
for (var t = 0, tl = triangles.length; t < tl; ++t) {
|
|
243
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function wrapProps(obj, size) {
|
|
247
|
+
var returnObj = {};
|
|
248
|
+
for (var _key2 in obj) {
|
|
249
|
+
returnObj[_key2] = {
|
|
250
|
+
value: obj[_key2],
|
|
251
|
+
size: size
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
return returnObj;
|
|
255
|
+
}
|
|
256
|
+
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
257
|
+
return {
|
|
258
|
+
points: _objectSpread(_objectSpread({}, points), {}, {
|
|
259
|
+
positions: {
|
|
260
|
+
value: points.positions,
|
|
261
|
+
size: coordLength
|
|
262
|
+
},
|
|
263
|
+
globalFeatureIds: {
|
|
264
|
+
value: points.globalFeatureIds,
|
|
265
|
+
size: 1
|
|
266
|
+
},
|
|
267
|
+
featureIds: {
|
|
268
|
+
value: points.featureIds,
|
|
269
|
+
size: 1
|
|
270
|
+
},
|
|
271
|
+
numericProps: wrapProps(points.numericProps, 1)
|
|
272
|
+
}),
|
|
273
|
+
lines: _objectSpread(_objectSpread({}, lines), {}, {
|
|
274
|
+
positions: {
|
|
275
|
+
value: lines.positions,
|
|
276
|
+
size: coordLength
|
|
277
|
+
},
|
|
278
|
+
pathIndices: {
|
|
279
|
+
value: lines.pathIndices,
|
|
280
|
+
size: 1
|
|
281
|
+
},
|
|
282
|
+
globalFeatureIds: {
|
|
283
|
+
value: lines.globalFeatureIds,
|
|
284
|
+
size: 1
|
|
285
|
+
},
|
|
286
|
+
featureIds: {
|
|
287
|
+
value: lines.featureIds,
|
|
288
|
+
size: 1
|
|
289
|
+
},
|
|
290
|
+
numericProps: wrapProps(lines.numericProps, 1)
|
|
291
|
+
}),
|
|
292
|
+
polygons: _objectSpread(_objectSpread({}, polygons), {}, {
|
|
293
|
+
positions: {
|
|
294
|
+
value: polygons.positions,
|
|
295
|
+
size: coordLength
|
|
296
|
+
},
|
|
297
|
+
polygonIndices: {
|
|
298
|
+
value: polygons.polygonIndices,
|
|
299
|
+
size: 1
|
|
300
|
+
},
|
|
301
|
+
primitivePolygonIndices: {
|
|
302
|
+
value: polygons.primitivePolygonIndices,
|
|
303
|
+
size: 1
|
|
304
|
+
},
|
|
305
|
+
triangles: {
|
|
306
|
+
value: new Uint32Array(polygons.triangles),
|
|
307
|
+
size: 1
|
|
308
|
+
},
|
|
309
|
+
globalFeatureIds: {
|
|
310
|
+
value: polygons.globalFeatureIds,
|
|
311
|
+
size: 1
|
|
312
|
+
},
|
|
313
|
+
featureIds: {
|
|
314
|
+
value: polygons.featureIds,
|
|
315
|
+
size: 1
|
|
316
|
+
},
|
|
317
|
+
numericProps: wrapProps(polygons.numericProps, 1)
|
|
318
|
+
})
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function fillNumericProperties(object, properties, index, length) {
|
|
322
|
+
for (var numericPropName in object.numericProps) {
|
|
323
|
+
if (numericPropName in properties) {
|
|
324
|
+
var value = properties[numericPropName];
|
|
325
|
+
object.numericProps[numericPropName].fill(value, index, index + length);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function keepStringProperties(properties, numericKeys) {
|
|
330
|
+
var props = {};
|
|
331
|
+
for (var _key3 in properties) {
|
|
332
|
+
if (!numericKeys.includes(_key3)) {
|
|
333
|
+
props[_key3] = properties[_key3];
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return props;
|
|
337
|
+
}
|
|
338
|
+
function deduceArrayType(x, constructor) {
|
|
339
|
+
if (constructor === Array || !Number.isFinite(x)) {
|
|
340
|
+
return Array;
|
|
341
|
+
}
|
|
342
|
+
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
343
|
+
}
|
|
344
|
+
//# sourceMappingURL=flat-geojson-to-binary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flat-geojson-to-binary.js","names":["_polygon","require","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","arguments","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","flatGeojsonToBinary","features","geometryInfo","options","propArrayTypes","extractNumericPropTypes","numericPropKeys","k","fillArrays","PositionDataType","Float32Array","TEST_EXPORTS","exports","_iterator","_step","feature","properties","val","deduceArrayType","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLength","_options$numericPropK","_options$PositionData","hasGlobalId","GlobalFeatureIdsDataType","Uint32Array","Uint16Array","points","type","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","_i","_arr","_iterator2","_step2","propName","T","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","_iterator3","_step3","geometry","handlePoint","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","il","indices","start","end","l","ll","startPosition","areas","nextIndices","undefined","endPosition","triangulatePolygon","_ref","polygonPositions","subarray","offset","holes","map","earcut","t","tl","wrapProps","obj","size","returnObj","index","numericPropName","numericKeys","props","includes","x","Number","isFinite","Float64Array","Math","fround"],"sources":["../../../src/lib/flat-geojson-to-binary.ts"],"sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport type {\n BinaryAttribute,\n BinaryFeatures,\n FlatFeature,\n FlatPoint,\n FlatLineString,\n FlatPolygon,\n GeojsonGeometryInfo,\n TypedArray\n} from '@loaders.gl/schema';\nimport {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-binary-types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param geometryInfo\n * @param options\n * @returns filled arrays\n */\nexport function flatGeojsonToBinary(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo,\n options?: FlatGeojsonToBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(\n features,\n {\n propArrayTypes,\n ...geometryInfo\n },\n {\n numericPropKeys: (options && options.numericPropKeys) || numericPropKeys,\n PositionDataType: options ? options.PositionDataType : Float32Array\n }\n );\n}\n\n/**\n * Options for `flatGeojsonToBinary`\n */\nexport type FlatGeojsonToBinaryOptions = {\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\nexport const TEST_EXPORTS = {\n extractNumericPropTypes\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: FlatFeature[]): {\n [key: string]: PropArrayConstructor;\n} {\n const propArrayTypes = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, Array is stored to prevent rechecking in the future\n // Additionally, detects if 64 bit precision is required\n const val = feature.properties[key];\n propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);\n }\n }\n }\n\n return propArrayTypes;\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param geometryInfo\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo & {\n propArrayTypes: {[key: string]: PropArrayConstructor};\n },\n options: FlatGeojsonToBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount,\n propArrayTypes,\n coordLength\n } = geometryInfo;\n const {numericPropKeys = [], PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: Points = {\n type: 'Point',\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: Lines = {\n type: 'LineString',\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: Polygons = {\n type: 'Polygon',\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n const T = propArrayTypes[propName];\n object.numericProps[propName] = new T(object.positions.length / coordLength) as TypedArray;\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: FlatPoint,\n points: Points,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: FlatLineString,\n lines: Lines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.indices.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.indices[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.indices[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: FlatPolygon,\n polygons: Polygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.indices is a 2D array\n for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas[l];\n const indices = geometry.indices[l];\n const nextIndices = geometry.indices[l + 1];\n\n for (let i = 0, il = indices.length; i < il; ++i) {\n const start = indices[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextIndices === undefined\n ? geometry.data.length // end of data (no next indices)\n : nextIndices[0] // start of first line in nextIndices\n : indices[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, indices, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param indices\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: Polygons,\n areas: number[],\n indices: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = indices[0];\n const holes = indices.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n // @ts-expect-error TODO can earcut handle binary arrays? Add tests?\n const triangles = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = triangles.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + triangles[t]);\n }\n}\n\n/**\n * Wraps an object containing array into accessors\n *\n * @param obj\n * @param size\n */\nfunction wrapProps(\n obj: {[key: string]: TypedArray},\n size: number\n): {[key: string]: BinaryAttribute} {\n const returnObj = {};\n for (const key in obj) {\n returnObj[key] = {value: obj[key], size};\n }\n return returnObj;\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: Points,\n lines: Lines,\n polygons: Polygons,\n coordLength: number\n): BinaryFeatures {\n return {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1},\n numericProps: wrapProps(points.numericProps, 1)\n },\n lines: {\n ...lines,\n positions: {value: lines.positions, size: coordLength},\n pathIndices: {value: lines.pathIndices, size: 1},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1},\n numericProps: wrapProps(lines.numericProps, 1)\n },\n polygons: {\n ...polygons,\n positions: {value: polygons.positions, size: coordLength},\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1},\n numericProps: wrapProps(polygons.numericProps, 1)\n }\n };\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: Points | Lines | Polygons,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n const value = properties[numericPropName] as number;\n object.numericProps[numericPropName].fill(value, index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\n/**\n *\n * Deduce correct array constructor to use for a given value\n *\n * @param x value to test\n * @param constructor previous constructor deduced\n * @returns PropArrayConstructor\n */\nfunction deduceArrayType(x: any, constructor: PropArrayConstructor): PropArrayConstructor {\n if (constructor === Array || !Number.isFinite(x)) {\n return Array;\n }\n\n // If this or previous value required 64bits use Float64Array\n return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;\n}\n"],"mappings":";;;;;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAAwC,SAAAC,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,MAAAE,EAAA,GAAAK,2BAAA,CAAAP,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAQ,MAAA,qBAAAN,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAO,CAAA,UAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,QAAAH,CAAA,IAAAT,CAAA,CAAAQ,MAAA,WAAAK,IAAA,mBAAAA,IAAA,SAAAC,KAAA,EAAAd,CAAA,CAAAS,CAAA,UAAAM,CAAA,WAAAA,EAAAC,EAAA,UAAAA,EAAA,KAAAC,CAAA,EAAAP,CAAA,gBAAAQ,SAAA,iJAAAC,gBAAA,SAAAC,MAAA,UAAAC,GAAA,WAAAV,CAAA,WAAAA,EAAA,IAAAT,EAAA,GAAAA,EAAA,CAAAoB,IAAA,CAAAtB,CAAA,MAAAY,CAAA,WAAAA,EAAA,QAAAW,IAAA,GAAArB,EAAA,CAAAsB,IAAA,IAAAL,gBAAA,GAAAI,IAAA,CAAAV,IAAA,SAAAU,IAAA,KAAAR,CAAA,WAAAA,EAAAU,GAAA,IAAAL,MAAA,SAAAC,GAAA,GAAAI,GAAA,KAAAR,CAAA,WAAAA,EAAA,eAAAE,gBAAA,IAA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AAEyJ,KAAK,EAAEA,KAAK,GAAG/J,MAAM,CAAC;IACzE;EACF;AACF;AASA,SAAS2H,oBAAoBA,CAC3BpD,UAA2D,EAC3D0F,WAAqB,EACrB;EACA,IAAMC,KAAK,GAAG,CAAC,CAAC;EAChB,KAAK,IAAMjH,KAAG,IAAIsB,UAAU,EAAE;IAC5B,IAAI,CAAC0F,WAAW,CAACE,QAAQ,CAAClH,KAAG,CAAC,EAAE;MAC9BiH,KAAK,CAACjH,KAAG,CAAC,GAAGsB,UAAU,CAACtB,KAAG,CAAC;IAC9B;EACF;EACA,OAAOiH,KAAK;AACd;AAUA,SAASzF,eAAeA,CAAC2F,CAAM,EAAE3I,WAAiC,EAAwB;EACxF,IAAIA,WAAW,KAAK5B,KAAK,IAAI,CAACwK,MAAM,CAACC,QAAQ,CAACF,CAAC,CAAC,EAAE;IAChD,OAAOvK,KAAK;EACd;EAGA,OAAO4B,WAAW,KAAK8I,YAAY,IAAIC,IAAI,CAACC,MAAM,CAACL,CAAC,CAAC,KAAKA,CAAC,GAAGG,YAAY,GAAGtG,YAAY;AAC3F"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.geojsonToBinary = geojsonToBinary;
|
|
7
|
+
var _extractGeometryInfo = require("./extract-geometry-info");
|
|
8
|
+
var _geojsonToFlatGeojson = require("./geojson-to-flat-geojson");
|
|
9
|
+
var _flatGeojsonToBinary = require("./flat-geojson-to-binary");
|
|
10
|
+
function geojsonToBinary(features) {
|
|
11
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
12
|
+
fixRingWinding: true
|
|
13
|
+
};
|
|
14
|
+
var geometryInfo = (0, _extractGeometryInfo.extractGeometryInfo)(features);
|
|
15
|
+
var coordLength = geometryInfo.coordLength;
|
|
16
|
+
var fixRingWinding = options.fixRingWinding;
|
|
17
|
+
var flatFeatures = (0, _geojsonToFlatGeojson.geojsonToFlatGeojson)(features, {
|
|
18
|
+
coordLength: coordLength,
|
|
19
|
+
fixRingWinding: fixRingWinding
|
|
20
|
+
});
|
|
21
|
+
return (0, _flatGeojsonToBinary.flatGeojsonToBinary)(flatFeatures, geometryInfo, {
|
|
22
|
+
numericPropKeys: options.numericPropKeys,
|
|
23
|
+
PositionDataType: options.PositionDataType || Float32Array
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=geojson-to-binary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geojson-to-binary.js","names":["_extractGeometryInfo","require","_geojsonToFlatGeojson","_flatGeojsonToBinary","geojsonToBinary","features","options","arguments","length","undefined","fixRingWinding","geometryInfo","extractGeometryInfo","coordLength","flatFeatures","geojsonToFlatGeojson","flatGeojsonToBinary","numericPropKeys","PositionDataType","Float32Array"],"sources":["../../../src/lib/geojson-to-binary.ts"],"sourcesContent":["import type {Feature} from '@loaders.gl/schema';\nimport type {BinaryFeatures} from '@loaders.gl/schema';\n\nimport {extractGeometryInfo} from './extract-geometry-info';\nimport {geojsonToFlatGeojson} from './geojson-to-flat-geojson';\nimport {flatGeojsonToBinary} from './flat-geojson-to-binary';\n\n/**\n * Options for `geojsonToBinary`\n */\nexport type GeojsonToBinaryOptions = {\n fixRingWinding: boolean;\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\n/**\n * Convert GeoJSON features to flat binary arrays\n *\n * @param features\n * @param options\n * @returns features in binary format, grouped by geometry type\n */\nexport function geojsonToBinary(\n features: Feature[],\n options: GeojsonToBinaryOptions = {fixRingWinding: true}\n): BinaryFeatures {\n const geometryInfo = extractGeometryInfo(features);\n const coordLength = geometryInfo.coordLength;\n const {fixRingWinding} = options;\n const flatFeatures = geojsonToFlatGeojson(features, {coordLength, fixRingWinding});\n return flatGeojsonToBinary(flatFeatures, geometryInfo, {\n numericPropKeys: options.numericPropKeys,\n PositionDataType: options.PositionDataType || Float32Array\n });\n}\n"],"mappings":";;;;;;AAGA,IAAAA,oBAAA,GAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAF,OAAA;AAkBO,SAASG,eAAeA,CAC7BC,QAAmB,EAEH;EAAA,IADhBC,OAA+B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IAACG,cAAc,EAAE;EAAI,CAAC;EAExD,IAAMC,YAAY,GAAG,IAAAC,wCAAmB,EAACP,QAAQ,CAAC;EAClD,IAAMQ,WAAW,GAAGF,YAAY,CAACE,WAAW;EAC5C,IAAOH,cAAc,GAAIJ,OAAO,CAAzBI,cAAc;EACrB,IAAMI,YAAY,GAAG,IAAAC,0CAAoB,EAACV,QAAQ,EAAE;IAACQ,WAAW,EAAXA,WAAW;IAAEH,cAAc,EAAdA;EAAc,CAAC,CAAC;EAClF,OAAO,IAAAM,wCAAmB,EAACF,YAAY,EAAEH,YAAY,EAAE;IACrDM,eAAe,EAAEX,OAAO,CAACW,eAAe;IACxCC,gBAAgB,EAAEZ,OAAO,CAACY,gBAAgB,IAAIC;EAChD,CAAC,CAAC;AACJ"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.geojsonToFlatGeojson = geojsonToFlatGeojson;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _polygon = require("@math.gl/polygon");
|
|
11
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
14
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
|
+
function geojsonToFlatGeojson(features) {
|
|
17
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
18
|
+
coordLength: 2,
|
|
19
|
+
fixRingWinding: true
|
|
20
|
+
};
|
|
21
|
+
return features.map(function (feature) {
|
|
22
|
+
return flattenFeature(feature, options);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function flattenPoint(coordinates, data, indices, options) {
|
|
26
|
+
indices.push(data.length);
|
|
27
|
+
data.push.apply(data, (0, _toConsumableArray2.default)(coordinates));
|
|
28
|
+
for (var i = coordinates.length; i < options.coordLength; i++) {
|
|
29
|
+
data.push(0);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function flattenLineString(coordinates, data, indices, options) {
|
|
33
|
+
indices.push(data.length);
|
|
34
|
+
var _iterator = _createForOfIteratorHelper(coordinates),
|
|
35
|
+
_step;
|
|
36
|
+
try {
|
|
37
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
38
|
+
var c = _step.value;
|
|
39
|
+
data.push.apply(data, (0, _toConsumableArray2.default)(c));
|
|
40
|
+
for (var i = c.length; i < options.coordLength; i++) {
|
|
41
|
+
data.push(0);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} catch (err) {
|
|
45
|
+
_iterator.e(err);
|
|
46
|
+
} finally {
|
|
47
|
+
_iterator.f();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function flattenPolygon(coordinates, data, indices, areas, options) {
|
|
51
|
+
var count = 0;
|
|
52
|
+
var ringAreas = [];
|
|
53
|
+
var polygons = [];
|
|
54
|
+
var _iterator2 = _createForOfIteratorHelper(coordinates),
|
|
55
|
+
_step2;
|
|
56
|
+
try {
|
|
57
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
58
|
+
var lineString = _step2.value;
|
|
59
|
+
var lineString2d = lineString.map(function (p) {
|
|
60
|
+
return p.slice(0, 2);
|
|
61
|
+
});
|
|
62
|
+
var area = (0, _polygon.getPolygonSignedArea)(lineString2d.flat());
|
|
63
|
+
var ccw = area < 0;
|
|
64
|
+
if (options.fixRingWinding && (count === 0 && !ccw || count > 0 && ccw)) {
|
|
65
|
+
lineString.reverse();
|
|
66
|
+
area = -area;
|
|
67
|
+
}
|
|
68
|
+
ringAreas.push(area);
|
|
69
|
+
flattenLineString(lineString, data, polygons, options);
|
|
70
|
+
count++;
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
_iterator2.e(err);
|
|
74
|
+
} finally {
|
|
75
|
+
_iterator2.f();
|
|
76
|
+
}
|
|
77
|
+
if (count > 0) {
|
|
78
|
+
areas.push(ringAreas);
|
|
79
|
+
indices.push(polygons);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function flattenFeature(feature, options) {
|
|
83
|
+
var geometry = feature.geometry;
|
|
84
|
+
if (geometry.type === 'GeometryCollection') {
|
|
85
|
+
throw new Error('GeometryCollection type not supported');
|
|
86
|
+
}
|
|
87
|
+
var data = [];
|
|
88
|
+
var indices = [];
|
|
89
|
+
var areas;
|
|
90
|
+
var type;
|
|
91
|
+
switch (geometry.type) {
|
|
92
|
+
case 'Point':
|
|
93
|
+
type = 'Point';
|
|
94
|
+
flattenPoint(geometry.coordinates, data, indices, options);
|
|
95
|
+
break;
|
|
96
|
+
case 'MultiPoint':
|
|
97
|
+
type = 'Point';
|
|
98
|
+
geometry.coordinates.map(function (c) {
|
|
99
|
+
return flattenPoint(c, data, indices, options);
|
|
100
|
+
});
|
|
101
|
+
break;
|
|
102
|
+
case 'LineString':
|
|
103
|
+
type = 'LineString';
|
|
104
|
+
flattenLineString(geometry.coordinates, data, indices, options);
|
|
105
|
+
break;
|
|
106
|
+
case 'MultiLineString':
|
|
107
|
+
type = 'LineString';
|
|
108
|
+
geometry.coordinates.map(function (c) {
|
|
109
|
+
return flattenLineString(c, data, indices, options);
|
|
110
|
+
});
|
|
111
|
+
break;
|
|
112
|
+
case 'Polygon':
|
|
113
|
+
type = 'Polygon';
|
|
114
|
+
areas = [];
|
|
115
|
+
flattenPolygon(geometry.coordinates, data, indices, areas, options);
|
|
116
|
+
break;
|
|
117
|
+
case 'MultiPolygon':
|
|
118
|
+
type = 'Polygon';
|
|
119
|
+
areas = [];
|
|
120
|
+
geometry.coordinates.map(function (c) {
|
|
121
|
+
return flattenPolygon(c, data, indices, areas, options);
|
|
122
|
+
});
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
throw new Error("Unknown type: ".concat(type));
|
|
126
|
+
}
|
|
127
|
+
return _objectSpread(_objectSpread({}, feature), {}, {
|
|
128
|
+
geometry: {
|
|
129
|
+
type: type,
|
|
130
|
+
indices: indices,
|
|
131
|
+
data: data,
|
|
132
|
+
areas: areas
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=geojson-to-flat-geojson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geojson-to-flat-geojson.js","names":["_polygon","require","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","geojsonToFlatGeojson","features","options","undefined","coordLength","fixRingWinding","map","feature","flattenFeature","flattenPoint","coordinates","data","indices","_toConsumableArray2","flattenLineString","_iterator","_step","c","flattenPolygon","areas","count","ringAreas","polygons","_iterator2","_step2","lineString","lineString2d","p","area","getPolygonSignedArea","flat","ccw","reverse","geometry","type","Error","concat"],"sources":["../../../src/lib/geojson-to-flat-geojson.ts"],"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"],"mappings":";;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAsD,SAAAC,QAAAC,MAAA,EAA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