@loaders.gl/gis 3.1.0-beta.5 → 3.1.2
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/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +22 -6
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/binary-to-geojson.js +139 -93
- package/dist/es5/lib/binary-to-geojson.js.map +1 -1
- package/dist/es5/lib/extract-geometry-info.js +204 -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 +397 -0
- package/dist/es5/lib/flat-geojson-to-binary.js.map +1 -0
- package/dist/es5/lib/geojson-to-binary.js +17 -404
- package/dist/es5/lib/geojson-to-binary.js.map +1 -1
- package/dist/es5/lib/geojson-to-flat-geojson.js +169 -0
- package/dist/es5/lib/geojson-to-flat-geojson.js.map +1 -0
- package/dist/es5/lib/transform.js +24 -9
- package/dist/es5/lib/transform.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/extract-geometry-info.js +105 -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 +339 -0
- package/dist/esm/lib/flat-geojson-to-binary.js.map +1 -0
- package/dist/esm/lib/geojson-to-binary.js +17 -403
- package/dist/esm/lib/geojson-to-binary.js.map +1 -1
- package/dist/esm/lib/geojson-to-flat-geojson.js +116 -0
- package/dist/esm/lib/geojson-to-flat-geojson.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- 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 +375 -0
- package/dist/lib/geojson-to-binary.d.ts +12 -32
- package/dist/lib/geojson-to-binary.d.ts.map +1 -1
- package/dist/lib/geojson-to-binary.js +18 -356
- 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/package.json +5 -4
- 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 +564 -0
- package/src/lib/geojson-to-binary.ts +24 -450
- package/src/lib/geojson-to-flat-geojson.ts +171 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.geojsonToFlatGeojson = geojsonToFlatGeojson;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
+
|
|
14
|
+
var _polygon = require("@math.gl/polygon");
|
|
15
|
+
|
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
+
|
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
+
|
|
20
|
+
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; } } }; }
|
|
21
|
+
|
|
22
|
+
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); }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
function geojsonToFlatGeojson(features) {
|
|
27
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
28
|
+
coordLength: 2,
|
|
29
|
+
fixRingWinding: true
|
|
30
|
+
};
|
|
31
|
+
return features.map(function (feature) {
|
|
32
|
+
return flattenFeature(feature, options);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function flattenPoint(coordinates, data, indices, options) {
|
|
37
|
+
indices.push(data.length);
|
|
38
|
+
data.push.apply(data, (0, _toConsumableArray2.default)(coordinates));
|
|
39
|
+
|
|
40
|
+
for (var i = coordinates.length; i < options.coordLength; i++) {
|
|
41
|
+
data.push(0);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function flattenLineString(coordinates, data, indices, options) {
|
|
46
|
+
indices.push(data.length);
|
|
47
|
+
|
|
48
|
+
var _iterator = _createForOfIteratorHelper(coordinates),
|
|
49
|
+
_step;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
53
|
+
var c = _step.value;
|
|
54
|
+
data.push.apply(data, (0, _toConsumableArray2.default)(c));
|
|
55
|
+
|
|
56
|
+
for (var i = c.length; i < options.coordLength; i++) {
|
|
57
|
+
data.push(0);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
_iterator.e(err);
|
|
62
|
+
} finally {
|
|
63
|
+
_iterator.f();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function flattenPolygon(coordinates, data, indices, areas, options) {
|
|
68
|
+
var count = 0;
|
|
69
|
+
var ringAreas = [];
|
|
70
|
+
var polygons = [];
|
|
71
|
+
|
|
72
|
+
var _iterator2 = _createForOfIteratorHelper(coordinates),
|
|
73
|
+
_step2;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
77
|
+
var lineString = _step2.value;
|
|
78
|
+
var lineString2d = lineString.map(function (p) {
|
|
79
|
+
return p.slice(0, 2);
|
|
80
|
+
});
|
|
81
|
+
var area = (0, _polygon.getPolygonSignedArea)(lineString2d.flat());
|
|
82
|
+
var ccw = area < 0;
|
|
83
|
+
|
|
84
|
+
if (options.fixRingWinding && (count === 0 && !ccw || count > 0 && ccw)) {
|
|
85
|
+
lineString.reverse();
|
|
86
|
+
area = -area;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
ringAreas.push(area);
|
|
90
|
+
flattenLineString(lineString, data, polygons, options);
|
|
91
|
+
count++;
|
|
92
|
+
}
|
|
93
|
+
} catch (err) {
|
|
94
|
+
_iterator2.e(err);
|
|
95
|
+
} finally {
|
|
96
|
+
_iterator2.f();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (count > 0) {
|
|
100
|
+
areas.push(ringAreas);
|
|
101
|
+
indices.push(polygons);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function flattenFeature(feature, options) {
|
|
106
|
+
var geometry = feature.geometry;
|
|
107
|
+
|
|
108
|
+
if (geometry.type === 'GeometryCollection') {
|
|
109
|
+
throw new Error('GeometryCollection type not supported');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
var data = [];
|
|
113
|
+
var indices = [];
|
|
114
|
+
var areas;
|
|
115
|
+
var type;
|
|
116
|
+
|
|
117
|
+
switch (geometry.type) {
|
|
118
|
+
case 'Point':
|
|
119
|
+
type = 'Point';
|
|
120
|
+
flattenPoint(geometry.coordinates, data, indices, options);
|
|
121
|
+
break;
|
|
122
|
+
|
|
123
|
+
case 'MultiPoint':
|
|
124
|
+
type = 'Point';
|
|
125
|
+
geometry.coordinates.map(function (c) {
|
|
126
|
+
return flattenPoint(c, data, indices, options);
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
|
|
130
|
+
case 'LineString':
|
|
131
|
+
type = 'LineString';
|
|
132
|
+
flattenLineString(geometry.coordinates, data, indices, options);
|
|
133
|
+
break;
|
|
134
|
+
|
|
135
|
+
case 'MultiLineString':
|
|
136
|
+
type = 'LineString';
|
|
137
|
+
geometry.coordinates.map(function (c) {
|
|
138
|
+
return flattenLineString(c, data, indices, options);
|
|
139
|
+
});
|
|
140
|
+
break;
|
|
141
|
+
|
|
142
|
+
case 'Polygon':
|
|
143
|
+
type = 'Polygon';
|
|
144
|
+
areas = [];
|
|
145
|
+
flattenPolygon(geometry.coordinates, data, indices, areas, options);
|
|
146
|
+
break;
|
|
147
|
+
|
|
148
|
+
case 'MultiPolygon':
|
|
149
|
+
type = 'Polygon';
|
|
150
|
+
areas = [];
|
|
151
|
+
geometry.coordinates.map(function (c) {
|
|
152
|
+
return flattenPolygon(c, data, indices, areas, options);
|
|
153
|
+
});
|
|
154
|
+
break;
|
|
155
|
+
|
|
156
|
+
default:
|
|
157
|
+
throw new Error("Unknown type: ".concat(type));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return _objectSpread(_objectSpread({}, feature), {}, {
|
|
161
|
+
geometry: {
|
|
162
|
+
type: type,
|
|
163
|
+
indices: indices,
|
|
164
|
+
data: data,
|
|
165
|
+
areas: areas
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=geojson-to-flat-geojson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/geojson-to-flat-geojson.ts"],"names":["geojsonToFlatGeojson","features","options","coordLength","fixRingWinding","map","feature","flattenFeature","flattenPoint","coordinates","data","indices","push","length","i","flattenLineString","c","flattenPolygon","areas","count","ringAreas","polygons","lineString","lineString2d","p","slice","area","flat","ccw","reverse","geometry","type","Error"],"mappings":";;;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D,CAAD,EAAIN,IAAJ,EAAUC,OAAV,EAAmBO,KAAnB,EAA0BhB,OAA1B,CAArB;AAAA,OAAzB;AACA;;AACF;AACE,YAAM,IAAI8B,KAAJ,yBAA2BD,IAA3B,EAAN;AA5BJ;;AA+BA,yCAAWzB,OAAX;AAAoBwB,IAAAA,QAAQ,EAAE;AAACC,MAAAA,IAAI,EAAJA,IAAD;AAAOpB,MAAAA,OAAO,EAAPA,OAAP;AAAgBD,MAAAA,IAAI,EAAJA,IAAhB;AAAsBQ,MAAAA,KAAK,EAALA;AAAtB;AAA9B;AACD","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"],"file":"geojson-to-flat-geojson.js"}
|
|
@@ -6,6 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.transformBinaryCoords = transformBinaryCoords;
|
|
7
7
|
exports.transformGeoJsonCoords = transformGeoJsonCoords;
|
|
8
8
|
|
|
9
|
+
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; } } }; }
|
|
10
|
+
|
|
11
|
+
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); }
|
|
12
|
+
|
|
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
|
+
|
|
9
15
|
function transformBinaryCoords(binaryFeatures, transformCoordinate) {
|
|
10
16
|
if (binaryFeatures.points) {
|
|
11
17
|
transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);
|
|
@@ -23,20 +29,29 @@ function transformBinaryCoords(binaryFeatures, transformCoordinate) {
|
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
function transformBinaryGeometryPositions(binaryGeometry, fn) {
|
|
26
|
-
|
|
27
|
-
positions
|
|
28
|
-
} = binaryGeometry;
|
|
32
|
+
var positions = binaryGeometry.positions;
|
|
29
33
|
|
|
30
|
-
for (
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
for (var i = 0; i < positions.value.length; i += positions.size) {
|
|
35
|
+
var _coord = Array.from(positions.value.subarray(i, i + positions.size));
|
|
36
|
+
|
|
37
|
+
var transformedCoord = fn(_coord);
|
|
33
38
|
positions.value.set(transformedCoord, i);
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
function transformGeoJsonCoords(features, fn) {
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
var _iterator = _createForOfIteratorHelper(features),
|
|
44
|
+
_step;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
48
|
+
var feature = _step.value;
|
|
49
|
+
feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
_iterator.e(err);
|
|
53
|
+
} finally {
|
|
54
|
+
_iterator.f();
|
|
40
55
|
}
|
|
41
56
|
|
|
42
57
|
return features;
|
|
@@ -47,7 +62,7 @@ function coordMap(array, fn) {
|
|
|
47
62
|
return fn(array);
|
|
48
63
|
}
|
|
49
64
|
|
|
50
|
-
return array.map(item
|
|
65
|
+
return array.map(function (item) {
|
|
51
66
|
return coordMap(item, fn);
|
|
52
67
|
});
|
|
53
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/transform.ts"],"names":["transformBinaryCoords","binaryFeatures","transformCoordinate","points","transformBinaryGeometryPositions","lines","polygons","binaryGeometry","fn","positions","i","value","length","size","coord","Array","from","subarray","transformedCoord","set","transformGeoJsonCoords","features","feature","geometry","coordinates","coordMap","array","isCoord","map","item","Number","isFinite"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/transform.ts"],"names":["transformBinaryCoords","binaryFeatures","transformCoordinate","points","transformBinaryGeometryPositions","lines","polygons","binaryGeometry","fn","positions","i","value","length","size","coord","Array","from","subarray","transformedCoord","set","transformGeoJsonCoords","features","feature","geometry","coordinates","coordMap","array","isCoord","map","item","Number","isFinite"],"mappings":";;;;;;;;;;;;;;AAUO,SAASA,qBAAT,CACLC,cADK,EAELC,mBAFK,EAGW;AAChB,MAAID,cAAc,CAACE,MAAnB,EAA2B;AACzBC,IAAAA,gCAAgC,CAACH,cAAc,CAACE,MAAhB,EAAwBD,mBAAxB,CAAhC;AACD;;AACD,MAAID,cAAc,CAACI,KAAnB,EAA0B;AACxBD,IAAAA,gCAAgC,CAACH,cAAc,CAACI,KAAhB,EAAuBH,mBAAvB,CAAhC;AACD;;AACD,MAAID,cAAc,CAACK,QAAnB,EAA6B;AAC3BF,IAAAA,gCAAgC,CAACH,cAAc,CAACK,QAAhB,EAA0BJ,mBAA1B,CAAhC;AACD;;AACD,SAAOD,cAAP;AACD;;AAGD,SAASG,gCAAT,CAA0CG,cAA1C,EAA0EC,EAA1E,EAAmG;AACjG,MAAOC,SAAP,GAAoBF,cAApB,CAAOE,SAAP;;AACA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,SAAS,CAACE,KAAV,CAAgBC,MAApC,EAA4CF,CAAC,IAAID,SAAS,CAACI,IAA3D,EAAiE;AAE/D,QAAMC,MAAoB,GAAGC,KAAK,CAACC,IAAN,CAAWP,SAAS,CAACE,KAAV,CAAgBM,QAAhB,CAAyBP,CAAzB,EAA4BA,CAAC,GAAGD,SAAS,CAACI,IAA1C,CAAX,CAA7B;;AACA,QAAMK,gBAAgB,GAAGV,EAAE,CAACM,MAAD,CAA3B;AAEAL,IAAAA,SAAS,CAACE,KAAV,CAAgBQ,GAAhB,CAAoBD,gBAApB,EAAsCR,CAAtC;AACD;AACF;;AASM,SAASU,sBAAT,CACLC,QADK,EAELb,EAFK,EAGK;AAAA,6CACYa,QADZ;AAAA;;AAAA;AACV,wDAAgC;AAAA,UAArBC,OAAqB;AAE9BA,MAAAA,OAAO,CAACC,QAAR,CAAiBC,WAAjB,GAA+BC,QAAQ,CAACH,OAAO,CAACC,QAAR,CAAiBC,WAAlB,EAA+BhB,EAA/B,CAAvC;AACD;AAJS;AAAA;AAAA;AAAA;AAAA;;AAKV,SAAOa,QAAP;AACD;;AAED,SAASI,QAAT,CAAkBC,KAAlB,EAAyBlB,EAAzB,EAA6B;AAC3B,MAAImB,OAAO,CAACD,KAAD,CAAX,EAAoB;AAClB,WAAOlB,EAAE,CAACkB,KAAD,CAAT;AACD;;AAED,SAAOA,KAAK,CAACE,GAAN,CAAU,UAACC,IAAD,EAAU;AACzB,WAAOJ,QAAQ,CAACI,IAAD,EAAOrB,EAAP,CAAf;AACD,GAFM,CAAP;AAGD;;AAED,SAASmB,OAAT,CAAiBD,KAAjB,EAAwB;AACtB,SAAOI,MAAM,CAACC,QAAP,CAAgBL,KAAK,CAAC,CAAD,CAArB,KAA6BI,MAAM,CAACC,QAAP,CAAgBL,KAAK,CAAC,CAAD,CAArB,CAApC;AACD","sourcesContent":["import type {BinaryFeatures, BinaryGeometry} from '@loaders.gl/schema';\n\ntype TransformCoordinate = (coord: number[]) => number[];\n\n/**\n * Apply transformation to every coordinate of binary features\n * @param binaryFeatures binary features\n * @param transformCoordinate Function to call on each coordinate\n * @return Transformed binary features\n */\nexport function transformBinaryCoords(\n binaryFeatures: BinaryFeatures,\n transformCoordinate: TransformCoordinate\n): BinaryFeatures {\n if (binaryFeatures.points) {\n transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);\n }\n if (binaryFeatures.lines) {\n transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);\n }\n if (binaryFeatures.polygons) {\n transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);\n }\n return binaryFeatures;\n}\n\n/** Transform one binary geometry */\nfunction transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: TransformCoordinate) {\n const {positions} = binaryGeometry;\n for (let i = 0; i < positions.value.length; i += positions.size) {\n // @ts-ignore inclusion of bigint causes problems\n const coord: Array<number> = Array.from(positions.value.subarray(i, i + positions.size));\n const transformedCoord = fn(coord);\n // @ts-ignore typescript typing for .set seems to require bigint?\n positions.value.set(transformedCoord, i);\n }\n}\n\n/**\n * Apply transformation to every coordinate of GeoJSON features\n *\n * @param features Array of GeoJSON features\n * @param fn Function to call on each coordinate\n * @return Transformed GeoJSON features\n */\nexport function transformGeoJsonCoords(\n features: object[],\n fn: (coord: number[]) => number[]\n): object[] {\n for (const feature of features) {\n // @ts-ignore\n feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);\n }\n return features;\n}\n\nfunction coordMap(array, fn) {\n if (isCoord(array)) {\n return fn(array);\n }\n\n return array.map((item) => {\n return coordMap(item, fn);\n });\n}\n\nfunction isCoord(array) {\n return Number.isFinite(array[0]) && Number.isFinite(array[1]);\n}\n"],"file":"transform.js"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { flatGeojsonToBinary } from './lib/flat-geojson-to-binary';
|
|
1
2
|
export { geojsonToBinary } from './lib/geojson-to-binary';
|
|
3
|
+
export { geojsonToFlatGeojson } from './lib/geojson-to-flat-geojson';
|
|
2
4
|
export { binaryToGeojson, binaryToGeoJson, binaryToGeometry } from './lib/binary-to-geojson';
|
|
3
5
|
export { transformBinaryCoords, transformGeoJsonCoords } from './lib/transform';
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["geojsonToBinary","binaryToGeojson","binaryToGeoJson","binaryToGeometry","transformBinaryCoords","transformGeoJsonCoords"],"mappings":"AAGA,SAAQA,eAAR,QAA8B,yBAA9B;AACA,SAAQC,eAAR,EAAyBC,eAAzB,EAA0CC,gBAA1C,QAAiE,yBAAjE;AACA,SAAQC,qBAAR,EAA+BC,sBAA/B,QAA4D,iBAA5D","sourcesContent":["// Types from `@loaders.gl/schema`\n\n// Functions\nexport {geojsonToBinary} from './lib/geojson-to-binary';\nexport {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["flatGeojsonToBinary","geojsonToBinary","geojsonToFlatGeojson","binaryToGeojson","binaryToGeoJson","binaryToGeometry","transformBinaryCoords","transformGeoJsonCoords"],"mappings":"AAGA,SAAQA,mBAAR,QAAkC,8BAAlC;AACA,SAAQC,eAAR,QAA8B,yBAA9B;AACA,SAAQC,oBAAR,QAAmC,+BAAnC;AACA,SAAQC,eAAR,EAAyBC,eAAzB,EAA0CC,gBAA1C,QAAiE,yBAAjE;AACA,SAAQC,qBAAR,EAA+BC,sBAA/B,QAA4D,iBAA5D","sourcesContent":["// Types from `@loaders.gl/schema`\n\n// Functions\nexport {flatGeojsonToBinary} from './lib/flat-geojson-to-binary';\nexport {geojsonToBinary} from './lib/geojson-to-binary';\nexport {geojsonToFlatGeojson} from './lib/geojson-to-flat-geojson';\nexport {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"file":"index.js"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export function extractGeometryInfo(features) {
|
|
2
|
+
let pointPositionsCount = 0;
|
|
3
|
+
let pointFeaturesCount = 0;
|
|
4
|
+
let linePositionsCount = 0;
|
|
5
|
+
let linePathsCount = 0;
|
|
6
|
+
let lineFeaturesCount = 0;
|
|
7
|
+
let polygonPositionsCount = 0;
|
|
8
|
+
let polygonObjectsCount = 0;
|
|
9
|
+
let polygonRingsCount = 0;
|
|
10
|
+
let polygonFeaturesCount = 0;
|
|
11
|
+
const coordLengths = new Set();
|
|
12
|
+
|
|
13
|
+
for (const feature of features) {
|
|
14
|
+
const geometry = feature.geometry;
|
|
15
|
+
|
|
16
|
+
switch (geometry.type) {
|
|
17
|
+
case 'Point':
|
|
18
|
+
pointFeaturesCount++;
|
|
19
|
+
pointPositionsCount++;
|
|
20
|
+
coordLengths.add(geometry.coordinates.length);
|
|
21
|
+
break;
|
|
22
|
+
|
|
23
|
+
case 'MultiPoint':
|
|
24
|
+
pointFeaturesCount++;
|
|
25
|
+
pointPositionsCount += geometry.coordinates.length;
|
|
26
|
+
|
|
27
|
+
for (const point of geometry.coordinates) {
|
|
28
|
+
coordLengths.add(point.length);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
break;
|
|
32
|
+
|
|
33
|
+
case 'LineString':
|
|
34
|
+
lineFeaturesCount++;
|
|
35
|
+
linePositionsCount += geometry.coordinates.length;
|
|
36
|
+
linePathsCount++;
|
|
37
|
+
|
|
38
|
+
for (const coord of geometry.coordinates) {
|
|
39
|
+
coordLengths.add(coord.length);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
break;
|
|
43
|
+
|
|
44
|
+
case 'MultiLineString':
|
|
45
|
+
lineFeaturesCount++;
|
|
46
|
+
|
|
47
|
+
for (const line of geometry.coordinates) {
|
|
48
|
+
linePositionsCount += line.length;
|
|
49
|
+
linePathsCount++;
|
|
50
|
+
|
|
51
|
+
for (const coord of line) {
|
|
52
|
+
coordLengths.add(coord.length);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case 'Polygon':
|
|
59
|
+
polygonFeaturesCount++;
|
|
60
|
+
polygonObjectsCount++;
|
|
61
|
+
polygonRingsCount += geometry.coordinates.length;
|
|
62
|
+
const flattened = geometry.coordinates.flat();
|
|
63
|
+
polygonPositionsCount += flattened.length;
|
|
64
|
+
|
|
65
|
+
for (const coord of flattened) {
|
|
66
|
+
coordLengths.add(coord.length);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case 'MultiPolygon':
|
|
72
|
+
polygonFeaturesCount++;
|
|
73
|
+
|
|
74
|
+
for (const polygon of geometry.coordinates) {
|
|
75
|
+
polygonObjectsCount++;
|
|
76
|
+
polygonRingsCount += polygon.length;
|
|
77
|
+
const flattened = polygon.flat();
|
|
78
|
+
polygonPositionsCount += flattened.length;
|
|
79
|
+
|
|
80
|
+
for (const coord of flattened) {
|
|
81
|
+
coordLengths.add(coord.length);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
break;
|
|
86
|
+
|
|
87
|
+
default:
|
|
88
|
+
throw new Error("Unsupported geometry type: ".concat(geometry.type));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
94
|
+
pointPositionsCount,
|
|
95
|
+
pointFeaturesCount,
|
|
96
|
+
linePositionsCount,
|
|
97
|
+
linePathsCount,
|
|
98
|
+
lineFeaturesCount,
|
|
99
|
+
polygonPositionsCount,
|
|
100
|
+
polygonObjectsCount,
|
|
101
|
+
polygonRingsCount,
|
|
102
|
+
polygonFeaturesCount
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=extract-geometry-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/extract-geometry-info.ts"],"names":["extractGeometryInfo","features","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLengths","Set","feature","geometry","type","add","coordinates","length","point","coord","line","flattened","flat","polygon","Error","coordLength","size","Math","max"],"mappings":"AAQA,OAAO,SAASA,mBAAT,CAA6BC,QAA7B,EAAuE;AAE5E,MAAIC,mBAAmB,GAAG,CAA1B;AACA,MAAIC,kBAAkB,GAAG,CAAzB;AACA,MAAIC,kBAAkB,GAAG,CAAzB;AACA,MAAIC,cAAc,GAAG,CAArB;AACA,MAAIC,iBAAiB,GAAG,CAAxB;AACA,MAAIC,qBAAqB,GAAG,CAA5B;AACA,MAAIC,mBAAmB,GAAG,CAA1B;AACA,MAAIC,iBAAiB,GAAG,CAAxB;AACA,MAAIC,oBAAoB,GAAG,CAA3B;AACA,QAAMC,YAAY,GAAG,IAAIC,GAAJ,EAArB;;AAEA,OAAK,MAAMC,OAAX,IAAsBZ,QAAtB,EAAgC;AAC9B,UAAMa,QAAQ,GAAGD,OAAO,CAACC,QAAzB;;AACA,YAAQA,QAAQ,CAACC,IAAjB;AACE,WAAK,OAAL;AACEZ,QAAAA,kBAAkB;AAClBD,QAAAA,mBAAmB;AACnBS,QAAAA,YAAY,CAACK,GAAb,CAAiBF,QAAQ,CAACG,WAAT,CAAqBC,MAAtC;AACA;;AACF,WAAK,YAAL;AACEf,QAAAA,kBAAkB;AAClBD,QAAAA,mBAAmB,IAAIY,QAAQ,CAACG,WAAT,CAAqBC,MAA5C;;AACA,aAAK,MAAMC,KAAX,IAAoBL,QAAQ,CAACG,WAA7B,EAA0C;AACxCN,UAAAA,YAAY,CAACK,GAAb,CAAiBG,KAAK,CAACD,MAAvB;AACD;;AACD;;AACF,WAAK,YAAL;AACEZ,QAAAA,iBAAiB;AACjBF,QAAAA,kBAAkB,IAAIU,QAAQ,CAACG,WAAT,CAAqBC,MAA3C;AACAb,QAA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J,sCAAwCX,QAAQ,CAACC,IAAjD,EAAN;AA5DJ;AA8DD;;AAED,SAAO;AACLW,IAAAA,WAAW,EAAEf,YAAY,CAACgB,IAAb,GAAoB,CAApB,GAAwBC,IAAI,CAACC,GAAL,CAAS,GAAGlB,YAAZ,CAAxB,GAAoD,CAD5D;AAGLT,IAAAA,mBAHK;AAILC,IAAAA,kBAJK;AAKLC,IAAAA,kBALK;AAMLC,IAAAA,cANK;AAOLC,IAAAA,iBAPK;AAQLC,IAAAA,qBARK;AASLC,IAAAA,mBATK;AAULC,IAAAA,iBAVK;AAWLC,IAAAA;AAXK,GAAP;AAaD","sourcesContent":["import {Feature, GeojsonGeometryInfo} from '@loaders.gl/schema';\n\n/**\n * Initial scan over GeoJSON features\n * Counts number of coordinates of each geometry type and\n * keeps track of the max coordinate dimensions\n */\n// eslint-disable-next-line complexity, max-statements\nexport function extractGeometryInfo(features: Feature[]): GeojsonGeometryInfo {\n // Counts the number of _positions_, so [x, y, z] counts as one\n let pointPositionsCount = 0;\n let pointFeaturesCount = 0;\n let linePositionsCount = 0;\n let linePathsCount = 0;\n let lineFeaturesCount = 0;\n let polygonPositionsCount = 0;\n let polygonObjectsCount = 0;\n let polygonRingsCount = 0;\n let polygonFeaturesCount = 0;\n const coordLengths = new Set<number>();\n\n for (const feature of features) {\n const geometry = feature.geometry;\n switch (geometry.type) {\n case 'Point':\n pointFeaturesCount++;\n pointPositionsCount++;\n coordLengths.add(geometry.coordinates.length);\n break;\n case 'MultiPoint':\n pointFeaturesCount++;\n pointPositionsCount += geometry.coordinates.length;\n for (const point of geometry.coordinates) {\n coordLengths.add(point.length);\n }\n break;\n case 'LineString':\n lineFeaturesCount++;\n linePositionsCount += geometry.coordinates.length;\n linePathsCount++;\n\n for (const coord of geometry.coordinates) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiLineString':\n lineFeaturesCount++;\n for (const line of geometry.coordinates) {\n linePositionsCount += line.length;\n linePathsCount++;\n\n // eslint-disable-next-line max-depth\n for (const coord of line) {\n coordLengths.add(coord.length);\n }\n }\n break;\n case 'Polygon':\n polygonFeaturesCount++;\n polygonObjectsCount++;\n polygonRingsCount += geometry.coordinates.length;\n const flattened = geometry.coordinates.flat();\n polygonPositionsCount += flattened.length;\n\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiPolygon':\n polygonFeaturesCount++;\n for (const polygon of geometry.coordinates) {\n polygonObjectsCount++;\n polygonRingsCount += polygon.length;\n const flattened = polygon.flat();\n polygonPositionsCount += flattened.length;\n\n // eslint-disable-next-line max-depth\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n }\n break;\n default:\n throw new Error(`Unsupported geometry type: ${geometry.type}`);\n }\n }\n\n return {\n coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,\n\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n };\n}\n"],"file":"extract-geometry-info.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"flat-geojson-to-binary-types.js"}
|