@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,13 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
11
50
|
/**
|
|
12
51
|
* @module helpers
|
|
13
52
|
*/
|
|
@@ -17,7 +56,7 @@ export declare type AllGeoJSON = Feature | FeatureCollection | Geometry | Geomet
|
|
|
17
56
|
* @memberof helpers
|
|
18
57
|
* @type {number}
|
|
19
58
|
*/
|
|
20
|
-
|
|
59
|
+
declare const earthRadius = 6371008.8;
|
|
21
60
|
/**
|
|
22
61
|
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
|
|
23
62
|
*
|
|
@@ -26,7 +65,7 @@ export declare const earthRadius = 6371008.8;
|
|
|
26
65
|
* @memberof helpers
|
|
27
66
|
* @type {Object}
|
|
28
67
|
*/
|
|
29
|
-
|
|
68
|
+
declare const factors: Record<Units, number>;
|
|
30
69
|
/**
|
|
31
70
|
|
|
32
71
|
* Area of measurement factors based on 1 square meter.
|
|
@@ -34,7 +73,7 @@ export declare const factors: Record<Units, number>;
|
|
|
34
73
|
* @memberof helpers
|
|
35
74
|
* @type {Object}
|
|
36
75
|
*/
|
|
37
|
-
|
|
76
|
+
declare const areaFactors: Record<AreaUnits, number>;
|
|
38
77
|
/**
|
|
39
78
|
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
|
|
40
79
|
*
|
|
@@ -55,7 +94,7 @@ export declare const areaFactors: Record<AreaUnits, number>;
|
|
|
55
94
|
*
|
|
56
95
|
* //=feature
|
|
57
96
|
*/
|
|
58
|
-
|
|
97
|
+
declare function feature<G extends GeometryObject = Geometry, P extends GeoJsonProperties = GeoJsonProperties>(geom: G | null, properties?: P, options?: {
|
|
59
98
|
bbox?: BBox;
|
|
60
99
|
id?: Id;
|
|
61
100
|
}): Feature<G, P>;
|
|
@@ -74,7 +113,7 @@ export declare function feature<G extends GeometryObject = Geometry, P = GeoJson
|
|
|
74
113
|
* var geometry = turf.geometry(type, coordinates);
|
|
75
114
|
* // => geometry
|
|
76
115
|
*/
|
|
77
|
-
|
|
116
|
+
declare function geometry(type: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon", coordinates: any[], _options?: Record<string, never>): Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
|
|
78
117
|
/**
|
|
79
118
|
* Creates a {@link Point} {@link Feature} from a Position.
|
|
80
119
|
*
|
|
@@ -90,7 +129,7 @@ export declare function geometry(type: "Point" | "LineString" | "Polygon" | "Mul
|
|
|
90
129
|
*
|
|
91
130
|
* //=point
|
|
92
131
|
*/
|
|
93
|
-
|
|
132
|
+
declare function point<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position, properties?: P, options?: {
|
|
94
133
|
bbox?: BBox;
|
|
95
134
|
id?: Id;
|
|
96
135
|
}): Feature<Point, P>;
|
|
@@ -114,7 +153,7 @@ export declare function point<P = GeoJsonProperties>(coordinates: Position, prop
|
|
|
114
153
|
*
|
|
115
154
|
* //=points
|
|
116
155
|
*/
|
|
117
|
-
|
|
156
|
+
declare function points<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
|
|
118
157
|
bbox?: BBox;
|
|
119
158
|
id?: Id;
|
|
120
159
|
}): FeatureCollection<Point, P>;
|
|
@@ -133,7 +172,7 @@ export declare function points<P = GeoJsonProperties>(coordinates: Position[], p
|
|
|
133
172
|
*
|
|
134
173
|
* //=polygon
|
|
135
174
|
*/
|
|
136
|
-
|
|
175
|
+
declare function polygon<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
|
|
137
176
|
bbox?: BBox;
|
|
138
177
|
id?: Id;
|
|
139
178
|
}): Feature<Polygon, P>;
|
|
@@ -155,7 +194,7 @@ export declare function polygon<P = GeoJsonProperties>(coordinates: Position[][]
|
|
|
155
194
|
*
|
|
156
195
|
* //=polygons
|
|
157
196
|
*/
|
|
158
|
-
|
|
197
|
+
declare function polygons<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: {
|
|
159
198
|
bbox?: BBox;
|
|
160
199
|
id?: Id;
|
|
161
200
|
}): FeatureCollection<Polygon, P>;
|
|
@@ -176,7 +215,7 @@ export declare function polygons<P = GeoJsonProperties>(coordinates: Position[][
|
|
|
176
215
|
* //=linestring1
|
|
177
216
|
* //=linestring2
|
|
178
217
|
*/
|
|
179
|
-
|
|
218
|
+
declare function lineString<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
|
|
180
219
|
bbox?: BBox;
|
|
181
220
|
id?: Id;
|
|
182
221
|
}): Feature<LineString, P>;
|
|
@@ -199,7 +238,7 @@ export declare function lineString<P = GeoJsonProperties>(coordinates: Position[
|
|
|
199
238
|
*
|
|
200
239
|
* //=linestrings
|
|
201
240
|
*/
|
|
202
|
-
|
|
241
|
+
declare function lineStrings<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
|
|
203
242
|
bbox?: BBox;
|
|
204
243
|
id?: Id;
|
|
205
244
|
}): FeatureCollection<LineString, P>;
|
|
@@ -225,7 +264,7 @@ export declare function lineStrings<P = GeoJsonProperties>(coordinates: Position
|
|
|
225
264
|
*
|
|
226
265
|
* //=collection
|
|
227
266
|
*/
|
|
228
|
-
|
|
267
|
+
declare function featureCollection<G extends GeometryObject = Geometry, P extends GeoJsonProperties = GeoJsonProperties>(features: Array<Feature<G, P>>, options?: {
|
|
229
268
|
bbox?: BBox;
|
|
230
269
|
id?: Id;
|
|
231
270
|
}): FeatureCollection<G, P>;
|
|
@@ -246,7 +285,7 @@ export declare function featureCollection<G extends GeometryObject = Geometry, P
|
|
|
246
285
|
*
|
|
247
286
|
* //=multiLine
|
|
248
287
|
*/
|
|
249
|
-
|
|
288
|
+
declare function multiLineString<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
|
|
250
289
|
bbox?: BBox;
|
|
251
290
|
id?: Id;
|
|
252
291
|
}): Feature<MultiLineString, P>;
|
|
@@ -267,7 +306,7 @@ export declare function multiLineString<P = GeoJsonProperties>(coordinates: Posi
|
|
|
267
306
|
*
|
|
268
307
|
* //=multiPt
|
|
269
308
|
*/
|
|
270
|
-
|
|
309
|
+
declare function multiPoint<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
|
|
271
310
|
bbox?: BBox;
|
|
272
311
|
id?: Id;
|
|
273
312
|
}): Feature<MultiPoint, P>;
|
|
@@ -289,7 +328,7 @@ export declare function multiPoint<P = GeoJsonProperties>(coordinates: Position[
|
|
|
289
328
|
* //=multiPoly
|
|
290
329
|
*
|
|
291
330
|
*/
|
|
292
|
-
|
|
331
|
+
declare function multiPolygon<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: {
|
|
293
332
|
bbox?: BBox;
|
|
294
333
|
id?: Id;
|
|
295
334
|
}): Feature<MultiPolygon, P>;
|
|
@@ -311,7 +350,7 @@ export declare function multiPolygon<P = GeoJsonProperties>(coordinates: Positio
|
|
|
311
350
|
*
|
|
312
351
|
* // => collection
|
|
313
352
|
*/
|
|
314
|
-
|
|
353
|
+
declare function geometryCollection<P extends GeoJsonProperties = GeoJsonProperties>(geometries: Array<Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon>, properties?: P, options?: {
|
|
315
354
|
bbox?: BBox;
|
|
316
355
|
id?: Id;
|
|
317
356
|
}): Feature<GeometryCollection, P>;
|
|
@@ -328,7 +367,7 @@ export declare function geometryCollection<P = GeoJsonProperties>(geometries: Ar
|
|
|
328
367
|
* turf.round(120.4321, 2)
|
|
329
368
|
* //=120.43
|
|
330
369
|
*/
|
|
331
|
-
|
|
370
|
+
declare function round(num: number, precision?: number): number;
|
|
332
371
|
/**
|
|
333
372
|
* Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
|
|
334
373
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
@@ -339,7 +378,7 @@ export declare function round(num: number, precision?: number): number;
|
|
|
339
378
|
* meters, kilometres, kilometers.
|
|
340
379
|
* @returns {number} distance
|
|
341
380
|
*/
|
|
342
|
-
|
|
381
|
+
declare function radiansToLength(radians: number, units?: Units): number;
|
|
343
382
|
/**
|
|
344
383
|
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
|
|
345
384
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
@@ -350,7 +389,7 @@ export declare function radiansToLength(radians: number, units?: Units): number;
|
|
|
350
389
|
* meters, kilometres, kilometers.
|
|
351
390
|
* @returns {number} radians
|
|
352
391
|
*/
|
|
353
|
-
|
|
392
|
+
declare function lengthToRadians(distance: number, units?: Units): number;
|
|
354
393
|
/**
|
|
355
394
|
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
|
|
356
395
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
|
|
@@ -361,7 +400,7 @@ export declare function lengthToRadians(distance: number, units?: Units): number
|
|
|
361
400
|
* meters, kilometres, kilometers.
|
|
362
401
|
* @returns {number} degrees
|
|
363
402
|
*/
|
|
364
|
-
|
|
403
|
+
declare function lengthToDegrees(distance: number, units?: Units): number;
|
|
365
404
|
/**
|
|
366
405
|
* Converts any bearing angle from the north line direction (positive clockwise)
|
|
367
406
|
* and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
|
|
@@ -370,7 +409,7 @@ export declare function lengthToDegrees(distance: number, units?: Units): number
|
|
|
370
409
|
* @param {number} bearing angle, between -180 and +180 degrees
|
|
371
410
|
* @returns {number} angle between 0 and 360 degrees
|
|
372
411
|
*/
|
|
373
|
-
|
|
412
|
+
declare function bearingToAzimuth(bearing: number): number;
|
|
374
413
|
/**
|
|
375
414
|
* Converts an angle in radians to degrees
|
|
376
415
|
*
|
|
@@ -378,7 +417,7 @@ export declare function bearingToAzimuth(bearing: number): number;
|
|
|
378
417
|
* @param {number} radians angle in radians
|
|
379
418
|
* @returns {number} degrees between 0 and 360 degrees
|
|
380
419
|
*/
|
|
381
|
-
|
|
420
|
+
declare function radiansToDegrees(radians: number): number;
|
|
382
421
|
/**
|
|
383
422
|
* Converts an angle in degrees to radians
|
|
384
423
|
*
|
|
@@ -386,7 +425,7 @@ export declare function radiansToDegrees(radians: number): number;
|
|
|
386
425
|
* @param {number} degrees angle between 0 and 360 degrees
|
|
387
426
|
* @returns {number} angle in radians
|
|
388
427
|
*/
|
|
389
|
-
|
|
428
|
+
declare function degreesToRadians(degrees: number): number;
|
|
390
429
|
/**
|
|
391
430
|
* Converts a length to the requested unit.
|
|
392
431
|
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
|
|
@@ -396,7 +435,7 @@ export declare function degreesToRadians(degrees: number): number;
|
|
|
396
435
|
* @param {Units} [finalUnit="kilometers"] returned unit
|
|
397
436
|
* @returns {number} the converted length
|
|
398
437
|
*/
|
|
399
|
-
|
|
438
|
+
declare function convertLength(length: number, originalUnit?: Units, finalUnit?: Units): number;
|
|
400
439
|
/**
|
|
401
440
|
* Converts a area to the requested unit.
|
|
402
441
|
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares
|
|
@@ -405,7 +444,7 @@ export declare function convertLength(length: number, originalUnit?: Units, fina
|
|
|
405
444
|
* @param {Units} [finalUnit="kilometers"] returned unit
|
|
406
445
|
* @returns {number} the converted area
|
|
407
446
|
*/
|
|
408
|
-
|
|
447
|
+
declare function convertArea(area: number, originalUnit?: AreaUnits, finalUnit?: AreaUnits): number;
|
|
409
448
|
/**
|
|
410
449
|
* isNumber
|
|
411
450
|
*
|
|
@@ -417,7 +456,7 @@ export declare function convertArea(area: number, originalUnit?: AreaUnits, fina
|
|
|
417
456
|
* turf.isNumber('foo')
|
|
418
457
|
* //=false
|
|
419
458
|
*/
|
|
420
|
-
|
|
459
|
+
declare function isNumber(num: any): boolean;
|
|
421
460
|
/**
|
|
422
461
|
* isObject
|
|
423
462
|
*
|
|
@@ -429,7 +468,7 @@ export declare function isNumber(num: any): boolean;
|
|
|
429
468
|
* turf.isObject('foo')
|
|
430
469
|
* //=false
|
|
431
470
|
*/
|
|
432
|
-
|
|
471
|
+
declare function isObject(input: any): boolean;
|
|
433
472
|
/**
|
|
434
473
|
* Validate BBox
|
|
435
474
|
*
|
|
@@ -451,7 +490,7 @@ export declare function isObject(input: any): boolean;
|
|
|
451
490
|
* validateBBox(undefined)
|
|
452
491
|
* //=Error
|
|
453
492
|
*/
|
|
454
|
-
|
|
493
|
+
declare function validateBBox(bbox: any): void;
|
|
455
494
|
/**
|
|
456
495
|
* Validate Id
|
|
457
496
|
*
|
|
@@ -473,4 +512,6 @@ export declare function validateBBox(bbox: any): void;
|
|
|
473
512
|
* validateId(undefined)
|
|
474
513
|
* //=Error
|
|
475
514
|
*/
|
|
476
|
-
|
|
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 };
|