index.d.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. import { BBox, CollectionTypes, Feature, FeatureCollection, GeoJSONObject, Geometries, Geometry, GeometryCollection, GeometryObject, GeometryTypes, Id, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Position, Properties, Types } from "./lib/geojson";
  2. export { Id, Properties, BBox, Position, Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryObject, GeoJSONObject, GeometryCollection, Geometry, GeometryTypes, Types, CollectionTypes, Geometries, Feature, FeatureCollection, };
  3. export declare type Coord = Feature<Point> | Point | Position;
  4. export declare type Units = "meters" | "millimeters" | "centimeters" | "kilometers" | "acres" | "miles" | "nauticalmiles" | "inches" | "yards" | "feet" | "radians" | "degrees" | "hectares";
  5. export declare type Grid = "point" | "square" | "hex" | "triangle";
  6. export declare type Corners = "sw" | "se" | "nw" | "ne" | "center" | "centroid";
  7. export declare type Lines = LineString | MultiLineString | Polygon | MultiPolygon;
  8. export declare type AllGeoJSON = Feature | FeatureCollection | Geometry | GeometryCollection;
  9. /**
  10. * @module helpers
  11. */
  12. /**
  13. * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
  14. *
  15. * @memberof helpers
  16. * @type {number}
  17. */
  18. export declare let earthRadius: number;
  19. /**
  20. * Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
  21. *
  22. * @memberof helpers
  23. * @type {Object}
  24. */
  25. export declare let factors: {
  26. [key: string]: number;
  27. };
  28. /**
  29. * Units of measurement factors based on 1 meter.
  30. *
  31. * @memberof helpers
  32. * @type {Object}
  33. */
  34. export declare let unitsFactors: {
  35. [key: string]: number;
  36. };
  37. /**
  38. * Area of measurement factors based on 1 square meter.
  39. *
  40. * @memberof helpers
  41. * @type {Object}
  42. */
  43. export declare let areaFactors: any;
  44. /**
  45. * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
  46. *
  47. * @name feature
  48. * @param {Geometry} geometry input geometry
  49. * @param {Object} [properties={}] an Object of key-value pairs to add as properties
  50. * @param {Object} [options={}] Optional Parameters
  51. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
  52. * @param {string|number} [options.id] Identifier associated with the Feature
  53. * @returns {Feature} a GeoJSON Feature
  54. * @example
  55. * var geometry = {
  56. * "type": "Point",
  57. * "coordinates": [110, 50]
  58. * };
  59. *
  60. * var feature = turf.feature(geometry);
  61. *
  62. * //=feature
  63. */
  64. export declare function feature<G = Geometry, P = Properties>(geom: G, properties?: P, options?: {
  65. bbox?: BBox;
  66. id?: Id;
  67. }): Feature<G, P>;
  68. /**
  69. * Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
  70. * For GeometryCollection type use `helpers.geometryCollection`
  71. *
  72. * @name geometry
  73. * @param {string} type Geometry Type
  74. * @param {Array<any>} coordinates Coordinates
  75. * @param {Object} [options={}] Optional Parameters
  76. * @returns {Geometry} a GeoJSON Geometry
  77. * @example
  78. * var type = "Point";
  79. * var coordinates = [110, 50];
  80. * var geometry = turf.geometry(type, coordinates);
  81. * // => geometry
  82. */
  83. export declare function geometry(type: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon", coordinates: any[], _options?: Record<string, never>): Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon;
  84. /**
  85. * Creates a {@link Point} {@link Feature} from a Position.
  86. *
  87. * @name point
  88. * @param {Array<number>} coordinates longitude, latitude position (each in decimal degrees)
  89. * @param {Object} [properties={}] an Object of key-value pairs to add as properties
  90. * @param {Object} [options={}] Optional Parameters
  91. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
  92. * @param {string|number} [options.id] Identifier associated with the Feature
  93. * @returns {Feature<Point>} a Point feature
  94. * @example
  95. * var point = turf.point([-75.343, 39.984]);
  96. *
  97. * //=point
  98. */
  99. export declare function point<P = Properties>(coordinates: Position, properties?: P, options?: {
  100. bbox?: BBox;
  101. id?: Id;
  102. }): Feature<Point, P>;
  103. /**
  104. * Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
  105. *
  106. * @name points
  107. * @param {Array<Array<number>>} coordinates an array of Points
  108. * @param {Object} [properties={}] Translate these properties to each Feature
  109. * @param {Object} [options={}] Optional Parameters
  110. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]
  111. * associated with the FeatureCollection
  112. * @param {string|number} [options.id] Identifier associated with the FeatureCollection
  113. * @returns {FeatureCollection<Point>} Point Feature
  114. * @example
  115. * var points = turf.points([
  116. * [-75, 39],
  117. * [-80, 45],
  118. * [-78, 50]
  119. * ]);
  120. *
  121. * //=points
  122. */
  123. export declare function points<P = Properties>(coordinates: Position[], properties?: P, options?: {
  124. bbox?: BBox;
  125. id?: Id;
  126. }): FeatureCollection<Point, P>;
  127. /**
  128. * Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
  129. *
  130. * @name polygon
  131. * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings
  132. * @param {Object} [properties={}] an Object of key-value pairs to add as properties
  133. * @param {Object} [options={}] Optional Parameters
  134. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
  135. * @param {string|number} [options.id] Identifier associated with the Feature
  136. * @returns {Feature<Polygon>} Polygon Feature
  137. * @example
  138. * var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });
  139. *
  140. * //=polygon
  141. */
  142. export declare function polygon<P = Properties>(coordinates: Position[][], properties?: P, options?: {
  143. bbox?: BBox;
  144. id?: Id;
  145. }): Feature<Polygon, P>;
  146. /**
  147. * Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
  148. *
  149. * @name polygons
  150. * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygon coordinates
  151. * @param {Object} [properties={}] an Object of key-value pairs to add as properties
  152. * @param {Object} [options={}] Optional Parameters
  153. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
  154. * @param {string|number} [options.id] Identifier associated with the FeatureCollection
  155. * @returns {FeatureCollection<Polygon>} Polygon FeatureCollection
  156. * @example
  157. * var polygons = turf.polygons([
  158. * [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
  159. * [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
  160. * ]);
  161. *
  162. * //=polygons
  163. */
  164. export declare function polygons<P = Properties>(coordinates: Position[][][], properties?: P, options?: {
  165. bbox?: BBox;
  166. id?: Id;
  167. }): FeatureCollection<Polygon, P>;
  168. /**
  169. * Creates a {@link LineString} {@link Feature} from an Array of Positions.
  170. *
  171. * @name lineString
  172. * @param {Array<Array<number>>} coordinates an array of Positions
  173. * @param {Object} [properties={}] an Object of key-value pairs to add as properties
  174. * @param {Object} [options={}] Optional Parameters
  175. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
  176. * @param {string|number} [options.id] Identifier associated with the Feature
  177. * @returns {Feature<LineString>} LineString Feature
  178. * @example
  179. * var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
  180. * var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
  181. *
  182. * //=linestring1
  183. * //=linestring2
  184. */
  185. export declare function lineString<P = Properties>(coordinates: Position[], properties?: P, options?: {
  186. bbox?: BBox;
  187. id?: Id;
  188. }): Feature<LineString, P>;
  189. /**
  190. * Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
  191. *
  192. * @name lineStrings
  193. * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings
  194. * @param {Object} [properties={}] an Object of key-value pairs to add as properties
  195. * @param {Object} [options={}] Optional Parameters
  196. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]
  197. * associated with the FeatureCollection
  198. * @param {string|number} [options.id] Identifier associated with the FeatureCollection
  199. * @returns {FeatureCollection<LineString>} LineString FeatureCollection
  200. * @example
  201. * var linestrings = turf.lineStrings([
  202. * [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
  203. * [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
  204. * ]);
  205. *
  206. * //=linestrings
  207. */
  208. export declare function lineStrings<P = Properties>(coordinates: Position[][], properties?: P, options?: {
  209. bbox?: BBox;
  210. id?: Id;
  211. }): FeatureCollection<LineString, P>;
  212. /**
  213. * Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
  214. *
  215. * @name featureCollection
  216. * @param {Feature[]} features input features
  217. * @param {Object} [options={}] Optional Parameters
  218. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
  219. * @param {string|number} [options.id] Identifier associated with the Feature
  220. * @returns {FeatureCollection} FeatureCollection of Features
  221. * @example
  222. * var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
  223. * var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
  224. * var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
  225. *
  226. * var collection = turf.featureCollection([
  227. * locationA,
  228. * locationB,
  229. * locationC
  230. * ]);
  231. *
  232. * //=collection
  233. */
  234. export declare function featureCollection<G = Geometry, P = Properties>(features: Array<Feature<G, P>>, options?: {
  235. bbox?: BBox;
  236. id?: Id;
  237. }): FeatureCollection<G, P>;
  238. /**
  239. * Creates a {@link Feature<MultiLineString>} based on a
  240. * coordinate array. Properties can be added optionally.
  241. *
  242. * @name multiLineString
  243. * @param {Array<Array<Array<number>>>} coordinates an array of LineStrings
  244. * @param {Object} [properties={}] an Object of key-value pairs to add as properties
  245. * @param {Object} [options={}] Optional Parameters
  246. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
  247. * @param {string|number} [options.id] Identifier associated with the Feature
  248. * @returns {Feature<MultiLineString>} a MultiLineString feature
  249. * @throws {Error} if no coordinates are passed
  250. * @example
  251. * var multiLine = turf.multiLineString([[[0,0],[10,10]]]);
  252. *
  253. * //=multiLine
  254. */
  255. export declare function multiLineString<P = Properties>(coordinates: Position[][], properties?: P, options?: {
  256. bbox?: BBox;
  257. id?: Id;
  258. }): Feature<MultiLineString, P>;
  259. /**
  260. * Creates a {@link Feature<MultiPoint>} based on a
  261. * coordinate array. Properties can be added optionally.
  262. *
  263. * @name multiPoint
  264. * @param {Array<Array<number>>} coordinates an array of Positions
  265. * @param {Object} [properties={}] an Object of key-value pairs to add as properties
  266. * @param {Object} [options={}] Optional Parameters
  267. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
  268. * @param {string|number} [options.id] Identifier associated with the Feature
  269. * @returns {Feature<MultiPoint>} a MultiPoint feature
  270. * @throws {Error} if no coordinates are passed
  271. * @example
  272. * var multiPt = turf.multiPoint([[0,0],[10,10]]);
  273. *
  274. * //=multiPt
  275. */
  276. export declare function multiPoint<P = Properties>(coordinates: Position[], properties?: P, options?: {
  277. bbox?: BBox;
  278. id?: Id;
  279. }): Feature<MultiPoint, P>;
  280. /**
  281. * Creates a {@link Feature<MultiPolygon>} based on a
  282. * coordinate array. Properties can be added optionally.
  283. *
  284. * @name multiPolygon
  285. * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygons
  286. * @param {Object} [properties={}] an Object of key-value pairs to add as properties
  287. * @param {Object} [options={}] Optional Parameters
  288. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
  289. * @param {string|number} [options.id] Identifier associated with the Feature
  290. * @returns {Feature<MultiPolygon>} a multipolygon feature
  291. * @throws {Error} if no coordinates are passed
  292. * @example
  293. * var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);
  294. *
  295. * //=multiPoly
  296. *
  297. */
  298. export declare function multiPolygon<P = Properties>(coordinates: Position[][][], properties?: P, options?: {
  299. bbox?: BBox;
  300. id?: Id;
  301. }): Feature<MultiPolygon, P>;
  302. /**
  303. * Creates a {@link Feature<GeometryCollection>} based on a
  304. * coordinate array. Properties can be added optionally.
  305. *
  306. * @name geometryCollection
  307. * @param {Array<Geometry>} geometries an array of GeoJSON Geometries
  308. * @param {Object} [properties={}] an Object of key-value pairs to add as properties
  309. * @param {Object} [options={}] Optional Parameters
  310. * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
  311. * @param {string|number} [options.id] Identifier associated with the Feature
  312. * @returns {Feature<GeometryCollection>} a GeoJSON GeometryCollection Feature
  313. * @example
  314. * var pt = turf.geometry("Point", [100, 0]);
  315. * var line = turf.geometry("LineString", [[101, 0], [102, 1]]);
  316. * var collection = turf.geometryCollection([pt, line]);
  317. *
  318. * // => collection
  319. */
  320. export declare function geometryCollection<P = Properties>(geometries: Array<Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon>, properties?: P, options?: {
  321. bbox?: BBox;
  322. id?: Id;
  323. }): Feature<GeometryCollection, P>;
  324. /**
  325. * Round number to precision
  326. *
  327. * @param {number} num Number
  328. * @param {number} [precision=0] Precision
  329. * @returns {number} rounded number
  330. * @example
  331. * turf.round(120.4321)
  332. * //=120
  333. *
  334. * turf.round(120.4321, 2)
  335. * //=120.43
  336. */
  337. export declare function round(num: number, precision?: number): number;
  338. /**
  339. * Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
  340. * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
  341. *
  342. * @name radiansToLength
  343. * @param {number} radians in radians across the sphere
  344. * @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
  345. * meters, kilometres, kilometers.
  346. * @returns {number} distance
  347. */
  348. export declare function radiansToLength(radians: number, units?: Units): number;
  349. /**
  350. * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
  351. * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
  352. *
  353. * @name lengthToRadians
  354. * @param {number} distance in real units
  355. * @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
  356. * meters, kilometres, kilometers.
  357. * @returns {number} radians
  358. */
  359. export declare function lengthToRadians(distance: number, units?: Units): number;
  360. /**
  361. * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
  362. * Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
  363. *
  364. * @name lengthToDegrees
  365. * @param {number} distance in real units
  366. * @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
  367. * meters, kilometres, kilometers.
  368. * @returns {number} degrees
  369. */
  370. export declare function lengthToDegrees(distance: number, units?: Units): number;
  371. /**
  372. * Converts any bearing angle from the north line direction (positive clockwise)
  373. * and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
  374. *
  375. * @name bearingToAzimuth
  376. * @param {number} bearing angle, between -180 and +180 degrees
  377. * @returns {number} angle between 0 and 360 degrees
  378. */
  379. export declare function bearingToAzimuth(bearing: number): number;
  380. /**
  381. * Converts an angle in radians to degrees
  382. *
  383. * @name radiansToDegrees
  384. * @param {number} radians angle in radians
  385. * @returns {number} degrees between 0 and 360 degrees
  386. */
  387. export declare function radiansToDegrees(radians: number): number;
  388. /**
  389. * Converts an angle in degrees to radians
  390. *
  391. * @name degreesToRadians
  392. * @param {number} degrees angle between 0 and 360 degrees
  393. * @returns {number} angle in radians
  394. */
  395. export declare function degreesToRadians(degrees: number): number;
  396. /**
  397. * Converts a length to the requested unit.
  398. * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
  399. *
  400. * @param {number} length to be converted
  401. * @param {Units} [originalUnit="kilometers"] of the length
  402. * @param {Units} [finalUnit="kilometers"] returned unit
  403. * @returns {number} the converted length
  404. */
  405. export declare function convertLength(length: number, originalUnit?: Units, finalUnit?: Units): number;
  406. /**
  407. * Converts a area to the requested unit.
  408. * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares
  409. * @param {number} area to be converted
  410. * @param {Units} [originalUnit="meters"] of the distance
  411. * @param {Units} [finalUnit="kilometers"] returned unit
  412. * @returns {number} the converted area
  413. */
  414. export declare function convertArea(area: number, originalUnit?: Units, finalUnit?: Units): number;
  415. /**
  416. * isNumber
  417. *
  418. * @param {*} num Number to validate
  419. * @returns {boolean} true/false
  420. * @example
  421. * turf.isNumber(123)
  422. * //=true
  423. * turf.isNumber('foo')
  424. * //=false
  425. */
  426. export declare function isNumber(num: any): boolean;
  427. /**
  428. * isObject
  429. *
  430. * @param {*} input variable to validate
  431. * @returns {boolean} true/false
  432. * @example
  433. * turf.isObject({elevation: 10})
  434. * //=true
  435. * turf.isObject('foo')
  436. * //=false
  437. */
  438. export declare function isObject(input: any): boolean;
  439. /**
  440. * Validate BBox
  441. *
  442. * @private
  443. * @param {Array<number>} bbox BBox to validate
  444. * @returns {void}
  445. * @throws Error if BBox is not valid
  446. * @example
  447. * validateBBox([-180, -40, 110, 50])
  448. * //=OK
  449. * validateBBox([-180, -40])
  450. * //=Error
  451. * validateBBox('Foo')
  452. * //=Error
  453. * validateBBox(5)
  454. * //=Error
  455. * validateBBox(null)
  456. * //=Error
  457. * validateBBox(undefined)
  458. * //=Error
  459. */
  460. export declare function validateBBox(bbox: any): void;
  461. /**
  462. * Validate Id
  463. *
  464. * @private
  465. * @param {string|number} id Id to validate
  466. * @returns {void}
  467. * @throws Error if Id is not valid
  468. * @example
  469. * validateId([-180, -40, 110, 50])
  470. * //=Error
  471. * validateId([-180, -40])
  472. * //=Error
  473. * validateId('Foo')
  474. * //=OK
  475. * validateId(5)
  476. * //=OK
  477. * validateId(null)
  478. * //=Error
  479. * validateId(undefined)
  480. * //=Error
  481. */
  482. export declare function validateId(id: any): void;