diff --git a/packages/geoprocessing/data/in/squares.fgb b/packages/geoprocessing/data/in/squares.fgb new file mode 100644 index 0000000000..0c22598a06 Binary files /dev/null and b/packages/geoprocessing/data/in/squares.fgb differ diff --git a/packages/geoprocessing/data/in/squares.json b/packages/geoprocessing/data/in/squares.json index 907bd6fb42..65993bfbad 100644 --- a/packages/geoprocessing/data/in/squares.json +++ b/packages/geoprocessing/data/in/squares.json @@ -1,100 +1,105 @@ { "type": "FeatureCollection", + "name": "squares", + "crs": { + "type": "name", + "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } + }, "features": [ { "type": "Feature", - "properties": {}, + "properties": { "name": "outsideTwoByPolyBottomRight" }, "geometry": { + "type": "Polygon", "coordinates": [ [ - [0, 0], - [2, 0], - [2, 2], - [0, 2], - [0, 0] + [3.0, 0.0], + [4.0, 0.0], + [4.0, 1.0], + [3.0, 1.0], + [3.0, 0.0] ] - ], - "type": "Polygon" + ] } }, { "type": "Feature", - "properties": {}, + "properties": { "name": "outsideTwoByPolyTopRight" }, "geometry": { + "type": "Polygon", "coordinates": [ [ - [0, 0], - [1, 0], - [1, 1], - [0, 1], - [0, 0] + [3.0, 3.0], + [4.0, 3.0], + [4.0, 4.0], + [3.0, 4.0], + [3.0, 3.0] ] - ], - "type": "Polygon" + ] } }, { "type": "Feature", - "properties": {}, + "properties": { "name": "outsideTwoByPolyTopLeft" }, "geometry": { + "type": "Polygon", "coordinates": [ [ - [1, 1], - [3, 1], - [3, 2], - [1, 2], - [1, 1] + [0.0, 3.0], + [1.0, 3.0], + [1.0, 4.0], + [0.0, 4.0], + [0.0, 3.0] ] - ], - "type": "Polygon" + ] } }, { "type": "Feature", - "properties": {}, + "properties": { "name": "halfInsideTwoByPoly" }, "geometry": { + "type": "Polygon", "coordinates": [ [ - [3, 3], - [4, 3], - [4, 4], - [3, 4], - [3, 3] + [1.0, 1.0], + [3.0, 1.0], + [3.0, 2.0], + [1.0, 2.0], + [1.0, 1.0] ] - ], - "type": "Polygon" + ] } }, { "type": "Feature", - "properties": {}, + "properties": { "name": "twoByPoly" }, "geometry": { + "type": "Polygon", "coordinates": [ [ - [0, 3], - [1, 3], - [1, 4], - [0, 4], - [0, 3] + [0.0, 0.0], + [2.0, 0.0], + [2.0, 2.0], + [0.0, 2.0], + [0.0, 0.0] ] - ], - "type": "Polygon" + ] } }, { "type": "Feature", - "properties": {}, + "properties": { "name": "insideTwoByPoly" }, "geometry": { + "type": "Polygon", "coordinates": [ [ - [3, 0], - [4, 0], - [4, 1], - [3, 1], - [3, 0] + [0.0, 0.0], + [1.0, 0.0], + [1.0, 1.0], + [0.0, 1.0], + [0.0, 0.0] ] - ], - "type": "Polygon" + ] } } ] diff --git a/packages/geoprocessing/data/in/squaresReadme.txt b/packages/geoprocessing/data/in/squaresReadme.txt new file mode 100644 index 0000000000..fb376e8621 --- /dev/null +++ b/packages/geoprocessing/data/in/squaresReadme.txt @@ -0,0 +1,54 @@ + + + + +squares.fgb polygons are rectangles in increments of 1 degree + + 4 @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ + @ ---------------- @ @ ---------------- @ + @ ---------------- @ @ ---------------- @ + @ ---------------- @ @ ---------------- @ + @ ---------------- @ @ ---------------- @ + @ ---------------- @ @ ---------------- @ + @ ---------------- @ @ ---------------- @ + @ ---------------- @ @ ---------------- @ + @ ---------------- @ @ ---------------- @ + @ ---------------- @ @ ---------------- @ + 3 @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ + + + + + + + + + 2 wide polygon overlaps top right of 2x2 + 2 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @ ---------------- @ +++++++++++++++++@ ---------------- @ + @ ---------------- @ +++++++++++++++++@ ---------------- @ + @ ---------------- @ +++++++++++++++++@ ---------------- @ + @ ---------------- @ +++++++++++++++++@ ---------------- @ + @ ---------------- @ +++++++++++++++++@ ---------------- @ + @ ---------------- @ +++++++++++++++++@ ---------------- @ + @ ---------------- @ +++++++++++++++++@ ---------------- @ + @ ---------------- @ +++++++++++++++++@ ---------------- @ + @ ---------------- @ +++++++++++++++++@ ---------------- @ + 1 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @+++++++++++++++++ @ ---------------- @ @ ---------------- @ + @+++++++++++++++++ @ ---------------- @ @ ---------------- @ + @+++++++++++++++++ @ ---------------- @ @ ---------------- @ + @+++++++++++++++++ @ ---------------- @ @ ---------------- @ + @+++++++++++++++++ @ ---------------- @ @ ---------------- @ + @+++++++++++++++++ @ ---------------- @ @ ---------------- @ + @+++++++++++++++++ @ ---------------- @ @ ---------------- @ + @+++++++++++++++++ @ ---------------- @ @ ---------------- @ + @+++++++++++++++++ @ ---------------- @ @ ---------------- @ + 0 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ + 1x1 poly overlaps + bottom left of + 2x2 square + + 0 1 2 3 4 + + \ No newline at end of file diff --git a/packages/geoprocessing/src/dataproviders/getFeaturesForSketchBBoxes.test.e2e.ts b/packages/geoprocessing/src/dataproviders/getFeaturesForSketchBBoxes.test.e2e.ts index c056bbb45a..ba7ab7e9b5 100644 --- a/packages/geoprocessing/src/dataproviders/getFeaturesForSketchBBoxes.test.e2e.ts +++ b/packages/geoprocessing/src/dataproviders/getFeaturesForSketchBBoxes.test.e2e.ts @@ -1,39 +1,100 @@ import { expect, test } from "vitest"; -import { loadFgb } from "./flatgeobuf.js"; import canonicalize from "../util/canonicalize.js"; -import { deserialize } from "flatgeobuf/lib/mjs/geojson.js"; - -import { readFileSync } from "node:fs"; -import path from "node:path"; -import { isFeatureCollection } from "../index.js"; +import fs from "fs-extra"; +import { + getFeaturesForBBoxes, + getFeaturesForSketchBBoxes, +} from "./getFeaturesForSketchBBoxes.js"; +import { genSampleSketch } from "../helpers/sketch.js"; +import { bbox, featureCollection, polygon } from "@turf/turf"; +import fix from "../testing/fixtures/squareSketches.js"; +import { SketchCollection } from "../types/sketch.js"; +import { Polygon } from "geojson"; describe("getFeaturesForBBoxes", () => { test("getFeaturesForBBoxes - simple", async () => { - const canonicalStr = canonicalize([ - { - id: 0, // this is not in the data, but fgb client automatically adds it on deserialize as of v3.36.0 - type: "Feature", - properties: { - name: "World boundary", - description: "World", - }, - geometry: { - coordinates: [ - [ - [-180, 90], - [-180, -90], - [180, -90], - [180, 90], - [-180, 90], - ], - ], - type: "Polygon", - }, - }, - ]); + const worldJson = fs.readJsonSync("data/in/world.json"); + // pull features out of FC and add index based ID, just as the flatgeobuf client does on read + const worldFeatures = worldJson.features.map((f, index) => { + f.id = index; + return f; + }); + const canonicalStr = canonicalize(worldFeatures); + const url = "http://127.0.0.1:8080/data/in/world.fgb"; + const features = await getFeaturesForBBoxes([[-1, -1, 1, 1]], url); + expect(features.length).toEqual(1); + expect(canonicalize(features)).toEqual(canonicalStr); + }); +}); + +describe("getFeaturesForSketchBBoxes", () => { + test("getFeaturesForSketchBBoxes - simple", async () => { + const worldJson = fs.readJsonSync("data/in/world.json"); + // pull features out of FC and add index based ID, just as the flatgeobuf client does on read + const worldFeatures = worldJson.features.map((f, index) => { + f.id = index; + return f; + }); + const canonicalStr = canonicalize(worldFeatures); const url = "http://127.0.0.1:8080/data/in/world.fgb"; - const features = await loadFgb(url); + const poly = polygon([ + [ + [0, 0], + [1, 0], + [1, 1], + [0, 1], + [0, 0], + ], + ]); + const sketch = genSampleSketch(poly.geometry, "sketch1"); + const features = await getFeaturesForSketchBBoxes(sketch, url); expect(features.length).toEqual(1); expect(canonicalize(features)).toEqual(canonicalStr); }); + + test("getFeaturesForSketchBBoxes - bottom left squares", async () => { + const url = "http://127.0.0.1:8080/data/in/squares.fgb"; + const poly = polygon([ + [ + [0, 0], + [1, 0], + [1, 1], + [0, 1], + [0, 0], + ], + ]); + const sketch = genSampleSketch(poly.geometry, "sketch1"); + const features = await getFeaturesForSketchBBoxes(sketch, url); + // Should pick up twoByPoly, insideTwoByPoly, and the corner of halfInsideTwoByPoly + expect(features.length).toEqual(3); + }); + + test("getFeaturesForSketchBBoxes - sketch collection", async () => { + const url = "http://127.0.0.1:8080/data/in/squares.fgb"; + const testSC: SketchCollection = { + type: "FeatureCollection", + properties: { + id: "test", + name: "Collection 1", + updatedAt: "2021-11-20T00:00:34.269Z", + createdAt: "2021-11-19T23:34:12.889Z", + sketchClassId: "615b65a2aac8c8285d50d9f3", + isCollection: true, + userAttributes: [], + }, + bbox: bbox( + featureCollection([ + fix.outsideTwoByPolyTopLeftSketch, + fix.outsideTwoByPolyBottomRightSketch, + ]), + ), + features: [ + fix.outsideTwoByPolyTopLeftSketch, + fix.outsideTwoByPolyBottomRightSketch, + ], + }; + const features = await getFeaturesForSketchBBoxes(testSC, url); + // Should pick up outsideTwoByPolyTopLeftSketch, outsideTwoByPolyBottomRightSketch, and the corner of halfInsideTwoByPoly + expect(features.length).toEqual(3); + }); }); diff --git a/packages/geoprocessing/src/testing/fixtures/squareSketches.ts b/packages/geoprocessing/src/testing/fixtures/squareSketches.ts index 066b1ac0fd..5a958e96d7 100644 --- a/packages/geoprocessing/src/testing/fixtures/squareSketches.ts +++ b/packages/geoprocessing/src/testing/fixtures/squareSketches.ts @@ -27,7 +27,7 @@ const tiny: Feature = feature({ ], }); -const outer: Feature = feature({ +const twoByPoly: Feature = feature({ type: "Polygon", coordinates: [ [ @@ -39,9 +39,9 @@ const outer: Feature = feature({ ], ], }); -const outerArea = area(outer); +const twoByPolyArea = area(twoByPoly); -const outerOuter: Feature = feature({ +const fourByPoly: Feature = feature({ type: "Polygon", coordinates: [ [ @@ -53,10 +53,10 @@ const outerOuter: Feature = feature({ ], ], }); -const outerOuterArea = area(outerOuter); +const fourByPolyArea = area(fourByPoly); // fully inside outer -const poly1 = polygon([ +const insideTwoByPoly = polygon([ [ [0, 0], [1, 0], @@ -66,16 +66,21 @@ const poly1 = polygon([ ], ]); -const multiPoly1 = multiPolygon([poly1.geometry.coordinates]); -const sketchMultiPoly1 = genSampleSketch( - multiPoly1.geometry, +const insideTwoByMultiPoly = multiPolygon([ + insideTwoByPoly.geometry.coordinates, +]); +const insideTwoByMultipolySketch = genSampleSketch( + insideTwoByMultiPoly.geometry, "sketchMultiPoly1", ); -const sketch1 = genSampleSketch(poly1.geometry, "sketch1"); +const insideTwoByPolySketch = genSampleSketch( + insideTwoByPoly.geometry, + "sketch1", +); // half inside outer -const poly2 = polygon([ +const halfInsideTwoByPoly = polygon([ [ [1, 1], [3, 1], @@ -84,7 +89,7 @@ const poly2 = polygon([ [1, 1], ], ]); -const poly2Inner = polygon([ +const fullyInsideTwoPoly = polygon([ [ [1, 1], [2, 1], @@ -93,10 +98,13 @@ const poly2Inner = polygon([ [1, 1], ], ]); -const sketch2 = genSampleSketch(poly2.geometry, "sketch2"); +const halfInsideTwoBySketchPoly = genSampleSketch( + halfInsideTwoByPoly.geometry, + "sketch2", +); -// fully outside outer -const poly3 = polygon([ +// fully outside outer top right +const outsideTwoByPolyTopRight = polygon([ [ [3, 3], [4, 3], @@ -105,7 +113,40 @@ const poly3 = polygon([ [3, 3], ], ]); -const sketch3 = genSampleSketch(poly3.geometry, "sketch3"); +const outsideTwoByPolyTopRightSketch = genSampleSketch( + outsideTwoByPolyTopRight.geometry, + "sketch3", +); + +// fully outside outer bottom right +const outsideTwoByPolyBottomRight = polygon([ + [ + [3, 0], + [4, 0], + [4, 1], + [3, 1], + [3, 0], + ], +]); +const outsideTwoByPolyBottomRightSketch = genSampleSketch( + outsideTwoByPolyBottomRight.geometry, + "outsideTwoByPolyBottomRight", +); + +// fully outside outer bottom right +const outsideTwoByPolyTopLeft = polygon([ + [ + [0, 3], + [1, 3], + [1, 4], + [0, 4], + [0, 3], + ], +]); +const outsideTwoByPolyTopLeftSketch = genSampleSketch( + outsideTwoByPolyTopLeft.geometry, + "outsideTwoByPolyTopLeft", +); const collectionId = "CCCC"; const sketchCollection: SketchCollection = { @@ -119,8 +160,18 @@ const sketchCollection: SketchCollection = { isCollection: true, userAttributes: [], }, - bbox: bbox(featureCollection([sketch1, sketch2, sketch3])), - features: [sketch1, sketch2, sketch3], + bbox: bbox( + featureCollection([ + insideTwoByPolySketch, + halfInsideTwoBySketchPoly, + outsideTwoByPolyTopRightSketch, + ]), + ), + features: [ + insideTwoByPolySketch, + halfInsideTwoBySketchPoly, + outsideTwoByPolyTopRightSketch, + ], }; const mixedCollectionId = "MMMM"; @@ -135,8 +186,13 @@ const mixedPolySketchCollection: SketchCollection = { isCollection: true, userAttributes: [], }, - bbox: bbox(featureCollection([sketch1, multiPoly1])), - features: [sketch1, sketchMultiPoly1], + bbox: bbox( + featureCollection([ + insideTwoByPolySketch, + insideTwoByMultiPoly, + ]), + ), + features: [insideTwoByPolySketch, insideTwoByMultipolySketch], }; const scArea = area(sketchCollection); @@ -153,24 +209,35 @@ const overlapCollection: SketchCollection = { isCollection: true, userAttributes: [], }, - bbox: bbox(featureCollection([sketch1, sketch2])), - features: [sketch1, sketch2, sketch2], + bbox: bbox( + featureCollection([insideTwoByPolySketch, halfInsideTwoBySketchPoly]), + ), + features: [ + insideTwoByPolySketch, + halfInsideTwoBySketchPoly, + halfInsideTwoBySketchPoly, + ], }; export default { tiny, - outer, - outerArea, - outerOuterArea, - poly1, - multiPoly1, - sketch1, - sketchMultiPoly1, - poly2, - poly2Inner, - sketch2, - poly3, - sketch3, + twoByPoly, + twoByPolyArea, + fourByPoly, + fourByPolyArea, + insideTwoByPoly, + insideTwoByMultiPoly, + insideTwoByPolySketch, + insideTwoByMultipolySketch, + halfInsideTwoByPoly, + fullyInsideTwoPoly, + halfInsideTwoBySketchPoly, + outsideTwoByPolyTopRight, + outsideTwoByPolyTopRightSketch, + outsideTwoByPolyBottomRight, + outsideTwoByPolyBottomRightSketch, + outsideTwoByPolyTopLeft, + outsideTwoByPolyTopLeftSketch, collectionId, mixedCollectionId, sketchCollection, diff --git a/packages/geoprocessing/src/toolbox/area.test.ts b/packages/geoprocessing/src/toolbox/area.test.ts index 1d4ebeb845..fc625d968a 100644 --- a/packages/geoprocessing/src/toolbox/area.test.ts +++ b/packages/geoprocessing/src/toolbox/area.test.ts @@ -9,13 +9,15 @@ describe("area", () => { }); test("area - sketch polygon", async () => { - const metrics = await area(fix.sketch1); + const metrics = await area(fix.insideTwoByPolySketch); expect(metrics.length).toBe(1); expect(metrics[0].value).toBeCloseTo(12_363_718_145.180_046); }); test("area - sketch polygon set metric id", async () => { - const metrics = await area(fix.sketch1, { metricId: "specialArea" }); + const metrics = await area(fix.insideTwoByPolySketch, { + metricId: "specialArea", + }); expect(metrics.length).toBe(1); expect(metrics[0].metricId).toBe("specialArea"); }); diff --git a/packages/geoprocessing/src/toolbox/genPreprocessor.test.ts b/packages/geoprocessing/src/toolbox/genPreprocessor.test.ts index 9b81901fd1..accbfcc54d 100644 --- a/packages/geoprocessing/src/toolbox/genPreprocessor.test.ts +++ b/packages/geoprocessing/src/toolbox/genPreprocessor.test.ts @@ -126,30 +126,30 @@ describe("genClipToPolygonsPreprocessor", () => { test("genClipToPolygonsPreprocessor should successfully generate and run preprocessor", async () => { const featureOperations: FeatureClipOperation[] = [ { - clipFeatures: [fix.outer], + clipFeatures: [fix.twoByPoly], operation: "intersection", }, ]; const preprocessor = genClipToPolygonFeatures(featureOperations); - const result = await preprocessor(fix.poly2); + const result = await preprocessor(fix.halfInsideTwoByPoly); expect(result).toBeTruthy(); - expect(area(result)).toBe(area(fix.poly2Inner)); + expect(area(result)).toBe(area(fix.fullyInsideTwoPoly)); }, 60_000); test("geoprocessorz - sketch outside of datasource should not clip at all", async () => { const featureOperations: FeatureClipOperation[] = [ { - clipFeatures: [fix.outer], + clipFeatures: [fix.twoByPoly], operation: "difference", }, ]; const preprocessor = genClipToPolygonFeatures(featureOperations, {}); - const result = await preprocessor(fix.poly3); + const result = await preprocessor(fix.outsideTwoByPolyTopRight); expect(result).toBeTruthy(); - expect(area(result)).toBe(area(fix.poly3)); // should be same as input + expect(area(result)).toBe(area(fix.outsideTwoByPolyTopRight)); // should be same as input }, 20_000); }); diff --git a/packages/geoprocessing/src/toolbox/overlapArea.test.ts b/packages/geoprocessing/src/toolbox/overlapArea.test.ts index cbdd63f0fc..1b5f7e42ab 100644 --- a/packages/geoprocessing/src/toolbox/overlapArea.test.ts +++ b/packages/geoprocessing/src/toolbox/overlapArea.test.ts @@ -12,10 +12,10 @@ describe("overlapArea", () => { }); test("outerArea", () => { - expect(fix.outerArea).toBeCloseTo(49_447_340_364.086_09); + expect(fix.twoByPolyArea).toBeCloseTo(49_447_340_364.086_09); }); test("outerOuterArea", () => { - expect(fix.outerOuterArea).toBeCloseTo(197_668_873_521.434_88); + expect(fix.fourByPolyArea).toBeCloseTo(197_668_873_521.434_88); }); test("overlapArea - undefined sketch throws", async () => { @@ -26,51 +26,77 @@ describe("overlapArea", () => { // sketch always assumed to be within outer boundary. outerArea is passed as pre-calculated area avoiding need to compute it on the fly test("overlapArea overall - single polygon fully inside", async () => { - const metrics = await overlapArea("test", fix.sketch1, fix.outerArea); + const metrics = await overlapArea( + "test", + fix.insideTwoByPolySketch, + fix.twoByPolyArea, + ); expect(metrics[0].value).toBeCloseTo(12_363_718_145.180_046); expect(metrics[1].value).toBeCloseTo(0.25); // takes up bottom left quadrant of outer }); test("overlapSubarea - undefined sketch throws", async () => { expect( - async () => await overlapSubarea("test", undefined!, fix.outer), + async () => await overlapSubarea("test", undefined!, fix.twoByPoly), ).rejects.toThrow(ValidationError); }); }); describe("overlapSubarea", () => { test("overlapSubarea - undefined subareaFeature returns zero value metrics", async () => { - const metrics = await overlapSubarea("test", fix.sketch1, undefined!); + const metrics = await overlapSubarea( + "test", + fix.insideTwoByPolySketch, + undefined!, + ); expect(metrics.length).toBe(2); for (const m of metrics) expect(m.value).toEqual(0); }); test("overlapSubarea intersect - single polygon fully inside", async () => { - const metrics = await overlapSubarea("test", fix.sketch1, fix.outer); + const metrics = await overlapSubarea( + "test", + fix.insideTwoByPolySketch, + fix.twoByPoly, + ); expect(metrics[0].value).toBeCloseTo(12_363_718_145.180_046); expect(metrics[1].value).toBeCloseTo(0.25); }); test("overlapSubarea difference - single polygon fully inside", async () => { - const metrics = await overlapSubarea("test", fix.sketch1, fix.outer, { - operation: "difference", - outerArea: fix.outerArea, - }); + const metrics = await overlapSubarea( + "test", + fix.insideTwoByPolySketch, + fix.twoByPoly, + { + operation: "difference", + outerArea: fix.twoByPolyArea, + }, + ); expect(metrics[0].value).toBeCloseTo(0); expect(metrics[1].value).toBeCloseTo(0); }); test("overlapSubarea intersect - single polygon fully outside", async () => { - const metrics = await overlapSubarea("test", fix.sketch3, fix.outer); + const metrics = await overlapSubarea( + "test", + fix.outsideTwoByPolyTopRightSketch, + fix.twoByPoly, + ); expect(metrics[0].value).toBeCloseTo(0); expect(metrics[1].value).toBeCloseTo(0); }); test("overlapSubarea difference - single polygon fully outside outer, inside of outerOuter", async () => { - const metrics = await overlapSubarea("test", fix.sketch3, fix.outer, { - operation: "difference", - outerArea: fix.outerOuterArea, - }); + const metrics = await overlapSubarea( + "test", + fix.outsideTwoByPolyTopRightSketch, + fix.twoByPoly, + { + operation: "difference", + outerArea: fix.fourByPolyArea, + }, + ); expect(metrics[0].value).toBeCloseTo(12_341_127_230.893_69); expect(metrics[1].value).toBeCloseTo(0.083_26); // should be 1 square of 16 in outerOuter }); @@ -80,7 +106,7 @@ describe("overlapSubarea", () => { const metrics = await overlapArea( "test", fix.sketchCollection, - fix.outerOuterArea, + fix.fourByPolyArea, ); const collPercMetric = firstMatchingMetric( metrics, @@ -97,7 +123,7 @@ describe("overlapSubarea", () => { const metrics = await overlapSubarea( "test", fix.sketchCollection, - fix.outer, + fix.twoByPoly, ); expect(area(fix.sketchCollection)).toBe(fix.scArea); @@ -126,10 +152,10 @@ describe("overlapSubarea", () => { const metrics = await overlapSubarea( "test", fix.sketchCollection, - fix.outer, + fix.twoByPoly, { operation: "difference", - outerArea: fix.outerOuterArea, + outerArea: fix.fourByPolyArea, }, ); diff --git a/packages/geoprocessing/src/toolbox/overlapFeatures.test.ts b/packages/geoprocessing/src/toolbox/overlapFeatures.test.ts index 5d094609aa..5f2da0435d 100644 --- a/packages/geoprocessing/src/toolbox/overlapFeatures.test.ts +++ b/packages/geoprocessing/src/toolbox/overlapFeatures.test.ts @@ -12,22 +12,26 @@ describe("overlapFeatures", () => { }); test("outerArea", () => { - expect(fix.outerArea).toBeCloseTo(49_447_340_364.086_09); + expect(fix.twoByPolyArea).toBeCloseTo(49_447_340_364.086_09); }); test("outerOuterArea", () => { - expect(fix.outerOuterArea).toBeCloseTo(197_668_873_521.434_88); + expect(fix.fourByPolyArea).toBeCloseTo(197_668_873_521.434_88); }); test("overlapFeatures - sketch polygon fully inside", async () => { - const metrics = await overlapFeatures("test", [fix.outer], fix.sketch1); - expect(metrics[0].value).toBeCloseTo(area(fix.sketch1)); + const metrics = await overlapFeatures( + "test", + [fix.twoByPoly], + fix.insideTwoByPolySketch, + ); + expect(metrics[0].value).toBeCloseTo(area(fix.insideTwoByPolySketch)); }); test("overlapFeatures - sketch polygon fully inside - truncation", async () => { const metricsNoTruncation = await overlapFeatures( "test", [fix.tiny], - fix.sketch1, + fix.insideTwoByPolySketch, { truncate: false, }, @@ -37,7 +41,7 @@ describe("overlapFeatures", () => { const metricsTruncation = await overlapFeatures( "test", [fix.tiny], - fix.sketch1, + fix.insideTwoByPolySketch, { truncate: true, }, @@ -47,7 +51,7 @@ describe("overlapFeatures", () => { const metricsTruncationDefault = await overlapFeatures( "test", [fix.tiny], - fix.sketch1, + fix.insideTwoByPolySketch, ); expect(metricsTruncationDefault[0].value).toBe(0.012_364); }); @@ -55,26 +59,30 @@ describe("overlapFeatures", () => { test("overlapFeatures - sketch multipolygon fully inside", async () => { const metrics = await overlapFeatures( "test", - [fix.outer], - fix.sketchMultiPoly1, + [fix.twoByPoly], + fix.insideTwoByMultipolySketch, ); - expect(metrics[0].value).toBeCloseTo(area(fix.sketchMultiPoly1)); + expect(metrics[0].value).toBeCloseTo(area(fix.insideTwoByMultipolySketch)); }); test("overlapFeatures - multipolygon both arguments", async () => { const metrics = await overlapFeatures( "test", - [fix.sketchMultiPoly1], - fix.sketchMultiPoly1, + [fix.insideTwoByMultipolySketch], + fix.insideTwoByMultipolySketch, ); - expect(metrics[0].value).toBeCloseTo(area(fix.sketchMultiPoly1)); + expect(metrics[0].value).toBeCloseTo(area(fix.insideTwoByMultipolySketch)); }); test.skip("overlapFeatures - sketch polygon half inside", async () => { - const metrics = await overlapFeatures("test", [fix.outer], fix.sketch2); + const metrics = await overlapFeatures( + "test", + [fix.twoByPoly], + fix.halfInsideTwoBySketchPoly, + ); expect(metrics.length).toEqual(1); // overlap should be ~50% of original sketch area - const areaOf2 = area(fix.sketch2); + const areaOf2 = area(fix.halfInsideTwoBySketchPoly); const percDiff = (metrics[0].value / (areaOf2 * 0.5)) % 1; expect(percDiff).toBeCloseTo(0); }); @@ -104,7 +112,11 @@ describe("overlapFeatures", () => { }); test("overlapFeatures - sketch polygon fully outside", async () => { - const metrics = await overlapFeatures("test", [fix.outer], fix.sketch3); + const metrics = await overlapFeatures( + "test", + [fix.twoByPoly], + fix.outsideTwoByPolyTopRightSketch, + ); expect(metrics.length).toEqual(1); expect(metrics[0].value).toBe(0); }); @@ -112,7 +124,7 @@ describe("overlapFeatures", () => { test("overlapFeatures - mixed poly sketch collection fully inside", async () => { const metrics = await overlapFeatures( "test", - [fix.outer], + [fix.twoByPoly], fix.mixedPolySketchCollection, ); expect(metrics.length).toBe(3); @@ -154,7 +166,7 @@ describe("overlapFeatures", () => { test("overlapFeatures - sketch collection half inside", async () => { const metrics = await overlapFeatures( "test", - [fix.outer], + [fix.twoByPoly], fix.sketchCollection, ); expect(metrics.length).toBe(4);