@turf/helpers 7.0.0-alpha.0 → 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 -42
- package/dist/{es/index.js → esm/index.d.mts} +116 -257
- package/dist/esm/index.mjs +458 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +30 -22
- package/dist/es/lib/geojson.js +0 -0
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -686
- 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,22 +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
|
-
millimeters: 1000000,
|
|
56
|
-
millimetres: 1000000,
|
|
57
|
-
yards: 1.195990046,
|
|
58
|
-
};
|
|
76
|
+
declare const areaFactors: Record<AreaUnits, number>;
|
|
59
77
|
/**
|
|
60
78
|
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
|
|
61
79
|
*
|
|
@@ -76,18 +94,10 @@ export const areaFactors = {
|
|
|
76
94
|
*
|
|
77
95
|
* //=feature
|
|
78
96
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
if (options.bbox) {
|
|
85
|
-
feat.bbox = options.bbox;
|
|
86
|
-
}
|
|
87
|
-
feat.properties = properties || {};
|
|
88
|
-
feat.geometry = geom;
|
|
89
|
-
return feat;
|
|
90
|
-
}
|
|
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>;
|
|
91
101
|
/**
|
|
92
102
|
* Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
|
|
93
103
|
* For GeometryCollection type use `helpers.geometryCollection`
|
|
@@ -103,24 +113,7 @@ export function feature(geom, properties, options = {}) {
|
|
|
103
113
|
* var geometry = turf.geometry(type, coordinates);
|
|
104
114
|
* // => geometry
|
|
105
115
|
*/
|
|
106
|
-
|
|
107
|
-
switch (type) {
|
|
108
|
-
case "Point":
|
|
109
|
-
return point(coordinates).geometry;
|
|
110
|
-
case "LineString":
|
|
111
|
-
return lineString(coordinates).geometry;
|
|
112
|
-
case "Polygon":
|
|
113
|
-
return polygon(coordinates).geometry;
|
|
114
|
-
case "MultiPoint":
|
|
115
|
-
return multiPoint(coordinates).geometry;
|
|
116
|
-
case "MultiLineString":
|
|
117
|
-
return multiLineString(coordinates).geometry;
|
|
118
|
-
case "MultiPolygon":
|
|
119
|
-
return multiPolygon(coordinates).geometry;
|
|
120
|
-
default:
|
|
121
|
-
throw new Error(type + " is invalid");
|
|
122
|
-
}
|
|
123
|
-
}
|
|
116
|
+
declare function geometry(type: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon", coordinates: any[], _options?: Record<string, never>): Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
|
|
124
117
|
/**
|
|
125
118
|
* Creates a {@link Point} {@link Feature} from a Position.
|
|
126
119
|
*
|
|
@@ -136,25 +129,10 @@ export function geometry(type, coordinates, _options = {}) {
|
|
|
136
129
|
*
|
|
137
130
|
* //=point
|
|
138
131
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (!Array.isArray(coordinates)) {
|
|
144
|
-
throw new Error("coordinates must be an Array");
|
|
145
|
-
}
|
|
146
|
-
if (coordinates.length < 2) {
|
|
147
|
-
throw new Error("coordinates must be at least 2 numbers long");
|
|
148
|
-
}
|
|
149
|
-
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {
|
|
150
|
-
throw new Error("coordinates must contain numbers");
|
|
151
|
-
}
|
|
152
|
-
const geom = {
|
|
153
|
-
type: "Point",
|
|
154
|
-
coordinates,
|
|
155
|
-
};
|
|
156
|
-
return feature(geom, properties, options);
|
|
157
|
-
}
|
|
132
|
+
declare function point<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position, properties?: P, options?: {
|
|
133
|
+
bbox?: BBox;
|
|
134
|
+
id?: Id;
|
|
135
|
+
}): Feature<Point, P>;
|
|
158
136
|
/**
|
|
159
137
|
* Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
|
|
160
138
|
*
|
|
@@ -175,11 +153,10 @@ export function point(coordinates, properties, options = {}) {
|
|
|
175
153
|
*
|
|
176
154
|
* //=points
|
|
177
155
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
156
|
+
declare function points<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
|
|
157
|
+
bbox?: BBox;
|
|
158
|
+
id?: Id;
|
|
159
|
+
}): FeatureCollection<Point, P>;
|
|
183
160
|
/**
|
|
184
161
|
* Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
|
|
185
162
|
*
|
|
@@ -195,27 +172,10 @@ export function points(coordinates, properties, options = {}) {
|
|
|
195
172
|
*
|
|
196
173
|
* //=polygon
|
|
197
174
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
if (ring[ring.length - 1].length !== ring[0].length) {
|
|
204
|
-
throw new Error("First and last Position are not equivalent.");
|
|
205
|
-
}
|
|
206
|
-
for (let j = 0; j < ring[ring.length - 1].length; j++) {
|
|
207
|
-
// Check if first point of Polygon contains two numbers
|
|
208
|
-
if (ring[ring.length - 1][j] !== ring[0][j]) {
|
|
209
|
-
throw new Error("First and last Position are not equivalent.");
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
const geom = {
|
|
214
|
-
type: "Polygon",
|
|
215
|
-
coordinates,
|
|
216
|
-
};
|
|
217
|
-
return feature(geom, properties, options);
|
|
218
|
-
}
|
|
175
|
+
declare function polygon<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
|
|
176
|
+
bbox?: BBox;
|
|
177
|
+
id?: Id;
|
|
178
|
+
}): Feature<Polygon, P>;
|
|
219
179
|
/**
|
|
220
180
|
* Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
|
|
221
181
|
*
|
|
@@ -234,11 +194,10 @@ export function polygon(coordinates, properties, options = {}) {
|
|
|
234
194
|
*
|
|
235
195
|
* //=polygons
|
|
236
196
|
*/
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
197
|
+
declare function polygons<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: {
|
|
198
|
+
bbox?: BBox;
|
|
199
|
+
id?: Id;
|
|
200
|
+
}): FeatureCollection<Polygon, P>;
|
|
242
201
|
/**
|
|
243
202
|
* Creates a {@link LineString} {@link Feature} from an Array of Positions.
|
|
244
203
|
*
|
|
@@ -256,16 +215,10 @@ export function polygons(coordinates, properties, options = {}) {
|
|
|
256
215
|
* //=linestring1
|
|
257
216
|
* //=linestring2
|
|
258
217
|
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const geom = {
|
|
264
|
-
type: "LineString",
|
|
265
|
-
coordinates,
|
|
266
|
-
};
|
|
267
|
-
return feature(geom, properties, options);
|
|
268
|
-
}
|
|
218
|
+
declare function lineString<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
|
|
219
|
+
bbox?: BBox;
|
|
220
|
+
id?: Id;
|
|
221
|
+
}): Feature<LineString, P>;
|
|
269
222
|
/**
|
|
270
223
|
* Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
|
|
271
224
|
*
|
|
@@ -285,11 +238,10 @@ export function lineString(coordinates, properties, options = {}) {
|
|
|
285
238
|
*
|
|
286
239
|
* //=linestrings
|
|
287
240
|
*/
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
241
|
+
declare function lineStrings<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
|
|
242
|
+
bbox?: BBox;
|
|
243
|
+
id?: Id;
|
|
244
|
+
}): FeatureCollection<LineString, P>;
|
|
293
245
|
/**
|
|
294
246
|
* Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
|
|
295
247
|
*
|
|
@@ -312,17 +264,10 @@ export function lineStrings(coordinates, properties, options = {}) {
|
|
|
312
264
|
*
|
|
313
265
|
* //=collection
|
|
314
266
|
*/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
if (options.bbox) {
|
|
321
|
-
fc.bbox = options.bbox;
|
|
322
|
-
}
|
|
323
|
-
fc.features = features;
|
|
324
|
-
return fc;
|
|
325
|
-
}
|
|
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>;
|
|
326
271
|
/**
|
|
327
272
|
* Creates a {@link Feature<MultiLineString>} based on a
|
|
328
273
|
* coordinate array. Properties can be added optionally.
|
|
@@ -340,13 +285,10 @@ export function featureCollection(features, options = {}) {
|
|
|
340
285
|
*
|
|
341
286
|
* //=multiLine
|
|
342
287
|
*/
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
};
|
|
348
|
-
return feature(geom, properties, options);
|
|
349
|
-
}
|
|
288
|
+
declare function multiLineString<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
|
|
289
|
+
bbox?: BBox;
|
|
290
|
+
id?: Id;
|
|
291
|
+
}): Feature<MultiLineString, P>;
|
|
350
292
|
/**
|
|
351
293
|
* Creates a {@link Feature<MultiPoint>} based on a
|
|
352
294
|
* coordinate array. Properties can be added optionally.
|
|
@@ -364,13 +306,10 @@ export function multiLineString(coordinates, properties, options = {}) {
|
|
|
364
306
|
*
|
|
365
307
|
* //=multiPt
|
|
366
308
|
*/
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
};
|
|
372
|
-
return feature(geom, properties, options);
|
|
373
|
-
}
|
|
309
|
+
declare function multiPoint<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
|
|
310
|
+
bbox?: BBox;
|
|
311
|
+
id?: Id;
|
|
312
|
+
}): Feature<MultiPoint, P>;
|
|
374
313
|
/**
|
|
375
314
|
* Creates a {@link Feature<MultiPolygon>} based on a
|
|
376
315
|
* coordinate array. Properties can be added optionally.
|
|
@@ -389,13 +328,10 @@ export function multiPoint(coordinates, properties, options = {}) {
|
|
|
389
328
|
* //=multiPoly
|
|
390
329
|
*
|
|
391
330
|
*/
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
};
|
|
397
|
-
return feature(geom, properties, options);
|
|
398
|
-
}
|
|
331
|
+
declare function multiPolygon<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: {
|
|
332
|
+
bbox?: BBox;
|
|
333
|
+
id?: Id;
|
|
334
|
+
}): Feature<MultiPolygon, P>;
|
|
399
335
|
/**
|
|
400
336
|
* Creates a {@link Feature<GeometryCollection>} based on a
|
|
401
337
|
* coordinate array. Properties can be added optionally.
|
|
@@ -414,13 +350,10 @@ export function multiPolygon(coordinates, properties, options = {}) {
|
|
|
414
350
|
*
|
|
415
351
|
* // => collection
|
|
416
352
|
*/
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
};
|
|
422
|
-
return feature(geom, properties, options);
|
|
423
|
-
}
|
|
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>;
|
|
424
357
|
/**
|
|
425
358
|
* Round number to precision
|
|
426
359
|
*
|
|
@@ -434,13 +367,7 @@ export function geometryCollection(geometries, properties, options = {}) {
|
|
|
434
367
|
* turf.round(120.4321, 2)
|
|
435
368
|
* //=120.43
|
|
436
369
|
*/
|
|
437
|
-
|
|
438
|
-
if (precision && !(precision >= 0)) {
|
|
439
|
-
throw new Error("precision must be a positive number");
|
|
440
|
-
}
|
|
441
|
-
const multiplier = Math.pow(10, precision || 0);
|
|
442
|
-
return Math.round(num * multiplier) / multiplier;
|
|
443
|
-
}
|
|
370
|
+
declare function round(num: number, precision?: number): number;
|
|
444
371
|
/**
|
|
445
372
|
* Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
|
|
446
373
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
@@ -451,13 +378,7 @@ export function round(num, precision = 0) {
|
|
|
451
378
|
* meters, kilometres, kilometers.
|
|
452
379
|
* @returns {number} distance
|
|
453
380
|
*/
|
|
454
|
-
|
|
455
|
-
const factor = factors[units];
|
|
456
|
-
if (!factor) {
|
|
457
|
-
throw new Error(units + " units is invalid");
|
|
458
|
-
}
|
|
459
|
-
return radians * factor;
|
|
460
|
-
}
|
|
381
|
+
declare function radiansToLength(radians: number, units?: Units): number;
|
|
461
382
|
/**
|
|
462
383
|
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
|
|
463
384
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
@@ -468,13 +389,7 @@ export function radiansToLength(radians, units = "kilometers") {
|
|
|
468
389
|
* meters, kilometres, kilometers.
|
|
469
390
|
* @returns {number} radians
|
|
470
391
|
*/
|
|
471
|
-
|
|
472
|
-
const factor = factors[units];
|
|
473
|
-
if (!factor) {
|
|
474
|
-
throw new Error(units + " units is invalid");
|
|
475
|
-
}
|
|
476
|
-
return distance / factor;
|
|
477
|
-
}
|
|
392
|
+
declare function lengthToRadians(distance: number, units?: Units): number;
|
|
478
393
|
/**
|
|
479
394
|
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
|
|
480
395
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
|
|
@@ -485,9 +400,7 @@ export function lengthToRadians(distance, units = "kilometers") {
|
|
|
485
400
|
* meters, kilometres, kilometers.
|
|
486
401
|
* @returns {number} degrees
|
|
487
402
|
*/
|
|
488
|
-
|
|
489
|
-
return radiansToDegrees(lengthToRadians(distance, units));
|
|
490
|
-
}
|
|
403
|
+
declare function lengthToDegrees(distance: number, units?: Units): number;
|
|
491
404
|
/**
|
|
492
405
|
* Converts any bearing angle from the north line direction (positive clockwise)
|
|
493
406
|
* and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
|
|
@@ -496,13 +409,7 @@ export function lengthToDegrees(distance, units) {
|
|
|
496
409
|
* @param {number} bearing angle, between -180 and +180 degrees
|
|
497
410
|
* @returns {number} angle between 0 and 360 degrees
|
|
498
411
|
*/
|
|
499
|
-
|
|
500
|
-
let angle = bearing % 360;
|
|
501
|
-
if (angle < 0) {
|
|
502
|
-
angle += 360;
|
|
503
|
-
}
|
|
504
|
-
return angle;
|
|
505
|
-
}
|
|
412
|
+
declare function bearingToAzimuth(bearing: number): number;
|
|
506
413
|
/**
|
|
507
414
|
* Converts an angle in radians to degrees
|
|
508
415
|
*
|
|
@@ -510,10 +417,7 @@ export function bearingToAzimuth(bearing) {
|
|
|
510
417
|
* @param {number} radians angle in radians
|
|
511
418
|
* @returns {number} degrees between 0 and 360 degrees
|
|
512
419
|
*/
|
|
513
|
-
|
|
514
|
-
const degrees = radians % (2 * Math.PI);
|
|
515
|
-
return (degrees * 180) / Math.PI;
|
|
516
|
-
}
|
|
420
|
+
declare function radiansToDegrees(radians: number): number;
|
|
517
421
|
/**
|
|
518
422
|
* Converts an angle in degrees to radians
|
|
519
423
|
*
|
|
@@ -521,10 +425,7 @@ export function radiansToDegrees(radians) {
|
|
|
521
425
|
* @param {number} degrees angle between 0 and 360 degrees
|
|
522
426
|
* @returns {number} angle in radians
|
|
523
427
|
*/
|
|
524
|
-
|
|
525
|
-
const radians = degrees % 360;
|
|
526
|
-
return (radians * Math.PI) / 180;
|
|
527
|
-
}
|
|
428
|
+
declare function degreesToRadians(degrees: number): number;
|
|
528
429
|
/**
|
|
529
430
|
* Converts a length to the requested unit.
|
|
530
431
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
@@ -534,12 +435,7 @@ export function degreesToRadians(degrees) {
|
|
|
534
435
|
* @param {Units} [finalUnit="kilometers"] returned unit
|
|
535
436
|
* @returns {number} the converted length
|
|
536
437
|
*/
|
|
537
|
-
|
|
538
|
-
if (!(length >= 0)) {
|
|
539
|
-
throw new Error("length must be a positive number");
|
|
540
|
-
}
|
|
541
|
-
return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
|
|
542
|
-
}
|
|
438
|
+
declare function convertLength(length: number, originalUnit?: Units, finalUnit?: Units): number;
|
|
543
439
|
/**
|
|
544
440
|
* Converts a area to the requested unit.
|
|
545
441
|
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares
|
|
@@ -548,20 +444,7 @@ export function convertLength(length, originalUnit = "kilometers", finalUnit = "
|
|
|
548
444
|
* @param {Units} [finalUnit="kilometers"] returned unit
|
|
549
445
|
* @returns {number} the converted area
|
|
550
446
|
*/
|
|
551
|
-
|
|
552
|
-
if (!(area >= 0)) {
|
|
553
|
-
throw new Error("area must be a positive number");
|
|
554
|
-
}
|
|
555
|
-
const startFactor = areaFactors[originalUnit];
|
|
556
|
-
if (!startFactor) {
|
|
557
|
-
throw new Error("invalid original units");
|
|
558
|
-
}
|
|
559
|
-
const finalFactor = areaFactors[finalUnit];
|
|
560
|
-
if (!finalFactor) {
|
|
561
|
-
throw new Error("invalid final units");
|
|
562
|
-
}
|
|
563
|
-
return (area / startFactor) * finalFactor;
|
|
564
|
-
}
|
|
447
|
+
declare function convertArea(area: number, originalUnit?: AreaUnits, finalUnit?: AreaUnits): number;
|
|
565
448
|
/**
|
|
566
449
|
* isNumber
|
|
567
450
|
*
|
|
@@ -573,9 +456,7 @@ export function convertArea(area, originalUnit = "meters", finalUnit = "kilomete
|
|
|
573
456
|
* turf.isNumber('foo')
|
|
574
457
|
* //=false
|
|
575
458
|
*/
|
|
576
|
-
|
|
577
|
-
return !isNaN(num) && num !== null && !Array.isArray(num);
|
|
578
|
-
}
|
|
459
|
+
declare function isNumber(num: any): boolean;
|
|
579
460
|
/**
|
|
580
461
|
* isObject
|
|
581
462
|
*
|
|
@@ -587,9 +468,7 @@ export function isNumber(num) {
|
|
|
587
468
|
* turf.isObject('foo')
|
|
588
469
|
* //=false
|
|
589
470
|
*/
|
|
590
|
-
|
|
591
|
-
return input !== null && typeof input === "object" && !Array.isArray(input);
|
|
592
|
-
}
|
|
471
|
+
declare function isObject(input: any): boolean;
|
|
593
472
|
/**
|
|
594
473
|
* Validate BBox
|
|
595
474
|
*
|
|
@@ -611,22 +490,7 @@ export function isObject(input) {
|
|
|
611
490
|
* validateBBox(undefined)
|
|
612
491
|
* //=Error
|
|
613
492
|
*/
|
|
614
|
-
|
|
615
|
-
if (!bbox) {
|
|
616
|
-
throw new Error("bbox is required");
|
|
617
|
-
}
|
|
618
|
-
if (!Array.isArray(bbox)) {
|
|
619
|
-
throw new Error("bbox must be an Array");
|
|
620
|
-
}
|
|
621
|
-
if (bbox.length !== 4 && bbox.length !== 6) {
|
|
622
|
-
throw new Error("bbox must be an Array of 4 or 6 numbers");
|
|
623
|
-
}
|
|
624
|
-
bbox.forEach((num) => {
|
|
625
|
-
if (!isNumber(num)) {
|
|
626
|
-
throw new Error("bbox must only contain numbers");
|
|
627
|
-
}
|
|
628
|
-
});
|
|
629
|
-
}
|
|
493
|
+
declare function validateBBox(bbox: any): void;
|
|
630
494
|
/**
|
|
631
495
|
* Validate Id
|
|
632
496
|
*
|
|
@@ -648,11 +512,6 @@ export function validateBBox(bbox) {
|
|
|
648
512
|
* validateId(undefined)
|
|
649
513
|
* //=Error
|
|
650
514
|
*/
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
if (["string", "number"].indexOf(typeof id) === -1) {
|
|
656
|
-
throw new Error("id must be a number or a string");
|
|
657
|
-
}
|
|
658
|
-
}
|
|
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 };
|