index.d.cts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
  2. /**
  3. * Takes a collection of input polygons and returns a combined polygon. If the
  4. * input polygons are not contiguous, this function returns a multi-polygon
  5. * feature.
  6. *
  7. * @function
  8. * @param {FeatureCollection<Polygon|MultiPolygon>} features input polygon features
  9. * @param {Object} [options={}] Optional Parameters
  10. * @param {GeoJsonProperties} [options.properties={}] properties to assign to output feature
  11. * @returns {Feature<(Polygon|MultiPolygon)>|null} a combined polygon or multi-polygon feature, or null if there were no input polygons to combine
  12. * @example
  13. *
  14. * const poly1 = turf.polygon(
  15. * [
  16. * [
  17. * [-82.574787, 35.594087],
  18. * [-82.574787, 35.615581],
  19. * [-82.545261, 35.615581],
  20. * [-82.545261, 35.594087],
  21. * [-82.574787, 35.594087],
  22. * ],
  23. * ],
  24. * { fill: "#0f0" }
  25. * );
  26. *
  27. * const poly2 = turf.polygon(
  28. * [
  29. * [
  30. * [-82.560024, 35.585153],
  31. * [-82.560024, 35.602602],
  32. * [-82.52964, 35.602602],
  33. * [-82.52964, 35.585153],
  34. * [-82.560024, 35.585153],
  35. * ],
  36. * ],
  37. * );
  38. *
  39. * const union = turf.union(turf.featureCollection([poly1, poly2]));
  40. *
  41. * //addToMap
  42. * const addToMap = { poly1, poly2, union };
  43. *
  44. * poly1.properties.fill = "#0f0";
  45. * poly2.properties.fill = "#00f";
  46. * union.properties.stroke = "red";
  47. * union.properties["stroke-width"] = 4;
  48. * union.properties.fill = "transparent";
  49. */
  50. declare function union<P extends GeoJsonProperties = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
  51. properties?: P;
  52. }): Feature<Polygon | MultiPolygon, P> | null;
  53. export { union as default, union };