index.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. import GeojsonEquality from "geojson-equality";
  2. import cleanCoords from "@turf/clean-coords";
  3. import { getGeom } from "@turf/invariant";
  4. /**
  5. * Determine whether two geometries of the same type have identical X,Y coordinate values.
  6. * See http://edndoc.esri.com/arcsde/9.0/general_topics/understand_spatial_relations.htm
  7. *
  8. * @name booleanEqual
  9. * @param {Geometry|Feature} feature1 GeoJSON input
  10. * @param {Geometry|Feature} feature2 GeoJSON input
  11. * @returns {boolean} true if the objects are equal, false otherwise
  12. * @example
  13. * var pt1 = turf.point([0, 0]);
  14. * var pt2 = turf.point([0, 0]);
  15. * var pt3 = turf.point([1, 1]);
  16. *
  17. * turf.booleanEqual(pt1, pt2);
  18. * //= true
  19. * turf.booleanEqual(pt2, pt3);
  20. * //= false
  21. */
  22. function booleanEqual(feature1, feature2) {
  23. var type1 = getGeom(feature1).type;
  24. var type2 = getGeom(feature2).type;
  25. if (type1 !== type2)
  26. return false;
  27. var equality = new GeojsonEquality({ precision: 6 });
  28. return equality.compare(cleanCoords(feature1), cleanCoords(feature2));
  29. }
  30. export default booleanEqual;