index.d.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { Feature, FeatureCollection, Geometries, GeometryCollection, Point } from "@turf/helpers";
  2. /**
  3. * Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
  4. *
  5. * @name getCoord
  6. * @param {Array<number>|Geometry<Point>|Feature<Point>} coord GeoJSON Point or an Array of numbers
  7. * @returns {Array<number>} coordinates
  8. * @example
  9. * var pt = turf.point([10, 10]);
  10. *
  11. * var coord = turf.getCoord(pt);
  12. * //= [10, 10]
  13. */
  14. export declare function getCoord(coord: Feature<Point> | Point | number[]): number[];
  15. /**
  16. * Unwrap coordinates from a Feature, Geometry Object or an Array
  17. *
  18. * @name getCoords
  19. * @param {Array<any>|Geometry|Feature} coords Feature, Geometry Object or an Array
  20. * @returns {Array<any>} coordinates
  21. * @example
  22. * var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);
  23. *
  24. * var coords = turf.getCoords(poly);
  25. * //= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]
  26. */
  27. export declare function getCoords<G extends Geometries>(coords: any[] | Feature<G> | G): any[];
  28. /**
  29. * Checks if coordinates contains a number
  30. *
  31. * @name containsNumber
  32. * @param {Array<any>} coordinates GeoJSON Coordinates
  33. * @returns {boolean} true if Array contains a number
  34. */
  35. export declare function containsNumber(coordinates: any[]): boolean;
  36. /**
  37. * Enforce expectations about types of GeoJSON objects for Turf.
  38. *
  39. * @name geojsonType
  40. * @param {GeoJSON} value any GeoJSON object
  41. * @param {string} type expected GeoJSON type
  42. * @param {string} name name of calling function
  43. * @throws {Error} if value is not the expected type.
  44. */
  45. export declare function geojsonType(value: any, type: string, name: string): void;
  46. /**
  47. * Enforce expectations about types of {@link Feature} inputs for Turf.
  48. * Internally this uses {@link geojsonType} to judge geometry types.
  49. *
  50. * @name featureOf
  51. * @param {Feature} feature a feature with an expected geometry type
  52. * @param {string} type expected GeoJSON type
  53. * @param {string} name name of calling function
  54. * @throws {Error} error if value is not the expected type.
  55. */
  56. export declare function featureOf(feature: Feature<any>, type: string, name: string): void;
  57. /**
  58. * Enforce expectations about types of {@link FeatureCollection} inputs for Turf.
  59. * Internally this uses {@link geojsonType} to judge geometry types.
  60. *
  61. * @name collectionOf
  62. * @param {FeatureCollection} featureCollection a FeatureCollection for which features will be judged
  63. * @param {string} type expected GeoJSON type
  64. * @param {string} name name of calling function
  65. * @throws {Error} if value is not the expected type.
  66. */
  67. export declare function collectionOf(featureCollection: FeatureCollection<any>, type: string, name: string): void;
  68. /**
  69. * Get Geometry from Feature or Geometry Object
  70. *
  71. * @param {Feature|Geometry} geojson GeoJSON Feature or Geometry Object
  72. * @returns {Geometry|null} GeoJSON Geometry Object
  73. * @throws {Error} if geojson is not a Feature or Geometry Object
  74. * @example
  75. * var point = {
  76. * "type": "Feature",
  77. * "properties": {},
  78. * "geometry": {
  79. * "type": "Point",
  80. * "coordinates": [110, 40]
  81. * }
  82. * }
  83. * var geom = turf.getGeom(point)
  84. * //={"type": "Point", "coordinates": [110, 40]}
  85. */
  86. export declare function getGeom<G extends Geometries | GeometryCollection>(geojson: Feature<G> | G): G;
  87. /**
  88. * Get GeoJSON object's type, Geometry type is prioritize.
  89. *
  90. * @param {GeoJSON} geojson GeoJSON object
  91. * @param {string} [name="geojson"] name of the variable to display in error message (unused)
  92. * @returns {string} GeoJSON type
  93. * @example
  94. * var point = {
  95. * "type": "Feature",
  96. * "properties": {},
  97. * "geometry": {
  98. * "type": "Point",
  99. * "coordinates": [110, 40]
  100. * }
  101. * }
  102. * var geom = turf.getType(point)
  103. * //="Point"
  104. */
  105. export declare function getType(geojson: Feature<any> | FeatureCollection<any> | Geometries | GeometryCollection, _name?: string): string;