Skip to content

Commit

Permalink
Merge branch 'dev' into overlapTemplates
Browse files Browse the repository at this point in the history
  • Loading branch information
avmey committed Mar 8, 2024
2 parents 7fd61db + d73e2d0 commit 58bc667
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
55 changes: 54 additions & 1 deletion packages/geoprocessing/src/toolbox/overlapGroupMetrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import {
overlapAreaGroupMetrics,
overlapFeaturesGroupMetrics,
overlapRasterGroupMetrics,
} from "./overlapGroupMetrics";
import { SketchCollection, Polygon, Metric, Sketch } from "../types";
import { SketchCollection, Polygon, Metric, Sketch, Feature } from "../types";
import parseGeoraster from "georaster";
import { toFeaturePolygonArray } from "../helpers";

const sketch: SketchCollection<Polygon> = {
type: "FeatureCollection",
Expand Down Expand Up @@ -202,6 +204,57 @@ describe("overlapAreaGroupMetrics", () => {
});
});

test("function is present", () => {
expect(typeof overlapFeaturesGroupMetrics).toBe("function");
});

test("overlapFeaturesGroupMetrics", async () => {
const featMetrics: Metric[] = [
{
metricId: "test",
value: 46020431.777366,
classId: "world",
groupId: null,
geographyId: null,
sketchId: "62055aac9557604f3e5f6d3e",
extra: { sketchName: "VitoriaNorth" },
},
{
metricId: "test",
value: 10335615.29727,
classId: "world",
groupId: null,
geographyId: null,
sketchId: "62055ac19557604f3e5f6d43",
extra: { sketchName: "VitoriaSouth" },
},
{
metricId: "test",
value: 56356047.074636,
classId: "world",
groupId: null,
geographyId: null,
sketchId: "62055ac79557604f3e5f6d44",
extra: { sketchName: "Vitoria", isCollection: true },
},
];
const features = toFeaturePolygonArray(sketch);
const featuresByClass: Record<string, Feature<Polygon>[]> = {
world: features as Feature<Polygon>[],
};

const metrics = await overlapFeaturesGroupMetrics({
metricId: "featuresOverlap",
groupIds: protectionLevels,
sketch,
metricToGroup: metricToLevel,
metrics: featMetrics,
featuresByClass: featuresByClass,
});

expect(metrics.length).toEqual(protectionLevels.length);
});

test("function is present", () => {
expect(typeof overlapRasterGroupMetrics).toBe("function");
});
Expand Down
2 changes: 1 addition & 1 deletion packages/geoprocessing/src/toolbox/overlapGroupMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function overlapRasterGroupMetrics(options: {
metricToGroup: (sketchMetric: Metric) => string;
/** The metrics to group */
metrics: Metric[];
/** Raster to overlap, keyed by class ID, use empty array if overlapArea operation */
/** Raster to overlap, keyed by class ID */
featuresByClass: Record<string, Georaster>;
/** only generate metrics for groups that sketches match to, rather than all */
onlyPresentGroups?: boolean;
Expand Down

0 comments on commit 58bc667

Please sign in to comment.