@turf/helpers 7.0.0-alpha.2 → 7.0.0
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/{es/index.js → cjs/index.d.cts} +116 -258
- package/dist/{js → esm}/index.d.ts +80 -39
- package/dist/esm/index.js +458 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +31 -24
- 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
|
@@ -1,3 +1,52 @@
|
|
|
1
|
+
import { GeoJSON, Feature, Point, Position, LineString, MultiLineString, Polygon, MultiPolygon, FeatureCollection, Geometry, GeometryCollection, GeometryObject, GeoJsonProperties, BBox, MultiPoint } from 'geojson';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Id
|
|
5
|
+
*
|
|
6
|
+
* https://tools.ietf.org/html/rfc7946#section-3.2
|
|
7
|
+
* If a Feature has a commonly used identifier, that identifier SHOULD be included as a member of
|
|
8
|
+
* the Feature object with the name "id", and the value of this member is either a JSON string or number.
|
|
9
|
+
*
|
|
10
|
+
* Should be contributed to @types/geojson
|
|
11
|
+
*/
|
|
12
|
+
type Id = string | number;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
|
|
16
|
+
* GeoJSON equality checking utility.
|
|
17
|
+
* Adapted from https://github.com/geosquare/geojson-equality
|
|
18
|
+
*
|
|
19
|
+
* @memberof helpers
|
|
20
|
+
* @type {Class}
|
|
21
|
+
*/
|
|
22
|
+
declare class GeojsonEquality {
|
|
23
|
+
private precision;
|
|
24
|
+
private direction;
|
|
25
|
+
private compareProperties;
|
|
26
|
+
constructor(opts?: {
|
|
27
|
+
precision?: number;
|
|
28
|
+
direction?: boolean;
|
|
29
|
+
compareProperties?: boolean;
|
|
30
|
+
});
|
|
31
|
+
compare(g1: GeoJSON, g2: GeoJSON): boolean;
|
|
32
|
+
private compareCoord;
|
|
33
|
+
private compareLine;
|
|
34
|
+
private fixStartIndex;
|
|
35
|
+
private comparePath;
|
|
36
|
+
private comparePolygon;
|
|
37
|
+
private compareGeometryCollection;
|
|
38
|
+
private compareFeature;
|
|
39
|
+
private compareFeatureCollection;
|
|
40
|
+
private compareBBox;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type Coord = Feature<Point> | Point | Position;
|
|
44
|
+
type Units = "meters" | "metres" | "millimeters" | "millimetres" | "centimeters" | "centimetres" | "kilometers" | "kilometres" | "miles" | "nauticalmiles" | "inches" | "yards" | "feet" | "radians" | "degrees";
|
|
45
|
+
type AreaUnits = Exclude<Units, "radians" | "degrees"> | "acres" | "hectares";
|
|
46
|
+
type Grid = "point" | "square" | "hex" | "triangle";
|
|
47
|
+
type Corners = "sw" | "se" | "nw" | "ne" | "center" | "centroid";
|
|
48
|
+
type Lines = LineString | MultiLineString | Polygon | MultiPolygon;
|
|
49
|
+
type AllGeoJSON = Feature | FeatureCollection | Geometry | GeometryCollection;
|
|
1
50
|
/**
|
|
2
51
|
* @module helpers
|
|
3
52
|
*/
|
|
@@ -7,7 +56,7 @@
|
|
|
7
56
|
* @memberof helpers
|
|
8
57
|
* @type {number}
|
|
9
58
|
*/
|
|
10
|
-
|
|
59
|
+
declare const earthRadius = 6371008.8;
|
|
11
60
|
/**
|
|
12
61
|
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
|
|
13
62
|
*
|
|
@@ -16,23 +65,7 @@ export const earthRadius = 6371008.8;
|
|
|
16
65
|
* @memberof helpers
|
|
17
66
|
* @type {Object}
|
|
18
67
|
*/
|
|
19
|
-
|
|
20
|
-
centimeters: earthRadius * 100,
|
|
21
|
-
centimetres: earthRadius * 100,
|
|
22
|
-
degrees: 360 / (2 * Math.PI),
|
|
23
|
-
feet: earthRadius * 3.28084,
|
|
24
|
-
inches: earthRadius * 39.37,
|
|
25
|
-
kilometers: earthRadius / 1000,
|
|
26
|
-
kilometres: earthRadius / 1000,
|
|
27
|
-
meters: earthRadius,
|
|
28
|
-
metres: earthRadius,
|
|
29
|
-
miles: earthRadius / 1609.344,
|
|
30
|
-
millimeters: earthRadius * 1000,
|
|
31
|
-
millimetres: earthRadius * 1000,
|
|
32
|
-
nauticalmiles: earthRadius / 1852,
|
|
33
|
-
radians: 1,
|
|
34
|
-
yards: earthRadius * 1.0936,
|
|
35
|
-
};
|
|
68
|
+
declare const factors: Record<Units, number>;
|
|
36
69
|
/**
|
|
37
70
|
|
|
38
71
|
* Area of measurement factors based on 1 square meter.
|
|
@@ -40,23 +73,7 @@ export const factors = {
|
|
|
40
73
|
* @memberof helpers
|
|
41
74
|
* @type {Object}
|
|
42
75
|
*/
|
|
43
|
-
|
|
44
|
-
acres: 0.000247105,
|
|
45
|
-
centimeters: 10000,
|
|
46
|
-
centimetres: 10000,
|
|
47
|
-
feet: 10.763910417,
|
|
48
|
-
hectares: 0.0001,
|
|
49
|
-
inches: 1550.003100006,
|
|
50
|
-
kilometers: 0.000001,
|
|
51
|
-
kilometres: 0.000001,
|
|
52
|
-
meters: 1,
|
|
53
|
-
metres: 1,
|
|
54
|
-
miles: 3.86e-7,
|
|
55
|
-
nauticalmiles: 2.9155334959812285e-7,
|
|
56
|
-
millimeters: 1000000,
|
|
57
|
-
millimetres: 1000000,
|
|
58
|
-
yards: 1.195990046,
|
|
59
|
-
};
|
|
76
|
+
declare const areaFactors: Record<AreaUnits, number>;
|
|
60
77
|
/**
|
|
61
78
|
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
|
|
62
79
|
*
|
|
@@ -77,18 +94,10 @@ export const areaFactors = {
|
|
|
77
94
|
*
|
|
78
95
|
* //=feature
|
|
79
96
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
if (options.bbox) {
|
|
86
|
-
feat.bbox = options.bbox;
|
|
87
|
-
}
|
|
88
|
-
feat.properties = properties || {};
|
|
89
|
-
feat.geometry = geom;
|
|
90
|
-
return feat;
|
|
91
|
-
}
|
|
97
|
+
declare function feature<G extends GeometryObject = Geometry, P extends GeoJsonProperties = GeoJsonProperties>(geom: G | null, properties?: P, options?: {
|
|
98
|
+
bbox?: BBox;
|
|
99
|
+
id?: Id;
|
|
100
|
+
}): Feature<G, P>;
|
|
92
101
|
/**
|
|
93
102
|
* Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
|
|
94
103
|
* For GeometryCollection type use `helpers.geometryCollection`
|
|
@@ -104,24 +113,7 @@ export function feature(geom, properties, options = {}) {
|
|
|
104
113
|
* var geometry = turf.geometry(type, coordinates);
|
|
105
114
|
* // => geometry
|
|
106
115
|
*/
|
|
107
|
-
|
|
108
|
-
switch (type) {
|
|
109
|
-
case "Point":
|
|
110
|
-
return point(coordinates).geometry;
|
|
111
|
-
case "LineString":
|
|
112
|
-
return lineString(coordinates).geometry;
|
|
113
|
-
case "Polygon":
|
|
114
|
-
return polygon(coordinates).geometry;
|
|
115
|
-
case "MultiPoint":
|
|
116
|
-
return multiPoint(coordinates).geometry;
|
|
117
|
-
case "MultiLineString":
|
|
118
|
-
return multiLineString(coordinates).geometry;
|
|
119
|
-
case "MultiPolygon":
|
|
120
|
-
return multiPolygon(coordinates).geometry;
|
|
121
|
-
default:
|
|
122
|
-
throw new Error(type + " is invalid");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
116
|
+
declare function geometry(type: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon", coordinates: any[], _options?: Record<string, never>): Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
|
|
125
117
|
/**
|
|
126
118
|
* Creates a {@link Point} {@link Feature} from a Position.
|
|
127
119
|
*
|
|
@@ -137,25 +129,10 @@ export function geometry(type, coordinates, _options = {}) {
|
|
|
137
129
|
*
|
|
138
130
|
* //=point
|
|
139
131
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (!Array.isArray(coordinates)) {
|
|
145
|
-
throw new Error("coordinates must be an Array");
|
|
146
|
-
}
|
|
147
|
-
if (coordinates.length < 2) {
|
|
148
|
-
throw new Error("coordinates must be at least 2 numbers long");
|
|
149
|
-
}
|
|
150
|
-
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {
|
|
151
|
-
throw new Error("coordinates must contain numbers");
|
|
152
|
-
}
|
|
153
|
-
const geom = {
|
|
154
|
-
type: "Point",
|
|
155
|
-
coordinates,
|
|
156
|
-
};
|
|
157
|
-
return feature(geom, properties, options);
|
|
158
|
-
}
|
|
132
|
+
declare function point<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position, properties?: P, options?: {
|
|
133
|
+
bbox?: BBox;
|
|
134
|
+
id?: Id;
|
|
135
|
+
}): Feature<Point, P>;
|
|
159
136
|
/**
|
|
160
137
|
* Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
|
|
161
138
|
*
|
|
@@ -176,11 +153,10 @@ export function point(coordinates, properties, options = {}) {
|
|
|
176
153
|
*
|
|
177
154
|
* //=points
|
|
178
155
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
156
|
+
declare function points<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
|
|
157
|
+
bbox?: BBox;
|
|
158
|
+
id?: Id;
|
|
159
|
+
}): FeatureCollection<Point, P>;
|
|
184
160
|
/**
|
|
185
161
|
* Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
|
|
186
162
|
*
|
|
@@ -196,27 +172,10 @@ export function points(coordinates, properties, options = {}) {
|
|
|
196
172
|
*
|
|
197
173
|
* //=polygon
|
|
198
174
|
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
if (ring[ring.length - 1].length !== ring[0].length) {
|
|
205
|
-
throw new Error("First and last Position are not equivalent.");
|
|
206
|
-
}
|
|
207
|
-
for (let j = 0; j < ring[ring.length - 1].length; j++) {
|
|
208
|
-
// Check if first point of Polygon contains two numbers
|
|
209
|
-
if (ring[ring.length - 1][j] !== ring[0][j]) {
|
|
210
|
-
throw new Error("First and last Position are not equivalent.");
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
const geom = {
|
|
215
|
-
type: "Polygon",
|
|
216
|
-
coordinates,
|
|
217
|
-
};
|
|
218
|
-
return feature(geom, properties, options);
|
|
219
|
-
}
|
|
175
|
+
declare function polygon<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
|
|
176
|
+
bbox?: BBox;
|
|
177
|
+
id?: Id;
|
|
178
|
+
}): Feature<Polygon, P>;
|
|
220
179
|
/**
|
|
221
180
|
* Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
|
|
222
181
|
*
|
|
@@ -235,11 +194,10 @@ export function polygon(coordinates, properties, options = {}) {
|
|
|
235
194
|
*
|
|
236
195
|
* //=polygons
|
|
237
196
|
*/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
197
|
+
declare function polygons<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: {
|
|
198
|
+
bbox?: BBox;
|
|
199
|
+
id?: Id;
|
|
200
|
+
}): FeatureCollection<Polygon, P>;
|
|
243
201
|
/**
|
|
244
202
|
* Creates a {@link LineString} {@link Feature} from an Array of Positions.
|
|
245
203
|
*
|
|
@@ -257,16 +215,10 @@ export function polygons(coordinates, properties, options = {}) {
|
|
|
257
215
|
* //=linestring1
|
|
258
216
|
* //=linestring2
|
|
259
217
|
*/
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const geom = {
|
|
265
|
-
type: "LineString",
|
|
266
|
-
coordinates,
|
|
267
|
-
};
|
|
268
|
-
return feature(geom, properties, options);
|
|
269
|
-
}
|
|
218
|
+
declare function lineString<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
|
|
219
|
+
bbox?: BBox;
|
|
220
|
+
id?: Id;
|
|
221
|
+
}): Feature<LineString, P>;
|
|
270
222
|
/**
|
|
271
223
|
* Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
|
|
272
224
|
*
|
|
@@ -286,11 +238,10 @@ export function lineString(coordinates, properties, options = {}) {
|
|
|
286
238
|
*
|
|
287
239
|
* //=linestrings
|
|
288
240
|
*/
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
241
|
+
declare function lineStrings<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
|
|
242
|
+
bbox?: BBox;
|
|
243
|
+
id?: Id;
|
|
244
|
+
}): FeatureCollection<LineString, P>;
|
|
294
245
|
/**
|
|
295
246
|
* Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
|
|
296
247
|
*
|
|
@@ -313,17 +264,10 @@ export function lineStrings(coordinates, properties, options = {}) {
|
|
|
313
264
|
*
|
|
314
265
|
* //=collection
|
|
315
266
|
*/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
if (options.bbox) {
|
|
322
|
-
fc.bbox = options.bbox;
|
|
323
|
-
}
|
|
324
|
-
fc.features = features;
|
|
325
|
-
return fc;
|
|
326
|
-
}
|
|
267
|
+
declare function featureCollection<G extends GeometryObject = Geometry, P extends GeoJsonProperties = GeoJsonProperties>(features: Array<Feature<G, P>>, options?: {
|
|
268
|
+
bbox?: BBox;
|
|
269
|
+
id?: Id;
|
|
270
|
+
}): FeatureCollection<G, P>;
|
|
327
271
|
/**
|
|
328
272
|
* Creates a {@link Feature<MultiLineString>} based on a
|
|
329
273
|
* coordinate array. Properties can be added optionally.
|
|
@@ -341,13 +285,10 @@ export function featureCollection(features, options = {}) {
|
|
|
341
285
|
*
|
|
342
286
|
* //=multiLine
|
|
343
287
|
*/
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
};
|
|
349
|
-
return feature(geom, properties, options);
|
|
350
|
-
}
|
|
288
|
+
declare function multiLineString<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
|
|
289
|
+
bbox?: BBox;
|
|
290
|
+
id?: Id;
|
|
291
|
+
}): Feature<MultiLineString, P>;
|
|
351
292
|
/**
|
|
352
293
|
* Creates a {@link Feature<MultiPoint>} based on a
|
|
353
294
|
* coordinate array. Properties can be added optionally.
|
|
@@ -365,13 +306,10 @@ export function multiLineString(coordinates, properties, options = {}) {
|
|
|
365
306
|
*
|
|
366
307
|
* //=multiPt
|
|
367
308
|
*/
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
};
|
|
373
|
-
return feature(geom, properties, options);
|
|
374
|
-
}
|
|
309
|
+
declare function multiPoint<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
|
|
310
|
+
bbox?: BBox;
|
|
311
|
+
id?: Id;
|
|
312
|
+
}): Feature<MultiPoint, P>;
|
|
375
313
|
/**
|
|
376
314
|
* Creates a {@link Feature<MultiPolygon>} based on a
|
|
377
315
|
* coordinate array. Properties can be added optionally.
|
|
@@ -390,13 +328,10 @@ export function multiPoint(coordinates, properties, options = {}) {
|
|
|
390
328
|
* //=multiPoly
|
|
391
329
|
*
|
|
392
330
|
*/
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
};
|
|
398
|
-
return feature(geom, properties, options);
|
|
399
|
-
}
|
|
331
|
+
declare function multiPolygon<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: {
|
|
332
|
+
bbox?: BBox;
|
|
333
|
+
id?: Id;
|
|
334
|
+
}): Feature<MultiPolygon, P>;
|
|
400
335
|
/**
|
|
401
336
|
* Creates a {@link Feature<GeometryCollection>} based on a
|
|
402
337
|
* coordinate array. Properties can be added optionally.
|
|
@@ -415,13 +350,10 @@ export function multiPolygon(coordinates, properties, options = {}) {
|
|
|
415
350
|
*
|
|
416
351
|
* // => collection
|
|
417
352
|
*/
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
};
|
|
423
|
-
return feature(geom, properties, options);
|
|
424
|
-
}
|
|
353
|
+
declare function geometryCollection<P extends GeoJsonProperties = GeoJsonProperties>(geometries: Array<Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon>, properties?: P, options?: {
|
|
354
|
+
bbox?: BBox;
|
|
355
|
+
id?: Id;
|
|
356
|
+
}): Feature<GeometryCollection, P>;
|
|
425
357
|
/**
|
|
426
358
|
* Round number to precision
|
|
427
359
|
*
|
|
@@ -435,13 +367,7 @@ export function geometryCollection(geometries, properties, options = {}) {
|
|
|
435
367
|
* turf.round(120.4321, 2)
|
|
436
368
|
* //=120.43
|
|
437
369
|
*/
|
|
438
|
-
|
|
439
|
-
if (precision && !(precision >= 0)) {
|
|
440
|
-
throw new Error("precision must be a positive number");
|
|
441
|
-
}
|
|
442
|
-
const multiplier = Math.pow(10, precision || 0);
|
|
443
|
-
return Math.round(num * multiplier) / multiplier;
|
|
444
|
-
}
|
|
370
|
+
declare function round(num: number, precision?: number): number;
|
|
445
371
|
/**
|
|
446
372
|
* Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
|
|
447
373
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
@@ -452,13 +378,7 @@ export function round(num, precision = 0) {
|
|
|
452
378
|
* meters, kilometres, kilometers.
|
|
453
379
|
* @returns {number} distance
|
|
454
380
|
*/
|
|
455
|
-
|
|
456
|
-
const factor = factors[units];
|
|
457
|
-
if (!factor) {
|
|
458
|
-
throw new Error(units + " units is invalid");
|
|
459
|
-
}
|
|
460
|
-
return radians * factor;
|
|
461
|
-
}
|
|
381
|
+
declare function radiansToLength(radians: number, units?: Units): number;
|
|
462
382
|
/**
|
|
463
383
|
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
|
|
464
384
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
@@ -469,13 +389,7 @@ export function radiansToLength(radians, units = "kilometers") {
|
|
|
469
389
|
* meters, kilometres, kilometers.
|
|
470
390
|
* @returns {number} radians
|
|
471
391
|
*/
|
|
472
|
-
|
|
473
|
-
const factor = factors[units];
|
|
474
|
-
if (!factor) {
|
|
475
|
-
throw new Error(units + " units is invalid");
|
|
476
|
-
}
|
|
477
|
-
return distance / factor;
|
|
478
|
-
}
|
|
392
|
+
declare function lengthToRadians(distance: number, units?: Units): number;
|
|
479
393
|
/**
|
|
480
394
|
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
|
|
481
395
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
|
|
@@ -486,9 +400,7 @@ export function lengthToRadians(distance, units = "kilometers") {
|
|
|
486
400
|
* meters, kilometres, kilometers.
|
|
487
401
|
* @returns {number} degrees
|
|
488
402
|
*/
|
|
489
|
-
|
|
490
|
-
return radiansToDegrees(lengthToRadians(distance, units));
|
|
491
|
-
}
|
|
403
|
+
declare function lengthToDegrees(distance: number, units?: Units): number;
|
|
492
404
|
/**
|
|
493
405
|
* Converts any bearing angle from the north line direction (positive clockwise)
|
|
494
406
|
* and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
|
|
@@ -497,13 +409,7 @@ export function lengthToDegrees(distance, units) {
|
|
|
497
409
|
* @param {number} bearing angle, between -180 and +180 degrees
|
|
498
410
|
* @returns {number} angle between 0 and 360 degrees
|
|
499
411
|
*/
|
|
500
|
-
|
|
501
|
-
let angle = bearing % 360;
|
|
502
|
-
if (angle < 0) {
|
|
503
|
-
angle += 360;
|
|
504
|
-
}
|
|
505
|
-
return angle;
|
|
506
|
-
}
|
|
412
|
+
declare function bearingToAzimuth(bearing: number): number;
|
|
507
413
|
/**
|
|
508
414
|
* Converts an angle in radians to degrees
|
|
509
415
|
*
|
|
@@ -511,10 +417,7 @@ export function bearingToAzimuth(bearing) {
|
|
|
511
417
|
* @param {number} radians angle in radians
|
|
512
418
|
* @returns {number} degrees between 0 and 360 degrees
|
|
513
419
|
*/
|
|
514
|
-
|
|
515
|
-
const degrees = radians % (2 * Math.PI);
|
|
516
|
-
return (degrees * 180) / Math.PI;
|
|
517
|
-
}
|
|
420
|
+
declare function radiansToDegrees(radians: number): number;
|
|
518
421
|
/**
|
|
519
422
|
* Converts an angle in degrees to radians
|
|
520
423
|
*
|
|
@@ -522,10 +425,7 @@ export function radiansToDegrees(radians) {
|
|
|
522
425
|
* @param {number} degrees angle between 0 and 360 degrees
|
|
523
426
|
* @returns {number} angle in radians
|
|
524
427
|
*/
|
|
525
|
-
|
|
526
|
-
const radians = degrees % 360;
|
|
527
|
-
return (radians * Math.PI) / 180;
|
|
528
|
-
}
|
|
428
|
+
declare function degreesToRadians(degrees: number): number;
|
|
529
429
|
/**
|
|
530
430
|
* Converts a length to the requested unit.
|
|
531
431
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
@@ -535,12 +435,7 @@ export function degreesToRadians(degrees) {
|
|
|
535
435
|
* @param {Units} [finalUnit="kilometers"] returned unit
|
|
536
436
|
* @returns {number} the converted length
|
|
537
437
|
*/
|
|
538
|
-
|
|
539
|
-
if (!(length >= 0)) {
|
|
540
|
-
throw new Error("length must be a positive number");
|
|
541
|
-
}
|
|
542
|
-
return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
|
|
543
|
-
}
|
|
438
|
+
declare function convertLength(length: number, originalUnit?: Units, finalUnit?: Units): number;
|
|
544
439
|
/**
|
|
545
440
|
* Converts a area to the requested unit.
|
|
546
441
|
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares
|
|
@@ -549,20 +444,7 @@ export function convertLength(length, originalUnit = "kilometers", finalUnit = "
|
|
|
549
444
|
* @param {Units} [finalUnit="kilometers"] returned unit
|
|
550
445
|
* @returns {number} the converted area
|
|
551
446
|
*/
|
|
552
|
-
|
|
553
|
-
if (!(area >= 0)) {
|
|
554
|
-
throw new Error("area must be a positive number");
|
|
555
|
-
}
|
|
556
|
-
const startFactor = areaFactors[originalUnit];
|
|
557
|
-
if (!startFactor) {
|
|
558
|
-
throw new Error("invalid original units");
|
|
559
|
-
}
|
|
560
|
-
const finalFactor = areaFactors[finalUnit];
|
|
561
|
-
if (!finalFactor) {
|
|
562
|
-
throw new Error("invalid final units");
|
|
563
|
-
}
|
|
564
|
-
return (area / startFactor) * finalFactor;
|
|
565
|
-
}
|
|
447
|
+
declare function convertArea(area: number, originalUnit?: AreaUnits, finalUnit?: AreaUnits): number;
|
|
566
448
|
/**
|
|
567
449
|
* isNumber
|
|
568
450
|
*
|
|
@@ -574,9 +456,7 @@ export function convertArea(area, originalUnit = "meters", finalUnit = "kilomete
|
|
|
574
456
|
* turf.isNumber('foo')
|
|
575
457
|
* //=false
|
|
576
458
|
*/
|
|
577
|
-
|
|
578
|
-
return !isNaN(num) && num !== null && !Array.isArray(num);
|
|
579
|
-
}
|
|
459
|
+
declare function isNumber(num: any): boolean;
|
|
580
460
|
/**
|
|
581
461
|
* isObject
|
|
582
462
|
*
|
|
@@ -588,9 +468,7 @@ export function isNumber(num) {
|
|
|
588
468
|
* turf.isObject('foo')
|
|
589
469
|
* //=false
|
|
590
470
|
*/
|
|
591
|
-
|
|
592
|
-
return input !== null && typeof input === "object" && !Array.isArray(input);
|
|
593
|
-
}
|
|
471
|
+
declare function isObject(input: any): boolean;
|
|
594
472
|
/**
|
|
595
473
|
* Validate BBox
|
|
596
474
|
*
|
|
@@ -612,22 +490,7 @@ export function isObject(input) {
|
|
|
612
490
|
* validateBBox(undefined)
|
|
613
491
|
* //=Error
|
|
614
492
|
*/
|
|
615
|
-
|
|
616
|
-
if (!bbox) {
|
|
617
|
-
throw new Error("bbox is required");
|
|
618
|
-
}
|
|
619
|
-
if (!Array.isArray(bbox)) {
|
|
620
|
-
throw new Error("bbox must be an Array");
|
|
621
|
-
}
|
|
622
|
-
if (bbox.length !== 4 && bbox.length !== 6) {
|
|
623
|
-
throw new Error("bbox must be an Array of 4 or 6 numbers");
|
|
624
|
-
}
|
|
625
|
-
bbox.forEach((num) => {
|
|
626
|
-
if (!isNumber(num)) {
|
|
627
|
-
throw new Error("bbox must only contain numbers");
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
}
|
|
493
|
+
declare function validateBBox(bbox: any): void;
|
|
631
494
|
/**
|
|
632
495
|
* Validate Id
|
|
633
496
|
*
|
|
@@ -649,11 +512,6 @@ export function validateBBox(bbox) {
|
|
|
649
512
|
* validateId(undefined)
|
|
650
513
|
* //=Error
|
|
651
514
|
*/
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
}
|
|
656
|
-
if (["string", "number"].indexOf(typeof id) === -1) {
|
|
657
|
-
throw new Error("id must be a number or a string");
|
|
658
|
-
}
|
|
659
|
-
}
|
|
515
|
+
declare function validateId(id: any): void;
|
|
516
|
+
|
|
517
|
+
export { type AllGeoJSON, type AreaUnits, type Coord, type Corners, GeojsonEquality, type Grid, type Id, type Lines, type Units, areaFactors, bearingToAzimuth, convertArea, convertLength, degreesToRadians, earthRadius, factors, feature, featureCollection, geometry, geometryCollection, isNumber, isObject, lengthToDegrees, lengthToRadians, lineString, lineStrings, multiLineString, multiPoint, multiPolygon, point, points, polygon, polygons, radiansToDegrees, radiansToLength, round, validateBBox, validateId };
|