@seasketch/geoprocessing
Version:
Geoprocessing and reporting framework for SeaSketch 2.0
62 lines (58 loc) • 1.47 kB
text/typescript
import { describe, test, expect } from "vitest";
import { cleanCoords } from "./cleanCoords.js";
import { feature, featureCollection } from "@turf/turf";
import { Feature, Polygon } from "../types/index.js";
describe("cleanCoords", () => {
test("cleanCoords Polygon", async () => {
const poly: Feature<Polygon> = feature({
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
});
const result = cleanCoords(poly);
// 182 should be cleaned to -178 and -92 should be cleaned to 88
expect(result.geometry.coordinates).toEqual([
[
[],
[-178, 88],
[-178, -15],
[],
[],
],
]);
});
test("cleanCoords FeatureCollection", async () => {
const poly: Feature<Polygon> = feature({
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
});
const fc = featureCollection([poly]);
const result = cleanCoords(fc);
expect(result.type).toBe("FeatureCollection");
expect(result.features.length).toBe(1);
expect(result.features[0].geometry.coordinates).toEqual([
[
[],
[-178, 88],
[-178, -15],
[],
[],
],
]);
});
});