@turf/helpers 7.0.0-alpha.1 → 7.0.0-alpha.110
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/README.md +4 -9
- package/dist/cjs/index.cjs +458 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +80 -39
- package/dist/{es/index.js → esm/index.d.mts} +116 -258
- package/dist/esm/index.mjs +458 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +30 -23
- package/dist/es/lib/geojson.js +0 -0
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -687
- package/dist/js/lib/geojson.d.ts +0 -10
- package/dist/js/lib/geojson.js +0 -2
package/README.md
CHANGED
|
@@ -567,26 +567,21 @@ Returns **[boolean][26]** true/false, including false for Arrays and Functions
|
|
|
567
567
|
|
|
568
568
|
[26]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
569
569
|
|
|
570
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
571
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
572
|
-
./scripts/generate-readmes in the turf project. -->
|
|
570
|
+
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
573
571
|
|
|
574
572
|
---
|
|
575
573
|
|
|
576
|
-
This module is part of the [Turfjs project](
|
|
577
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
578
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
579
|
-
PRs and issues.
|
|
574
|
+
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
580
575
|
|
|
581
576
|
### Installation
|
|
582
577
|
|
|
583
|
-
Install this module individually:
|
|
578
|
+
Install this single module individually:
|
|
584
579
|
|
|
585
580
|
```sh
|
|
586
581
|
$ npm install @turf/helpers
|
|
587
582
|
```
|
|
588
583
|
|
|
589
|
-
Or install the
|
|
584
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
590
585
|
|
|
591
586
|
```sh
|
|
592
587
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// lib/geojson-equality.ts
|
|
5
|
+
var _deepequal = require('deep-equal'); var _deepequal2 = _interopRequireDefault(_deepequal);
|
|
6
|
+
var _GeojsonEquality = class _GeojsonEquality {
|
|
7
|
+
constructor(opts) {
|
|
8
|
+
this.direction = false;
|
|
9
|
+
this.compareProperties = true;
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
this.precision = 10 ** -((_a = opts == null ? void 0 : opts.precision) != null ? _a : 17);
|
|
12
|
+
this.direction = (_b = opts == null ? void 0 : opts.direction) != null ? _b : false;
|
|
13
|
+
this.compareProperties = (_c = opts == null ? void 0 : opts.compareProperties) != null ? _c : true;
|
|
14
|
+
}
|
|
15
|
+
compare(g1, g2) {
|
|
16
|
+
if (g1.type !== g2.type) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (!sameLength(g1, g2)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
switch (g1.type) {
|
|
23
|
+
case "Point":
|
|
24
|
+
return this.compareCoord(g1.coordinates, g2.coordinates);
|
|
25
|
+
case "LineString":
|
|
26
|
+
return this.compareLine(g1.coordinates, g2.coordinates);
|
|
27
|
+
case "Polygon":
|
|
28
|
+
return this.comparePolygon(g1, g2);
|
|
29
|
+
case "GeometryCollection":
|
|
30
|
+
return this.compareGeometryCollection(g1, g2);
|
|
31
|
+
case "Feature":
|
|
32
|
+
return this.compareFeature(g1, g2);
|
|
33
|
+
case "FeatureCollection":
|
|
34
|
+
return this.compareFeatureCollection(g1, g2);
|
|
35
|
+
default:
|
|
36
|
+
if (g1.type.startsWith("Multi")) {
|
|
37
|
+
const g1s = explode(g1);
|
|
38
|
+
const g2s = explode(
|
|
39
|
+
g2
|
|
40
|
+
);
|
|
41
|
+
return g1s.every(
|
|
42
|
+
(g1part) => g2s.some((g2part) => this.compare(g1part, g2part))
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
compareCoord(c1, c2) {
|
|
49
|
+
return c1.length === c2.length && c1.every((c, i) => Math.abs(c - c2[i]) < this.precision);
|
|
50
|
+
}
|
|
51
|
+
compareLine(path1, path2, ind = 0, isPoly = false) {
|
|
52
|
+
if (!sameLength(path1, path2)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const p1 = path1;
|
|
56
|
+
let p2 = path2;
|
|
57
|
+
if (isPoly && !this.compareCoord(p1[0], p2[0])) {
|
|
58
|
+
const startIndex = this.fixStartIndex(p2, p1);
|
|
59
|
+
if (!startIndex) {
|
|
60
|
+
return false;
|
|
61
|
+
} else {
|
|
62
|
+
p2 = startIndex;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const sameDirection = this.compareCoord(p1[ind], p2[ind]);
|
|
66
|
+
if (this.direction || sameDirection) {
|
|
67
|
+
return this.comparePath(p1, p2);
|
|
68
|
+
} else {
|
|
69
|
+
if (this.compareCoord(p1[ind], p2[p2.length - (1 + ind)])) {
|
|
70
|
+
return this.comparePath(p1.slice().reverse(), p2);
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
fixStartIndex(sourcePath, targetPath) {
|
|
76
|
+
let correctPath, ind = -1;
|
|
77
|
+
for (let i = 0; i < sourcePath.length; i++) {
|
|
78
|
+
if (this.compareCoord(sourcePath[i], targetPath[0])) {
|
|
79
|
+
ind = i;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (ind >= 0) {
|
|
84
|
+
correctPath = [].concat(
|
|
85
|
+
sourcePath.slice(ind, sourcePath.length),
|
|
86
|
+
sourcePath.slice(1, ind + 1)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return correctPath;
|
|
90
|
+
}
|
|
91
|
+
comparePath(p1, p2) {
|
|
92
|
+
return p1.every((c, i) => this.compareCoord(c, p2[i]));
|
|
93
|
+
}
|
|
94
|
+
comparePolygon(g1, g2) {
|
|
95
|
+
if (this.compareLine(g1.coordinates[0], g2.coordinates[0], 1, true)) {
|
|
96
|
+
const holes1 = g1.coordinates.slice(1, g1.coordinates.length);
|
|
97
|
+
const holes2 = g2.coordinates.slice(1, g2.coordinates.length);
|
|
98
|
+
return holes1.every(
|
|
99
|
+
(h1) => holes2.some((h2) => this.compareLine(h1, h2, 1, true))
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
compareGeometryCollection(g1, g2) {
|
|
105
|
+
return sameLength(g1.geometries, g2.geometries) && this.compareBBox(g1, g2) && g1.geometries.every((g, i) => this.compare(g, g2.geometries[i]));
|
|
106
|
+
}
|
|
107
|
+
compareFeature(g1, g2) {
|
|
108
|
+
return g1.id === g2.id && (this.compareProperties ? _deepequal2.default.call(void 0, g1.properties, g2.properties) : true) && this.compareBBox(g1, g2) && this.compare(g1.geometry, g2.geometry);
|
|
109
|
+
}
|
|
110
|
+
compareFeatureCollection(g1, g2) {
|
|
111
|
+
return sameLength(g1.features, g2.features) && this.compareBBox(g1, g2) && g1.features.every((f, i) => this.compare(f, g2.features[i]));
|
|
112
|
+
}
|
|
113
|
+
compareBBox(g1, g2) {
|
|
114
|
+
return Boolean(!g1.bbox && !g2.bbox) || (g1.bbox && g2.bbox ? this.compareCoord(g1.bbox, g2.bbox) : false);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
__name(_GeojsonEquality, "GeojsonEquality");
|
|
118
|
+
var GeojsonEquality = _GeojsonEquality;
|
|
119
|
+
function sameLength(g1, g2) {
|
|
120
|
+
return g1.coordinates ? g1.coordinates.length === g2.coordinates.length : g1.length === g2.length;
|
|
121
|
+
}
|
|
122
|
+
__name(sameLength, "sameLength");
|
|
123
|
+
function explode(g) {
|
|
124
|
+
return g.coordinates.map((part) => ({
|
|
125
|
+
type: g.type.replace("Multi", ""),
|
|
126
|
+
coordinates: part
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
__name(explode, "explode");
|
|
130
|
+
|
|
131
|
+
// index.ts
|
|
132
|
+
var earthRadius = 63710088e-1;
|
|
133
|
+
var factors = {
|
|
134
|
+
centimeters: earthRadius * 100,
|
|
135
|
+
centimetres: earthRadius * 100,
|
|
136
|
+
degrees: 360 / (2 * Math.PI),
|
|
137
|
+
feet: earthRadius * 3.28084,
|
|
138
|
+
inches: earthRadius * 39.37,
|
|
139
|
+
kilometers: earthRadius / 1e3,
|
|
140
|
+
kilometres: earthRadius / 1e3,
|
|
141
|
+
meters: earthRadius,
|
|
142
|
+
metres: earthRadius,
|
|
143
|
+
miles: earthRadius / 1609.344,
|
|
144
|
+
millimeters: earthRadius * 1e3,
|
|
145
|
+
millimetres: earthRadius * 1e3,
|
|
146
|
+
nauticalmiles: earthRadius / 1852,
|
|
147
|
+
radians: 1,
|
|
148
|
+
yards: earthRadius * 1.0936
|
|
149
|
+
};
|
|
150
|
+
var areaFactors = {
|
|
151
|
+
acres: 247105e-9,
|
|
152
|
+
centimeters: 1e4,
|
|
153
|
+
centimetres: 1e4,
|
|
154
|
+
feet: 10.763910417,
|
|
155
|
+
hectares: 1e-4,
|
|
156
|
+
inches: 1550.003100006,
|
|
157
|
+
kilometers: 1e-6,
|
|
158
|
+
kilometres: 1e-6,
|
|
159
|
+
meters: 1,
|
|
160
|
+
metres: 1,
|
|
161
|
+
miles: 386e-9,
|
|
162
|
+
nauticalmiles: 29155334959812285e-23,
|
|
163
|
+
millimeters: 1e6,
|
|
164
|
+
millimetres: 1e6,
|
|
165
|
+
yards: 1.195990046
|
|
166
|
+
};
|
|
167
|
+
function feature(geom, properties, options = {}) {
|
|
168
|
+
const feat = { type: "Feature" };
|
|
169
|
+
if (options.id === 0 || options.id) {
|
|
170
|
+
feat.id = options.id;
|
|
171
|
+
}
|
|
172
|
+
if (options.bbox) {
|
|
173
|
+
feat.bbox = options.bbox;
|
|
174
|
+
}
|
|
175
|
+
feat.properties = properties || {};
|
|
176
|
+
feat.geometry = geom;
|
|
177
|
+
return feat;
|
|
178
|
+
}
|
|
179
|
+
__name(feature, "feature");
|
|
180
|
+
function geometry(type, coordinates, _options = {}) {
|
|
181
|
+
switch (type) {
|
|
182
|
+
case "Point":
|
|
183
|
+
return point(coordinates).geometry;
|
|
184
|
+
case "LineString":
|
|
185
|
+
return lineString(coordinates).geometry;
|
|
186
|
+
case "Polygon":
|
|
187
|
+
return polygon(coordinates).geometry;
|
|
188
|
+
case "MultiPoint":
|
|
189
|
+
return multiPoint(coordinates).geometry;
|
|
190
|
+
case "MultiLineString":
|
|
191
|
+
return multiLineString(coordinates).geometry;
|
|
192
|
+
case "MultiPolygon":
|
|
193
|
+
return multiPolygon(coordinates).geometry;
|
|
194
|
+
default:
|
|
195
|
+
throw new Error(type + " is invalid");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
__name(geometry, "geometry");
|
|
199
|
+
function point(coordinates, properties, options = {}) {
|
|
200
|
+
if (!coordinates) {
|
|
201
|
+
throw new Error("coordinates is required");
|
|
202
|
+
}
|
|
203
|
+
if (!Array.isArray(coordinates)) {
|
|
204
|
+
throw new Error("coordinates must be an Array");
|
|
205
|
+
}
|
|
206
|
+
if (coordinates.length < 2) {
|
|
207
|
+
throw new Error("coordinates must be at least 2 numbers long");
|
|
208
|
+
}
|
|
209
|
+
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {
|
|
210
|
+
throw new Error("coordinates must contain numbers");
|
|
211
|
+
}
|
|
212
|
+
const geom = {
|
|
213
|
+
type: "Point",
|
|
214
|
+
coordinates
|
|
215
|
+
};
|
|
216
|
+
return feature(geom, properties, options);
|
|
217
|
+
}
|
|
218
|
+
__name(point, "point");
|
|
219
|
+
function points(coordinates, properties, options = {}) {
|
|
220
|
+
return featureCollection(
|
|
221
|
+
coordinates.map((coords) => {
|
|
222
|
+
return point(coords, properties);
|
|
223
|
+
}),
|
|
224
|
+
options
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
__name(points, "points");
|
|
228
|
+
function polygon(coordinates, properties, options = {}) {
|
|
229
|
+
for (const ring of coordinates) {
|
|
230
|
+
if (ring.length < 4) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
"Each LinearRing of a Polygon must have 4 or more Positions."
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
if (ring[ring.length - 1].length !== ring[0].length) {
|
|
236
|
+
throw new Error("First and last Position are not equivalent.");
|
|
237
|
+
}
|
|
238
|
+
for (let j = 0; j < ring[ring.length - 1].length; j++) {
|
|
239
|
+
if (ring[ring.length - 1][j] !== ring[0][j]) {
|
|
240
|
+
throw new Error("First and last Position are not equivalent.");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const geom = {
|
|
245
|
+
type: "Polygon",
|
|
246
|
+
coordinates
|
|
247
|
+
};
|
|
248
|
+
return feature(geom, properties, options);
|
|
249
|
+
}
|
|
250
|
+
__name(polygon, "polygon");
|
|
251
|
+
function polygons(coordinates, properties, options = {}) {
|
|
252
|
+
return featureCollection(
|
|
253
|
+
coordinates.map((coords) => {
|
|
254
|
+
return polygon(coords, properties);
|
|
255
|
+
}),
|
|
256
|
+
options
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
__name(polygons, "polygons");
|
|
260
|
+
function lineString(coordinates, properties, options = {}) {
|
|
261
|
+
if (coordinates.length < 2) {
|
|
262
|
+
throw new Error("coordinates must be an array of two or more positions");
|
|
263
|
+
}
|
|
264
|
+
const geom = {
|
|
265
|
+
type: "LineString",
|
|
266
|
+
coordinates
|
|
267
|
+
};
|
|
268
|
+
return feature(geom, properties, options);
|
|
269
|
+
}
|
|
270
|
+
__name(lineString, "lineString");
|
|
271
|
+
function lineStrings(coordinates, properties, options = {}) {
|
|
272
|
+
return featureCollection(
|
|
273
|
+
coordinates.map((coords) => {
|
|
274
|
+
return lineString(coords, properties);
|
|
275
|
+
}),
|
|
276
|
+
options
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
__name(lineStrings, "lineStrings");
|
|
280
|
+
function featureCollection(features, options = {}) {
|
|
281
|
+
const fc = { type: "FeatureCollection" };
|
|
282
|
+
if (options.id) {
|
|
283
|
+
fc.id = options.id;
|
|
284
|
+
}
|
|
285
|
+
if (options.bbox) {
|
|
286
|
+
fc.bbox = options.bbox;
|
|
287
|
+
}
|
|
288
|
+
fc.features = features;
|
|
289
|
+
return fc;
|
|
290
|
+
}
|
|
291
|
+
__name(featureCollection, "featureCollection");
|
|
292
|
+
function multiLineString(coordinates, properties, options = {}) {
|
|
293
|
+
const geom = {
|
|
294
|
+
type: "MultiLineString",
|
|
295
|
+
coordinates
|
|
296
|
+
};
|
|
297
|
+
return feature(geom, properties, options);
|
|
298
|
+
}
|
|
299
|
+
__name(multiLineString, "multiLineString");
|
|
300
|
+
function multiPoint(coordinates, properties, options = {}) {
|
|
301
|
+
const geom = {
|
|
302
|
+
type: "MultiPoint",
|
|
303
|
+
coordinates
|
|
304
|
+
};
|
|
305
|
+
return feature(geom, properties, options);
|
|
306
|
+
}
|
|
307
|
+
__name(multiPoint, "multiPoint");
|
|
308
|
+
function multiPolygon(coordinates, properties, options = {}) {
|
|
309
|
+
const geom = {
|
|
310
|
+
type: "MultiPolygon",
|
|
311
|
+
coordinates
|
|
312
|
+
};
|
|
313
|
+
return feature(geom, properties, options);
|
|
314
|
+
}
|
|
315
|
+
__name(multiPolygon, "multiPolygon");
|
|
316
|
+
function geometryCollection(geometries, properties, options = {}) {
|
|
317
|
+
const geom = {
|
|
318
|
+
type: "GeometryCollection",
|
|
319
|
+
geometries
|
|
320
|
+
};
|
|
321
|
+
return feature(geom, properties, options);
|
|
322
|
+
}
|
|
323
|
+
__name(geometryCollection, "geometryCollection");
|
|
324
|
+
function round(num, precision = 0) {
|
|
325
|
+
if (precision && !(precision >= 0)) {
|
|
326
|
+
throw new Error("precision must be a positive number");
|
|
327
|
+
}
|
|
328
|
+
const multiplier = Math.pow(10, precision || 0);
|
|
329
|
+
return Math.round(num * multiplier) / multiplier;
|
|
330
|
+
}
|
|
331
|
+
__name(round, "round");
|
|
332
|
+
function radiansToLength(radians, units = "kilometers") {
|
|
333
|
+
const factor = factors[units];
|
|
334
|
+
if (!factor) {
|
|
335
|
+
throw new Error(units + " units is invalid");
|
|
336
|
+
}
|
|
337
|
+
return radians * factor;
|
|
338
|
+
}
|
|
339
|
+
__name(radiansToLength, "radiansToLength");
|
|
340
|
+
function lengthToRadians(distance, units = "kilometers") {
|
|
341
|
+
const factor = factors[units];
|
|
342
|
+
if (!factor) {
|
|
343
|
+
throw new Error(units + " units is invalid");
|
|
344
|
+
}
|
|
345
|
+
return distance / factor;
|
|
346
|
+
}
|
|
347
|
+
__name(lengthToRadians, "lengthToRadians");
|
|
348
|
+
function lengthToDegrees(distance, units) {
|
|
349
|
+
return radiansToDegrees(lengthToRadians(distance, units));
|
|
350
|
+
}
|
|
351
|
+
__name(lengthToDegrees, "lengthToDegrees");
|
|
352
|
+
function bearingToAzimuth(bearing) {
|
|
353
|
+
let angle = bearing % 360;
|
|
354
|
+
if (angle < 0) {
|
|
355
|
+
angle += 360;
|
|
356
|
+
}
|
|
357
|
+
return angle;
|
|
358
|
+
}
|
|
359
|
+
__name(bearingToAzimuth, "bearingToAzimuth");
|
|
360
|
+
function radiansToDegrees(radians) {
|
|
361
|
+
const degrees = radians % (2 * Math.PI);
|
|
362
|
+
return degrees * 180 / Math.PI;
|
|
363
|
+
}
|
|
364
|
+
__name(radiansToDegrees, "radiansToDegrees");
|
|
365
|
+
function degreesToRadians(degrees) {
|
|
366
|
+
const radians = degrees % 360;
|
|
367
|
+
return radians * Math.PI / 180;
|
|
368
|
+
}
|
|
369
|
+
__name(degreesToRadians, "degreesToRadians");
|
|
370
|
+
function convertLength(length, originalUnit = "kilometers", finalUnit = "kilometers") {
|
|
371
|
+
if (!(length >= 0)) {
|
|
372
|
+
throw new Error("length must be a positive number");
|
|
373
|
+
}
|
|
374
|
+
return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
|
|
375
|
+
}
|
|
376
|
+
__name(convertLength, "convertLength");
|
|
377
|
+
function convertArea(area, originalUnit = "meters", finalUnit = "kilometers") {
|
|
378
|
+
if (!(area >= 0)) {
|
|
379
|
+
throw new Error("area must be a positive number");
|
|
380
|
+
}
|
|
381
|
+
const startFactor = areaFactors[originalUnit];
|
|
382
|
+
if (!startFactor) {
|
|
383
|
+
throw new Error("invalid original units");
|
|
384
|
+
}
|
|
385
|
+
const finalFactor = areaFactors[finalUnit];
|
|
386
|
+
if (!finalFactor) {
|
|
387
|
+
throw new Error("invalid final units");
|
|
388
|
+
}
|
|
389
|
+
return area / startFactor * finalFactor;
|
|
390
|
+
}
|
|
391
|
+
__name(convertArea, "convertArea");
|
|
392
|
+
function isNumber(num) {
|
|
393
|
+
return !isNaN(num) && num !== null && !Array.isArray(num);
|
|
394
|
+
}
|
|
395
|
+
__name(isNumber, "isNumber");
|
|
396
|
+
function isObject(input) {
|
|
397
|
+
return input !== null && typeof input === "object" && !Array.isArray(input);
|
|
398
|
+
}
|
|
399
|
+
__name(isObject, "isObject");
|
|
400
|
+
function validateBBox(bbox) {
|
|
401
|
+
if (!bbox) {
|
|
402
|
+
throw new Error("bbox is required");
|
|
403
|
+
}
|
|
404
|
+
if (!Array.isArray(bbox)) {
|
|
405
|
+
throw new Error("bbox must be an Array");
|
|
406
|
+
}
|
|
407
|
+
if (bbox.length !== 4 && bbox.length !== 6) {
|
|
408
|
+
throw new Error("bbox must be an Array of 4 or 6 numbers");
|
|
409
|
+
}
|
|
410
|
+
bbox.forEach((num) => {
|
|
411
|
+
if (!isNumber(num)) {
|
|
412
|
+
throw new Error("bbox must only contain numbers");
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
__name(validateBBox, "validateBBox");
|
|
417
|
+
function validateId(id) {
|
|
418
|
+
if (!id) {
|
|
419
|
+
throw new Error("id is required");
|
|
420
|
+
}
|
|
421
|
+
if (["string", "number"].indexOf(typeof id) === -1) {
|
|
422
|
+
throw new Error("id must be a number or a string");
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
__name(validateId, "validateId");
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
exports.GeojsonEquality = GeojsonEquality; exports.areaFactors = areaFactors; exports.bearingToAzimuth = bearingToAzimuth; exports.convertArea = convertArea; exports.convertLength = convertLength; exports.degreesToRadians = degreesToRadians; exports.earthRadius = earthRadius; exports.factors = factors; exports.feature = feature; exports.featureCollection = featureCollection; exports.geometry = geometry; exports.geometryCollection = geometryCollection; exports.isNumber = isNumber; exports.isObject = isObject; exports.lengthToDegrees = lengthToDegrees; exports.lengthToRadians = lengthToRadians; exports.lineString = lineString; exports.lineStrings = lineStrings; exports.multiLineString = multiLineString; exports.multiPoint = multiPoint; exports.multiPolygon = multiPolygon; exports.point = point; exports.points = points; exports.polygon = polygon; exports.polygons = polygons; exports.radiansToDegrees = radiansToDegrees; exports.radiansToLength = radiansToLength; exports.round = round; exports.validateBBox = validateBBox; exports.validateId = validateId;
|
|
458
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../lib/geojson-equality.ts","../../index.ts"],"names":[],"mappings":";;;;AAaA,OAAO,WAAW;AAUX,IAAM,mBAAN,MAAM,iBAAgB;AAAA,EAK3B,YAAY,MAIT;AAPH,SAAQ,YAAY;AACpB,SAAQ,oBAAoB;AA1B9B;AAiCI,SAAK,YAAY,MAAM,GAAE,kCAAM,cAAN,YAAmB;AAC5C,SAAK,aAAY,kCAAM,cAAN,YAAmB;AACpC,SAAK,qBAAoB,kCAAM,sBAAN,YAA2B;AAAA,EACtD;AAAA,EAEA,QAAQ,IAAa,IAAsB;AACzC,QAAI,GAAG,SAAS,GAAG,MAAM;AACvB,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,WAAW,IAAI,EAAE,GAAG;AACvB,aAAO;AAAA,IACT;AAEA,YAAQ,GAAG,MAAM;AAAA,MACf,KAAK;AACH,eAAO,KAAK,aAAa,GAAG,aAAc,GAAa,WAAW;AAAA,MACpE,KAAK;AACH,eAAO,KAAK,YAAY,GAAG,aAAc,GAAkB,WAAW;AAAA,MACxE,KAAK;AACH,eAAO,KAAK,eAAe,IAAI,EAAa;AAAA,MAC9C,KAAK;AACH,eAAO,KAAK,0BAA0B,IAAI,EAAwB;AAAA,MACpE,KAAK;AACH,eAAO,KAAK,eAAe,IAAI,EAAa;AAAA,MAC9C,KAAK;AACH,eAAO,KAAK,yBAAyB,IAAI,EAAuB;AAAA,MAClE;AACE,YAAI,GAAG,KAAK,WAAW,OAAO,GAAG;AAC/B,gBAAM,MAAM,QAAQ,EAAE;AACtB,gBAAM,MAAM;AAAA,YACV;AAAA,UACF;AACA,iBAAO,IAAI;AAAA,Y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YAAY,SAAS;AACzC,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAEA,SAAQ,OAAO,cAAe;AAChC;AApBgB;AAiCT,SAAS,SAAS,KAAmB;AAC1C,SAAO,CAAC,MAAM,GAAG,KAAK,QAAQ,QAAQ,CAAC,MAAM,QAAQ,GAAG;AAC1D;AAFgB;AAeT,SAAS,SAAS,OAAqB;AAC5C,SAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAFgB;AAyBT,SAAS,aAAa,MAAiB;AAC5C,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACpC;AACA,MAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACxB,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC;AACA,MAAI,KAAK,WAAW,KAAK,KAAK,WAAW,GAAG;AAC1C,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA,OAAK,QAAQ,CAAC,QAAQ;AACpB,QAAI,CAAC,SAAS,GAAG,GAAG;AAClB,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AAAA,EACF,CAAC;AACH;AAfgB;AAsCT,SAAS,WAAW,IAAe;AACxC,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,gBAAgB;AAAA,EAClC;AACA,MAAI,CAAC,UAAU,QAAQ,EAAE,QAAQ,OAAO,EAAE,MAAM,IAAI;AAClD,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACF;AAPgB","sourcesContent":["import {\n Feature,\n LineString,\n Position,\n GeoJSON,\n Point,\n Polygon,\n GeometryCollection,\n FeatureCollection,\n MultiLineString,\n MultiPoint,\n MultiPolygon,\n} from \"geojson\";\nimport equal from \"deep-equal\";\n\n/**\n\n * GeoJSON equality checking utility.\n * Adapted from https://github.com/geosquare/geojson-equality\n *\n * @memberof helpers\n * @type {Class}\n */\nexport class GeojsonEquality {\n private precision: number;\n private direction = false;\n private compareProperties = true;\n\n constructor(opts?: {\n precision?: number;\n direction?: boolean;\n compareProperties?: boolean;\n }) {\n this.precision = 10 ** -(opts?.precision ?? 17);\n this.direction = opts?.direction ?? false;\n this.compareProperties = opts?.compareProperties ?? true;\n }\n\n compare(g1: GeoJSON, g2: GeoJSON): boolean {\n if (g1.type !== g2.type) {\n return false;\n }\n\n if (!sameLength(g1, g2)) {\n return false;\n }\n\n switch (g1.type) {\n case \"Point\":\n return this.compareCoord(g1.coordinates, (g2 as Point).coordinates);\n case \"LineString\":\n return this.compareLine(g1.coordinates, (g2 as LineString).coordinates);\n case \"Polygon\":\n return this.comparePolygon(g1, g2 as Polygon);\n case \"GeometryCollection\":\n return this.compareGeometryCollection(g1, g2 as GeometryCollection);\n case \"Feature\":\n return this.compareFeature(g1, g2 as Feature);\n case \"FeatureCollection\":\n return this.compareFeatureCollection(g1, g2 as FeatureCollection);\n default:\n if (g1.type.startsWith(\"Multi\")) {\n const g1s = explode(g1);\n const g2s = explode(\n g2 as MultiLineString | MultiPoint | MultiPolygon\n );\n return g1s.every((g1part) =>\n g2s.some((g2part) => this.compare(g1part as any, g2part as any))\n );\n }\n }\n return false;\n }\n\n private compareCoord(c1: Position, c2: Position) {\n return (\n c1.length === c2.length &&\n c1.every((c, i) => Math.abs(c - c2[i]) < this.precision)\n );\n }\n\n private compareLine(\n path1: Position[],\n path2: Position[],\n ind = 0,\n isPoly = false\n ): boolean {\n if (!sameLength(path1, path2)) {\n return false;\n }\n const p1 = path1;\n let p2 = path2;\n if (isPoly && !this.compareCoord(p1[0], p2[0])) {\n // fix start index of both to same point\n const startIndex = this.fixStartIndex(p2, p1);\n if (!startIndex) {\n return false;\n } else {\n p2 = startIndex;\n }\n }\n // for linestring ind =0 and for polygon ind =1\n const sameDirection = this.compareCoord(p1[ind], p2[ind]);\n if (this.direction || sameDirection) {\n return this.comparePath(p1, p2);\n } else {\n if (this.compareCoord(p1[ind], p2[p2.length - (1 + ind)])) {\n return this.comparePath(p1.slice().reverse(), p2);\n }\n return false;\n }\n }\n\n private fixStartIndex(sourcePath: Position[], targetPath: Position[]) {\n //make sourcePath first point same as of targetPath\n let correctPath,\n ind = -1;\n for (let i = 0; i < sourcePath.length; i++) {\n if (this.compareCoord(sourcePath[i], targetPath[0])) {\n ind = i;\n break;\n }\n }\n if (ind >= 0) {\n correctPath = ([] as Position[]).concat(\n sourcePath.slice(ind, sourcePath.length),\n sourcePath.slice(1, ind + 1)\n );\n }\n return correctPath;\n }\n\n private comparePath(p1: Position[], p2: Position[]) {\n return p1.every((c, i) => this.compareCoord(c, p2[i]));\n }\n\n private comparePolygon(g1: Polygon, g2: Polygon) {\n if (this.compareLine(g1.coordinates[0], g2.coordinates[0], 1, true)) {\n const holes1 = g1.coordinates.slice(1, g1.coordinates.length);\n const holes2 = g2.coordinates.slice(1, g2.coordinates.length);\n return holes1.every((h1) =>\n holes2.some((h2) => this.compareLine(h1, h2, 1, true))\n );\n }\n return false;\n }\n\n private compareGeometryCollection(\n g1: GeometryCollection,\n g2: GeometryCollection\n ) {\n return (\n sameLength(g1.geometries, g2.geometries) &&\n this.compareBBox(g1, g2) &&\n g1.geometries.every((g, i) => this.compare(g, g2.geometries[i]))\n );\n }\n\n private compareFeature(g1: Feature, g2: Feature) {\n return (\n g1.id === g2.id &&\n (this.compareProperties ? equal(g1.properties, g2.properties) : true) &&\n this.compareBBox(g1, g2) &&\n this.compare(g1.geometry, g2.geometry)\n );\n }\n\n private compareFeatureCollection(\n g1: FeatureCollection,\n g2: FeatureCollection\n ) {\n return (\n sameLength(g1.features, g2.features) &&\n this.compareBBox(g1, g2) &&\n g1.features.every((f, i) => this.compare(f, g2.features[i]))\n );\n }\n\n private compareBBox(g1: GeoJSON, g2: GeoJSON): boolean {\n return (\n Boolean(!g1.bbox && !g2.bbox) ||\n (g1.bbox && g2.bbox ? this.compareCoord(g1.bbox, g2.bbox) : false)\n );\n }\n}\n\nfunction sameLength(g1: any, g2: any) {\n return g1.coordinates\n ? g1.coordinates.length === g2.coordinates.length\n : g1.length === g2.length;\n}\n\nfunction explode(g: MultiLineString | MultiPoint | MultiPolygon) {\n return g.coordinates.map((part) => ({\n type: g.type.replace(\"Multi\", \"\"),\n coordinates: part,\n }));\n}\n","import {\n BBox,\n Feature,\n FeatureCollection,\n Geometry,\n GeometryCollection,\n GeometryObject,\n LineString,\n MultiLineString,\n MultiPoint,\n MultiPolygon,\n Point,\n Polygon,\n Position,\n GeoJsonProperties,\n} from \"geojson\";\n\nimport { Id } from \"./lib/geojson\";\nexport * from \"./lib/geojson\";\nexport * from \"./lib/geojson-equality\";\n\n// TurfJS Combined Types\nexport type Coord = Feature<Point> | Point | Position;\n\n// TurfJS String Types\nexport type Units =\n | \"meters\"\n | \"metres\"\n | \"millimeters\"\n | \"millimetres\"\n | \"centimeters\"\n | \"centimetres\"\n | \"kilometers\"\n | \"kilometres\"\n | \"miles\"\n | \"nauticalmiles\"\n | \"inches\"\n | \"yards\"\n | \"feet\"\n | \"radians\"\n | \"degrees\";\nexport type AreaUnits =\n | Exclude<Units, \"radians\" | \"degrees\">\n | \"acres\"\n | \"hectares\";\nexport type Grid = \"point\" | \"square\" | \"hex\" | \"triangle\";\nexport type Corners = \"sw\" | \"se\" | \"nw\" | \"ne\" | \"center\" | \"centroid\";\n\nexport type Lines = LineString | MultiLineString | Polygon | MultiPolygon;\nexport type AllGeoJSON =\n | Feature\n | FeatureCollection\n | Geometry\n | GeometryCollection;\n\n/**\n * @module helpers\n */\n\n/**\n * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.\n *\n * @memberof helpers\n * @type {number}\n */\nexport const earthRadius = 6371008.8;\n\n/**\n * Unit of measurement factors using a spherical (non-ellipsoid) earth radius.\n *\n * Keys are the name of the unit, values are the number of that unit in a single radian\n *\n * @memberof helpers\n * @type {Object}\n */\nexport const factors: Record<Units, number> = {\n centimeters: earthRadius * 100,\n centimetres: earthRadius * 100,\n degrees: 360 / (2 * Math.PI),\n feet: earthRadius * 3.28084,\n inches: earthRadius * 39.37,\n kilometers: earthRadius / 1000,\n kilometres: earthRadius / 1000,\n meters: earthRadius,\n metres: earthRadius,\n miles: earthRadius / 1609.344,\n millimeters: earthRadius * 1000,\n millimetres: earthRadius * 1000,\n nauticalmiles: earthRadius / 1852,\n radians: 1,\n yards: earthRadius * 1.0936,\n};\n\n/**\n\n * Area of measurement factors based on 1 square meter.\n *\n * @memberof helpers\n * @type {Object}\n */\nexport const areaFactors: Record<AreaUnits, number> = {\n acres: 0.000247105,\n centimeters: 10000,\n centimetres: 10000,\n feet: 10.763910417,\n hectares: 0.0001,\n inches: 1550.003100006,\n kilometers: 0.000001,\n kilometres: 0.000001,\n meters: 1,\n metres: 1,\n miles: 3.86e-7,\n nauticalmiles: 2.9155334959812285e-7,\n millimeters: 1000000,\n millimetres: 1000000,\n yards: 1.195990046,\n};\n\n/**\n * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.\n *\n * @name feature\n * @param {Geometry} geometry input geometry\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a GeoJSON Feature\n * @example\n * var geometry = {\n * \"type\": \"Point\",\n * \"coordinates\": [110, 50]\n * };\n *\n * var feature = turf.feature(geometry);\n *\n * //=feature\n */\nexport function feature<\n G extends GeometryObject = Geometry,\n P extends GeoJsonProperties = GeoJsonProperties,\n>(\n geom: G | null,\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): Feature<G, P> {\n const feat: any = { type: \"Feature\" };\n if (options.id === 0 || options.id) {\n feat.id = options.id;\n }\n if (options.bbox) {\n feat.bbox = options.bbox;\n }\n feat.properties = properties || {};\n feat.geometry = geom;\n return feat;\n}\n\n/**\n * Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.\n * For GeometryCollection type use `helpers.geometryCollection`\n *\n * @name geometry\n * @param {string} type Geometry Type\n * @param {Array<any>} coordinates Coordinates\n * @param {Object} [options={}] Optional Parameters\n * @returns {Geometry} a GeoJSON Geometry\n * @example\n * var type = \"Point\";\n * var coordinates = [110, 50];\n * var geometry = turf.geometry(type, coordinates);\n * // => geometry\n */\nexport function geometry(\n type:\n | \"Point\"\n | \"LineString\"\n | \"Polygon\"\n | \"MultiPoint\"\n | \"MultiLineString\"\n | \"MultiPolygon\",\n coordinates: any[],\n _options: Record<string, never> = {}\n) {\n switch (type) {\n case \"Point\":\n return point(coordinates).geometry;\n case \"LineString\":\n return lineString(coordinates).geometry;\n case \"Polygon\":\n return polygon(coordinates).geometry;\n case \"MultiPoint\":\n return multiPoint(coordinates).geometry;\n case \"MultiLineString\":\n return multiLineString(coordinates).geometry;\n case \"MultiPolygon\":\n return multiPolygon(coordinates).geometry;\n default:\n throw new Error(type + \" is invalid\");\n }\n}\n\n/**\n * Creates a {@link Point} {@link Feature} from a Position.\n *\n * @name point\n * @param {Array<number>} coordinates longitude, latitude position (each in decimal degrees)\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<Point>} a Point feature\n * @example\n * var point = turf.point([-75.343, 39.984]);\n *\n * //=point\n */\nexport function point<P extends GeoJsonProperties = GeoJsonProperties>(\n coordinates: Position,\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): Feature<Point, P> {\n if (!coordinates) {\n throw new Error(\"coordinates is required\");\n }\n if (!Array.isArray(coordinates)) {\n throw new Error(\"coordinates must be an Array\");\n }\n if (coordinates.length < 2) {\n throw new Error(\"coordinates must be at least 2 numbers long\");\n }\n if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {\n throw new Error(\"coordinates must contain numbers\");\n }\n\n const geom: Point = {\n type: \"Point\",\n coordinates,\n };\n return feature(geom, properties, options);\n}\n\n/**\n * Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.\n *\n * @name points\n * @param {Array<Array<number>>} coordinates an array of Points\n * @param {Object} [properties={}] Translate these properties to each Feature\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]\n * associated with the FeatureCollection\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection<Point>} Point Feature\n * @example\n * var points = turf.points([\n * [-75, 39],\n * [-80, 45],\n * [-78, 50]\n * ]);\n *\n * //=points\n */\nexport function points<P extends GeoJsonProperties = GeoJsonProperties>(\n coordinates: Position[],\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): FeatureCollection<Point, P> {\n return featureCollection(\n coordinates.map((coords) => {\n return point(coords, properties);\n }),\n options\n );\n}\n\n/**\n * Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.\n *\n * @name polygon\n * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<Polygon>} Polygon Feature\n * @example\n * var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });\n *\n * //=polygon\n */\nexport function polygon<P extends GeoJsonProperties = GeoJsonProperties>(\n coordinates: Position[][],\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): Feature<Polygon, P> {\n for (const ring of coordinates) {\n if (ring.length < 4) {\n throw new Error(\n \"Each LinearRing of a Polygon must have 4 or more Positions.\"\n );\n }\n\n if (ring[ring.length - 1].length !== ring[0].length) {\n throw new Error(\"First and last Position are not equivalent.\");\n }\n\n for (let j = 0; j < ring[ring.length - 1].length; j++) {\n // Check if first point of Polygon contains two numbers\n if (ring[ring.length - 1][j] !== ring[0][j]) {\n throw new Error(\"First and last Position are not equivalent.\");\n }\n }\n }\n const geom: Polygon = {\n type: \"Polygon\",\n coordinates,\n };\n return feature(geom, properties, options);\n}\n\n/**\n * Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.\n *\n * @name polygons\n * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygon coordinates\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection<Polygon>} Polygon FeatureCollection\n * @example\n * var polygons = turf.polygons([\n * [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],\n * [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],\n * ]);\n *\n * //=polygons\n */\nexport function polygons<P extends GeoJsonProperties = GeoJsonProperties>(\n coordinates: Position[][][],\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): FeatureCollection<Polygon, P> {\n return featureCollection(\n coordinates.map((coords) => {\n return polygon(coords, properties);\n }),\n options\n );\n}\n\n/**\n * Creates a {@link LineString} {@link Feature} from an Array of Positions.\n *\n * @name lineString\n * @param {Array<Array<number>>} coordinates an array of Positions\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<LineString>} LineString Feature\n * @example\n * var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});\n * var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});\n *\n * //=linestring1\n * //=linestring2\n */\nexport function lineString<P extends GeoJsonProperties = GeoJsonProperties>(\n coordinates: Position[],\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): Feature<LineString, P> {\n if (coordinates.length < 2) {\n throw new Error(\"coordinates must be an array of two or more positions\");\n }\n const geom: LineString = {\n type: \"LineString\",\n coordinates,\n };\n return feature(geom, properties, options);\n}\n\n/**\n * Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.\n *\n * @name lineStrings\n * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]\n * associated with the FeatureCollection\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection<LineString>} LineString FeatureCollection\n * @example\n * var linestrings = turf.lineStrings([\n * [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],\n * [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]\n * ]);\n *\n * //=linestrings\n */\nexport function lineStrings<P extends GeoJsonProperties = GeoJsonProperties>(\n coordinates: Position[][],\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): FeatureCollection<LineString, P> {\n return featureCollection(\n coordinates.map((coords) => {\n return lineString(coords, properties);\n }),\n options\n );\n}\n\n/**\n * Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.\n *\n * @name featureCollection\n * @param {Feature[]} features input features\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {FeatureCollection} FeatureCollection of Features\n * @example\n * var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});\n * var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});\n * var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});\n *\n * var collection = turf.featureCollection([\n * locationA,\n * locationB,\n * locationC\n * ]);\n *\n * //=collection\n */\nexport function featureCollection<\n G extends GeometryObject = Geometry,\n P extends GeoJsonProperties = GeoJsonProperties,\n>(\n features: Array<Feature<G, P>>,\n options: { bbox?: BBox; id?: Id } = {}\n): FeatureCollection<G, P> {\n const fc: any = { type: \"FeatureCollection\" };\n if (options.id) {\n fc.id = options.id;\n }\n if (options.bbox) {\n fc.bbox = options.bbox;\n }\n fc.features = features;\n return fc;\n}\n\n/**\n * Creates a {@link Feature<MultiLineString>} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiLineString\n * @param {Array<Array<Array<number>>>} coordinates an array of LineStrings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<MultiLineString>} a MultiLineString feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiLine = turf.multiLineString([[[0,0],[10,10]]]);\n *\n * //=multiLine\n */\nexport function multiLineString<\n P extends GeoJsonProperties = GeoJsonProperties,\n>(\n coordinates: Position[][],\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): Feature<MultiLineString, P> {\n const geom: MultiLineString = {\n type: \"MultiLineString\",\n coordinates,\n };\n return feature(geom, properties, options);\n}\n\n/**\n * Creates a {@link Feature<MultiPoint>} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiPoint\n * @param {Array<Array<number>>} coordinates an array of Positions\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<MultiPoint>} a MultiPoint feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiPt = turf.multiPoint([[0,0],[10,10]]);\n *\n * //=multiPt\n */\nexport function multiPoint<P extends GeoJsonProperties = GeoJsonProperties>(\n coordinates: Position[],\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): Feature<MultiPoint, P> {\n const geom: MultiPoint = {\n type: \"MultiPoint\",\n coordinates,\n };\n return feature(geom, properties, options);\n}\n\n/**\n * Creates a {@link Feature<MultiPolygon>} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiPolygon\n * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygons\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<MultiPolygon>} a multipolygon feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);\n *\n * //=multiPoly\n *\n */\nexport function multiPolygon<P extends GeoJsonProperties = GeoJsonProperties>(\n coordinates: Position[][][],\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): Feature<MultiPolygon, P> {\n const geom: MultiPolygon = {\n type: \"MultiPolygon\",\n coordinates,\n };\n return feature(geom, properties, options);\n}\n\n/**\n * Creates a {@link Feature<GeometryCollection>} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name geometryCollection\n * @param {Array<Geometry>} geometries an array of GeoJSON Geometries\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature<GeometryCollection>} a GeoJSON GeometryCollection Feature\n * @example\n * var pt = turf.geometry(\"Point\", [100, 0]);\n * var line = turf.geometry(\"LineString\", [[101, 0], [102, 1]]);\n * var collection = turf.geometryCollection([pt, line]);\n *\n * // => collection\n */\nexport function geometryCollection<\n P extends GeoJsonProperties = GeoJsonProperties,\n>(\n geometries: Array<\n Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon\n >,\n properties?: P,\n options: { bbox?: BBox; id?: Id } = {}\n): Feature<GeometryCollection, P> {\n const geom: GeometryCollection = {\n type: \"GeometryCollection\",\n geometries,\n };\n return feature(geom, properties, options);\n}\n\n/**\n * Round number to precision\n *\n * @param {number} num Number\n * @param {number} [precision=0] Precision\n * @returns {number} rounded number\n * @example\n * turf.round(120.4321)\n * //=120\n *\n * turf.round(120.4321, 2)\n * //=120.43\n */\nexport function round(num: number, precision = 0): number {\n if (precision && !(precision >= 0)) {\n throw new Error(\"precision must be a positive number\");\n }\n const multiplier = Math.pow(10, precision || 0);\n return Math.round(num * multiplier) / multiplier;\n}\n\n/**\n * Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @name radiansToLength\n * @param {number} radians in radians across the sphere\n * @param {string} [units=\"kilometers\"] can be degrees, radians, miles, inches, yards, metres,\n * meters, kilometres, kilometers.\n * @returns {number} distance\n */\nexport function radiansToLength(\n radians: number,\n units: Units = \"kilometers\"\n): number {\n const factor = factors[units];\n if (!factor) {\n throw new Error(units + \" units is invalid\");\n }\n return radians * factor;\n}\n\n/**\n * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @name lengthToRadians\n * @param {number} distance in real units\n * @param {string} [units=\"kilometers\"] can be degrees, radians, miles, inches, yards, metres,\n * meters, kilometres, kilometers.\n * @returns {number} radians\n */\nexport function lengthToRadians(\n distance: number,\n units: Units = \"kilometers\"\n): number {\n const factor = factors[units];\n if (!factor) {\n throw new Error(units + \" units is invalid\");\n }\n return distance / factor;\n}\n\n/**\n * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet\n *\n * @name lengthToDegrees\n * @param {number} distance in real units\n * @param {string} [units=\"kilometers\"] can be degrees, radians, miles, inches, yards, metres,\n * meters, kilometres, kilometers.\n * @returns {number} degrees\n */\nexport function lengthToDegrees(distance: number, units?: Units): number {\n return radiansToDegrees(lengthToRadians(distance, units));\n}\n\n/**\n * Converts any bearing angle from the north line direction (positive clockwise)\n * and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line\n *\n * @name bearingToAzimuth\n * @param {number} bearing angle, between -180 and +180 degrees\n * @returns {number} angle between 0 and 360 degrees\n */\nexport function bearingToAzimuth(bearing: number): number {\n let angle = bearing % 360;\n if (angle < 0) {\n angle += 360;\n }\n return angle;\n}\n\n/**\n * Converts an angle in radians to degrees\n *\n * @name radiansToDegrees\n * @param {number} radians angle in radians\n * @returns {number} degrees between 0 and 360 degrees\n */\nexport function radiansToDegrees(radians: number): number {\n const degrees = radians % (2 * Math.PI);\n return (degrees * 180) / Math.PI;\n}\n\n/**\n * Converts an angle in degrees to radians\n *\n * @name degreesToRadians\n * @param {number} degrees angle between 0 and 360 degrees\n * @returns {number} angle in radians\n */\nexport function degreesToRadians(degrees: number): number {\n const radians = degrees % 360;\n return (radians * Math.PI) / 180;\n}\n\n/**\n * Converts a length to the requested unit.\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @param {number} length to be converted\n * @param {Units} [originalUnit=\"kilometers\"] of the length\n * @param {Units} [finalUnit=\"kilometers\"] returned unit\n * @returns {number} the converted length\n */\nexport function convertLength(\n length: number,\n originalUnit: Units = \"kilometers\",\n finalUnit: Units = \"kilometers\"\n): number {\n if (!(length >= 0)) {\n throw new Error(\"length must be a positive number\");\n }\n return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);\n}\n\n/**\n * Converts a area to the requested unit.\n * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares\n * @param {number} area to be converted\n * @param {Units} [originalUnit=\"meters\"] of the distance\n * @param {Units} [finalUnit=\"kilometers\"] returned unit\n * @returns {number} the converted area\n */\nexport function convertArea(\n area: number,\n originalUnit: AreaUnits = \"meters\",\n finalUnit: AreaUnits = \"kilometers\"\n): number {\n if (!(area >= 0)) {\n throw new Error(\"area must be a positive number\");\n }\n\n const startFactor = areaFactors[originalUnit];\n if (!startFactor) {\n throw new Error(\"invalid original units\");\n }\n\n const finalFactor = areaFactors[finalUnit];\n if (!finalFactor) {\n throw new Error(\"invalid final units\");\n }\n\n return (area / startFactor) * finalFactor;\n}\n\n/**\n * isNumber\n *\n * @param {*} num Number to validate\n * @returns {boolean} true/false\n * @example\n * turf.isNumber(123)\n * //=true\n * turf.isNumber('foo')\n * //=false\n */\nexport function isNumber(num: any): boolean {\n return !isNaN(num) && num !== null && !Array.isArray(num);\n}\n\n/**\n * isObject\n *\n * @param {*} input variable to validate\n * @returns {boolean} true/false, including false for Arrays and Functions\n * @example\n * turf.isObject({elevation: 10})\n * //=true\n * turf.isObject('foo')\n * //=false\n */\nexport function isObject(input: any): boolean {\n return input !== null && typeof input === \"object\" && !Array.isArray(input);\n}\n\n/**\n * Validate BBox\n *\n * @private\n * @param {Array<number>} bbox BBox to validate\n * @returns {void}\n * @throws {Error} if BBox is not valid\n * @example\n * validateBBox([-180, -40, 110, 50])\n * //=OK\n * validateBBox([-180, -40])\n * //=Error\n * validateBBox('Foo')\n * //=Error\n * validateBBox(5)\n * //=Error\n * validateBBox(null)\n * //=Error\n * validateBBox(undefined)\n * //=Error\n */\nexport function validateBBox(bbox: any): void {\n if (!bbox) {\n throw new Error(\"bbox is required\");\n }\n if (!Array.isArray(bbox)) {\n throw new Error(\"bbox must be an Array\");\n }\n if (bbox.length !== 4 && bbox.length !== 6) {\n throw new Error(\"bbox must be an Array of 4 or 6 numbers\");\n }\n bbox.forEach((num) => {\n if (!isNumber(num)) {\n throw new Error(\"bbox must only contain numbers\");\n }\n });\n}\n\n/**\n * Validate Id\n *\n * @private\n * @param {string|number} id Id to validate\n * @returns {void}\n * @throws {Error} if Id is not valid\n * @example\n * validateId([-180, -40, 110, 50])\n * //=Error\n * validateId([-180, -40])\n * //=Error\n * validateId('Foo')\n * //=OK\n * validateId(5)\n * //=OK\n * validateId(null)\n * //=Error\n * validateId(undefined)\n * //=Error\n */\nexport function validateId(id: any): void {\n if (!id) {\n throw new Error(\"id is required\");\n }\n if ([\"string\", \"number\"].indexOf(typeof id) === -1) {\n throw new Error(\"id must be a number or a string\");\n }\n}\n"]}
|