@seasketch/geoprocessing
Version:
Geoprocessing and reporting framework for SeaSketch 2.0
294 lines (277 loc) • 5.96 kB
text/typescript
import {
SketchCollection,
Feature,
MultiPolygon,
Polygon,
} from "../../types/index.js";
import { genSampleSketch } from "../../helpers/index.js";
import {
feature,
featureCollection,
multiPolygon,
polygon,
area,
bbox,
} from "@turf/turf";
const tiny: Feature<Polygon> = feature({
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
});
const twoByPoly: Feature<Polygon> = feature(
{
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
},
{ width: 2 },
);
const twoByPolyArea = area(twoByPoly);
const fourByPoly: Feature<Polygon> = feature(
{
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
},
{ width: 4 },
);
const fourByPolyArea = area(fourByPoly);
// fully inside outer
const insideTwoByPoly = polygon(
[
[
[],
[],
[],
[],
[],
],
],
{ width: 1 },
);
const insideTwoByMultiPoly = multiPolygon([
insideTwoByPoly.geometry.coordinates,
]);
const insideTwoByMultipolySketch = genSampleSketch(
insideTwoByMultiPoly.geometry,
"sketchMultiPoly1",
);
const insideTwoByPolySketch = genSampleSketch(
insideTwoByPoly.geometry,
"insideTwoByPolySketch",
);
// half inside outer
const halfInsideTwoByPoly = polygon(
[
[
[],
[],
[],
[],
[],
],
],
{ width: 2 },
);
const fullyInsideTwoPoly = polygon(
[
[
[],
[],
[],
[],
[],
],
],
{ width: 1 },
);
const halfInsideTwoBySketchPoly = genSampleSketch(
halfInsideTwoByPoly.geometry,
"halfInsideTwoBySketchPoly",
);
// fully outside outer top right
const outsideTwoByPolyTopRight = polygon(
[
[
[],
[],
[],
[],
[],
],
],
{ width: 1 },
);
const outsideTwoByPolyTopRightSketch = genSampleSketch(
outsideTwoByPolyTopRight.geometry,
"outsideTwoByPolyTopRightSketch",
);
// fully outside outer bottom right
const outsideTwoByPolyBottomRight = polygon(
[
[
[],
[],
[],
[],
[],
],
],
{ width: 1 },
);
const outsideTwoByPolyBottomRightSketch = genSampleSketch(
outsideTwoByPolyBottomRight.geometry,
"outsideTwoByPolyBottomRightSketch",
);
// fully outside outer bottom right
const outsideTwoByPolyTopLeft = polygon(
[
[
[],
[],
[],
[],
[],
],
],
{ width: 1 },
);
const outsideTwoByPolyTopLeftSketch = genSampleSketch(
outsideTwoByPolyTopLeft.geometry,
"outsideTwoByPolyTopLeftSketch",
);
const collectionId = "CCCC";
const sketchCollection: SketchCollection<Polygon> = {
type: "FeatureCollection",
properties: {
id: collectionId,
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([
insideTwoByPolySketch,
halfInsideTwoBySketchPoly,
outsideTwoByPolyTopRightSketch,
]),
),
features: [
insideTwoByPolySketch,
halfInsideTwoBySketchPoly,
outsideTwoByPolyTopRightSketch,
],
};
const mixedCollectionId = "MMMM";
const mixedPolySketchCollection: SketchCollection<Polygon | MultiPolygon> = {
type: "FeatureCollection",
properties: {
id: mixedCollectionId,
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<Polygon | MultiPolygon>([
insideTwoByPolySketch,
insideTwoByMultiPoly,
]),
),
features: [insideTwoByPolySketch, insideTwoByMultipolySketch],
};
const scArea = area(sketchCollection);
/** 2nd and 3rd sketches are the same */
const overlapCollection: SketchCollection<Polygon> = {
type: "FeatureCollection",
properties: {
id: collectionId,
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([insideTwoByPolySketch, halfInsideTwoBySketchPoly]),
),
features: [
insideTwoByPolySketch,
halfInsideTwoBySketchPoly,
halfInsideTwoBySketchPoly,
],
};
/** One sketch is inside twoByPoly, one is outside twoByPoly */
const insideOutsideCollection: SketchCollection<Polygon> = {
type: "FeatureCollection",
properties: {
id: "inside-out-coll",
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([
insideTwoByPolySketch,
outsideTwoByPolyBottomRightSketch,
]),
),
features: [insideTwoByPolySketch, outsideTwoByPolyBottomRightSketch],
};
export default {
tiny,
twoByPoly,
twoByPolyArea,
fourByPoly,
fourByPolyArea,
insideTwoByPoly,
insideTwoByMultiPoly,
insideTwoByPolySketch,
insideTwoByMultipolySketch,
halfInsideTwoByPoly,
fullyInsideTwoPoly,
halfInsideTwoBySketchPoly,
outsideTwoByPolyTopRight,
outsideTwoByPolyTopRightSketch,
outsideTwoByPolyBottomRight,
outsideTwoByPolyBottomRightSketch,
outsideTwoByPolyTopLeft,
outsideTwoByPolyTopLeftSketch,
collectionId,
mixedCollectionId,
sketchCollection,
mixedPolySketchCollection,
overlapCollection,
insideOutsideCollection,
scArea,
};