@seasketch/geoprocessing
Version:
Geoprocessing and reporting framework for SeaSketch 2.0
42 lines • 1.22 kB
JavaScript
import { bbox, bboxPolygon, explode, distance } from "@turf/turf";
/**
* Returns the maximum width of the geojson or bbox
*/
export const maxWidth = (geojson) => {
const box = (() => {
if (Array.isArray(geojson)) {
return geojson;
}
else {
return bbox(geojson);
}
})();
const boxPoly = bboxPolygon(box);
const boxPoints = explode(boxPoly);
return Math.max(distance(boxPoints.features[0], boxPoints.features[1], {
units: "degrees",
}), distance(boxPoints.features[1], boxPoints.features[2], {
units: "degrees",
}));
};
/**
* Returns the minimum width of the bounding box of given feature
*/
export const minWidth = (geojson) => {
const box = (() => {
if (Array.isArray(geojson)) {
return geojson;
}
else {
return bbox(geojson);
}
})();
const boxPoly = bboxPolygon(box);
const boxPoints = explode(boxPoly);
return Math.min(distance(boxPoints.features[0], boxPoints.features[1], {
units: "degrees",
}), distance(boxPoints.features[1], boxPoints.features[2], {
units: "degrees",
}));
};
//# sourceMappingURL=width.js.map