From 46a61b9361e49999175661476c4afab9ae0e96e4 Mon Sep 17 00:00:00 2001 From: Abby Vath Meyer Date: Tue, 4 Feb 2025 18:17:56 +0000 Subject: [PATCH] Update gp to 7.0.1. Fix genSketchTable bug --- data/bin/genCog4326.ts | 26 +++- package-lock.json | 168 +++++++++++++------------ package.json | 2 +- project/datasources.json | 14 +-- project/geoprocessing.json | 6 +- src/components/ExistingProtections.tsx | 44 ++----- src/components/HabitatRestoration.tsx | 42 ++----- src/components/NearshoreHabitat.tsx | 44 ++----- src/components/OffshoreHabitat.tsx | 45 ++----- src/components/OusGear.tsx | 44 ++----- src/components/OusSector.tsx | 43 ++----- src/components/RenewableEnergy.tsx | 39 ++---- src/components/Shipwrecks.tsx | 36 +++--- src/components/SpeciesProtection.tsx | 42 ++----- src/functions/clipToLand.ts | 64 ---------- src/functions/clipToLandSmoke.test.ts | 10 -- src/functions/clipToOcean.ts | 58 --------- src/functions/clipToOceanEez.ts | 77 +++++------- src/util/genSketchTable.tsx | 37 ++++++ 19 files changed, 281 insertions(+), 560 deletions(-) delete mode 100644 src/functions/clipToLand.ts delete mode 100644 src/functions/clipToLandSmoke.test.ts delete mode 100644 src/functions/clipToOcean.ts create mode 100644 src/util/genSketchTable.tsx diff --git a/data/bin/genCog4326.ts b/data/bin/genCog4326.ts index b59a66a..9fe177d 100644 --- a/data/bin/genCog4326.ts +++ b/data/bin/genCog4326.ts @@ -1,6 +1,5 @@ import { $ } from "zx"; - -import datasources from "../../project/datasources.json"; +import datasources from "../../project/datasources.json" with { type: "json" }; import project from "../../project/projectClient.js"; // NEARSHORE HABITAT @@ -18,12 +17,14 @@ import project from "../../project/projectClient.js"; // await $`rm ${warpDst}`; // console.log(`Finished reimporting ${datasource.datasourceId}`); -project.getMetricGroup("renewableEnergy").classes.forEach(async (curClass) => { +// OFFSHORE HABITAT +const offshore = project.getMetricGroup("offshoreHabitat"); +for (const curClass of offshore.classes) { const datasource = datasources.find( (d) => d.datasourceId === curClass.datasourceId!, ); console.log(`Reimporting ${curClass.datasourceId}`); - if (!datasource) throw new Error(`Datasource ${curClass} not found`); + if (!datasource) throw new Error(`Datasource ${datasource} not found`); const src = datasource?.src; const warpDst = "data/dist/" + datasource.datasourceId + "_4326.tif"; const dst = "data/dist/" + datasource.datasourceId + ".tif"; @@ -31,4 +32,19 @@ project.getMetricGroup("renewableEnergy").classes.forEach(async (curClass) => { await $`gdal_translate -b ${datasource?.band} -r nearest --config GDAL_PAM_ENABLED NO --config GDAL_CACHEMAX 500 -co COMPRESS=LZW -co NUM_THREADS=ALL_CPUS -of COG -stats ${warpDst} ${dst}`; await $`rm ${warpDst}`; console.log(`Finished reimporting ${datasource.datasourceId}`); -}); +} + +// project.getMetricGroup("renewableEnergy").classes.forEach(async (curClass) => { +// const datasource = datasources.find( +// (d) => d.datasourceId === curClass.datasourceId!, +// ); +// console.log(`Reimporting ${curClass.datasourceId}`); +// if (!datasource) throw new Error(`Datasource ${curClass} not found`); +// const src = datasource?.src; +// const warpDst = "data/dist/" + datasource.datasourceId + "_4326.tif"; +// const dst = "data/dist/" + datasource.datasourceId + ".tif"; +// await $`gdalwarp -t_srs "EPSG:4326" -dstnodata ${datasource?.noDataValue} --config GDAL_PAM_ENABLED NO --config GDAL_CACHEMAX 500 -wm 500 -multi -wo NUM_THREADS=ALL_CPUS ${src} ${warpDst}`; +// await $`gdal_translate -b ${datasource?.band} -r nearest --config GDAL_PAM_ENABLED NO --config GDAL_CACHEMAX 500 -co COMPRESS=LZW -co NUM_THREADS=ALL_CPUS -of COG -stats ${warpDst} ${dst}`; +// await $`rm ${warpDst}`; +// console.log(`Finished reimporting ${datasource.datasourceId}`); +// }); diff --git a/package-lock.json b/package-lock.json index f248227..66aedbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@babel/preset-env": "^7.25.4", "@babel/preset-react": "^7.24.7", "@babel/preset-typescript": "^7.24.7", - "@seasketch/geoprocessing": "7.0.0-beta.9", + "@seasketch/geoprocessing": "7.0.2-experimental-socketError.3", "@storybook/addon-essentials": "^8.2.9", "@storybook/addon-interactions": "^8.2.9", "@storybook/addon-links": "^8.2.9", @@ -58,34 +58,35 @@ } }, "node_modules/@aws-cdk/asset-awscli-v1": { - "version": "2.2.207", - "resolved": "https://registry.npmjs.org/@aws-cdk/asset-awscli-v1/-/asset-awscli-v1-2.2.207.tgz", - "integrity": "sha512-5oRh5Ad7hGSqwM3+/X8MmIkUjBMGU9sd1g+pa3L0s8IL15OQcFW0ZT0gsUdEb/N/JV663jUUpSbtD7pLO65O4Q==" + "version": "2.2.222", + "resolved": "https://registry.npmjs.org/@aws-cdk/asset-awscli-v1/-/asset-awscli-v1-2.2.222.tgz", + "integrity": "sha512-9qjd91FwBYmxjfF3ckieTKrmmvIBZdSe1Daf/hRGxAPnhtH9Fm5Y3Oi0dJD2tRw0ufyM6AbvX9zgejcTqXc+LQ==", + "license": "Apache-2.0" }, "node_modules/@aws-cdk/asset-kubectl-v20": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/@aws-cdk/asset-kubectl-v20/-/asset-kubectl-v20-2.1.3.tgz", - "integrity": "sha512-cDG1w3ieM6eOT9mTefRuTypk95+oyD7P5X/wRltwmYxU7nZc3+076YEVS6vrjDKr3ADYbfn0lDKpfB1FBtO9CQ==" + "integrity": "sha512-cDG1w3ieM6eOT9mTefRuTypk95+oyD7P5X/wRltwmYxU7nZc3+076YEVS6vrjDKr3ADYbfn0lDKpfB1FBtO9CQ==", + "license": "Apache-2.0" }, "node_modules/@aws-cdk/asset-node-proxy-agent-v6": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@aws-cdk/asset-node-proxy-agent-v6/-/asset-node-proxy-agent-v6-2.1.0.tgz", - "integrity": "sha512-7bY3J8GCVxLupn/kNmpPc5VJz8grx+4RKfnnJiO1LG+uxkZfANZG3RMHhE+qQxxwkyQ9/MfPtTpf748UhR425A==" + "integrity": "sha512-7bY3J8GCVxLupn/kNmpPc5VJz8grx+4RKfnnJiO1LG+uxkZfANZG3RMHhE+qQxxwkyQ9/MfPtTpf748UhR425A==", + "license": "Apache-2.0" }, "node_modules/@aws-cdk/cloud-assembly-schema": { - "version": "36.3.0", - "resolved": "https://registry.npmjs.org/@aws-cdk/cloud-assembly-schema/-/cloud-assembly-schema-36.3.0.tgz", - "integrity": "sha512-mLSYgcMFTNCXrGAD7xob95p9s47/7WwEWUJiexxM46H2GxiijhlhLQJs31AS5uRRP6Cx1DLEu4qayKAUOOVGrw==", + "version": "39.2.13", + "resolved": "https://registry.npmjs.org/@aws-cdk/cloud-assembly-schema/-/cloud-assembly-schema-39.2.13.tgz", + "integrity": "sha512-wZ+b55jwGhUrhyR1VIyFkA2zv/6vMpnXX5vAs6KWN5LtGk06//b11eefGHULgKuTGdOEKk1PhoDg07oWW22/Gw==", "bundleDependencies": [ "jsonschema", "semver" ], + "license": "Apache-2.0", "dependencies": { - "jsonschema": "^1.4.1", - "semver": "^7.6.3" - }, - "engines": { - "node": ">= 18.18.0" + "jsonschema": "~1.4.1", + "semver": "^7.7.0" } }, "node_modules/@aws-cdk/cloud-assembly-schema/node_modules/jsonschema": { @@ -97,7 +98,7 @@ } }, "node_modules/@aws-cdk/cloud-assembly-schema/node_modules/semver": { - "version": "7.6.3", + "version": "7.7.0", "inBundle": true, "license": "ISC", "bin": { @@ -3474,9 +3475,10 @@ } }, "node_modules/@petamoriken/float16": { - "version": "3.8.7", - "resolved": "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.8.7.tgz", - "integrity": "sha512-/Ri4xDDpe12NT6Ex/DRgHzLlobiQXEW/hmG08w1wj/YU7hLemk97c+zHQFp0iZQ9r7YqgLEXZR2sls4HxBf9NA==", + "version": "3.9.1", + "resolved": "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.9.1.tgz", + "integrity": "sha512-j+ejhYwY6PeB+v1kn7lZFACUIG97u90WxMuGosILFsl9d4Ovi0sjk0GlPfoEcx+FzvXZDAfioD+NGnnPamXgMA==", + "license": "MIT", "optional": true }, "node_modules/@popperjs/core": { @@ -3491,7 +3493,8 @@ "node_modules/@repeaterjs/repeater": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/@repeaterjs/repeater/-/repeater-3.0.6.tgz", - "integrity": "sha512-Javneu5lsuhwNCryN+pXH93VPQ8g0dBX7wItHFgYiwQmzE1sVdg5tWHiOgHywzL2W21XQopa7IwIEnNbmeUJYA==" + "integrity": "sha512-Javneu5lsuhwNCryN+pXH93VPQ8g0dBX7wItHFgYiwQmzE1sVdg5tWHiOgHywzL2W21XQopa7IwIEnNbmeUJYA==", + "license": "MIT" }, "node_modules/@rollup/plugin-inject": { "version": "5.0.5", @@ -3733,9 +3736,10 @@ ] }, "node_modules/@seasketch/geoprocessing": { - "version": "7.0.0-beta.9", - "resolved": "https://registry.npmjs.org/@seasketch/geoprocessing/-/geoprocessing-7.0.0-beta.9.tgz", - "integrity": "sha512-SqG3hQUSCMbSCfCCjuiFOU5RHacJBYA9OLQ99/pNweGuTsz1AJ4XLxsdxh3yZRfboq/zEgYo3xkMzeVZBjhyag==", + "version": "7.0.2-experimental-socketError.3", + "resolved": "https://registry.npmjs.org/@seasketch/geoprocessing/-/geoprocessing-7.0.2-experimental-socketError.3.tgz", + "integrity": "sha512-lQXWYKDrRvE/fePC+5mm/FkSGxuWtWv3DtUScluwJcS/1gLTpzwoU3BM7JVxf2g4riQDO8Ajl3+3atqmWKbGKw==", + "license": "BSD-3-Clause", "dependencies": { "@aws-sdk/client-apigatewaymanagementapi": "^3.637.0", "@aws-sdk/client-cloudformation": "^3.637.0", @@ -3790,7 +3794,7 @@ "@types/uuid": "^10.0.0", "@vitejs/plugin-react": "^4.3.1", "abortcontroller-polyfill": "^1.7.5", - "aws-cdk-lib": "2.155.0", + "aws-cdk-lib": "^2.173.2", "aws-regions": "2.3.1", "bbox-fns": "^0.20.2", "bytes": "^3.1.2", @@ -3811,7 +3815,7 @@ "fast-deep-equal": "^3.1.3", "finalhandler": "^1.2.0", "flatbush": "^3.3.0", - "flatgeobuf": "3.33.0", + "flatgeobuf": "3.36.0", "fs-extra": "^11.2.0", "fuzzy-tools": "^1.2.0", "geoblaze": "2.8.0", @@ -3871,7 +3875,6 @@ "vite-plugin-node-polyfills": "^0.22.0", "vitest": "^2.0.5", "vitest-fetch-mock": "^0.3.0", - "web-streams-polyfill": "4.0.0", "ws": "^7.3.0", "zod": "^3.23.8", "zod-error": "^1.5.0", @@ -8504,9 +8507,9 @@ } }, "node_modules/aws-cdk-lib": { - "version": "2.155.0", - "resolved": "https://registry.npmjs.org/aws-cdk-lib/-/aws-cdk-lib-2.155.0.tgz", - "integrity": "sha512-QGzDhLldBXsyOUmhgtZ98PiOUS2g1Mb5MO08FiOvQn3+KSyJjQdq0GoyxtDpCNGLaWmIfcyrtB9aDhod38fl9g==", + "version": "2.177.0", + "resolved": "https://registry.npmjs.org/aws-cdk-lib/-/aws-cdk-lib-2.177.0.tgz", + "integrity": "sha512-nTnHAwjZaPJ5gfJjtzE/MyK6q0a66nWthoJl7l8srucRb+I30dczhbbXor6QCdVpJaTRAEliMOMq23aglsAQbg==", "bundleDependencies": [ "@balena/dockerignore", "case", @@ -8520,20 +8523,21 @@ "yaml", "mime-types" ], + "license": "Apache-2.0", "dependencies": { - "@aws-cdk/asset-awscli-v1": "^2.2.202", - "@aws-cdk/asset-kubectl-v20": "^2.1.2", - "@aws-cdk/asset-node-proxy-agent-v6": "^2.0.3", - "@aws-cdk/cloud-assembly-schema": "^36.0.5", + "@aws-cdk/asset-awscli-v1": "^2.2.208", + "@aws-cdk/asset-kubectl-v20": "^2.1.3", + "@aws-cdk/asset-node-proxy-agent-v6": "^2.1.0", + "@aws-cdk/cloud-assembly-schema": "^39.2.0", "@balena/dockerignore": "^1.0.2", "case": "1.6.3", "fs-extra": "^11.2.0", - "ignore": "^5.3.1", + "ignore": "^5.3.2", "jsonschema": "^1.4.1", "mime-types": "^2.1.35", "minimatch": "^3.1.2", "punycode": "^2.3.1", - "semver": "^7.6.2", + "semver": "^7.6.3", "table": "^6.8.2", "yaml": "1.10.2" }, @@ -8550,14 +8554,14 @@ "license": "Apache-2.0" }, "node_modules/aws-cdk-lib/node_modules/ajv": { - "version": "8.16.0", + "version": "8.17.1", "inBundle": true, "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.4.1" + "require-from-string": "^2.0.2" }, "funding": { "type": "github", @@ -8647,6 +8651,11 @@ "inBundle": true, "license": "MIT" }, + "node_modules/aws-cdk-lib/node_modules/fast-uri": { + "version": "3.0.3", + "inBundle": true, + "license": "BSD-3-Clause" + }, "node_modules/aws-cdk-lib/node_modules/fs-extra": { "version": "11.2.0", "inBundle": true, @@ -8666,7 +8675,7 @@ "license": "ISC" }, "node_modules/aws-cdk-lib/node_modules/ignore": { - "version": "5.3.1", + "version": "5.3.2", "inBundle": true, "license": "MIT", "engines": { @@ -8757,7 +8766,7 @@ } }, "node_modules/aws-cdk-lib/node_modules/semver": { - "version": "7.6.2", + "version": "7.6.3", "inBundle": true, "license": "ISC", "bin": { @@ -8830,14 +8839,6 @@ "node": ">= 10.0.0" } }, - "node_modules/aws-cdk-lib/node_modules/uri-js": { - "version": "4.4.1", - "inBundle": true, - "license": "BSD-2-Clause", - "dependencies": { - "punycode": "^2.1.0" - } - }, "node_modules/aws-cdk-lib/node_modules/yaml": { "version": "1.10.2", "inBundle": true, @@ -9881,6 +9882,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/color-parse/-/color-parse-2.0.2.tgz", "integrity": "sha512-eCtOz5w5ttWIUcaKLiktF+DxZO1R9KLNY/xhbV6CkhM7sR3GhVghmt6X6yOnzeaM24po+Z9/S1apbXMwA3Iepw==", + "license": "MIT", "optional": true, "dependencies": { "color-name": "^2.0.0" @@ -9890,6 +9892,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/color-name/-/color-name-2.0.0.tgz", "integrity": "sha512-SbtvAMWvASO5TE2QP07jHBMXKafgdZz8Vrsrn96fiL+O92/FN/PLARzUW5sKt013fjAprK2d2iCn2hk2Xb5oow==", + "license": "MIT", "optional": true, "engines": { "node": ">=12.20" @@ -9899,6 +9902,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/color-rgba/-/color-rgba-3.0.0.tgz", "integrity": "sha512-PPwZYkEY3M2THEHHV6Y95sGUie77S7X8v+h1r6LSAPF3/LL2xJ8duUXSrkic31Nzc4odPwHgUbiX/XuTYzQHQg==", + "license": "MIT", "optional": true, "dependencies": { "color-parse": "^2.0.0", @@ -9906,9 +9910,10 @@ } }, "node_modules/color-space": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-space/-/color-space-2.0.1.tgz", - "integrity": "sha512-nKqUYlo0vZATVOFHY810BSYjmCARrG7e5R3UE3CQlyjJTvv5kSSmPG1kzm/oDyyqjehM+lW1RnEt9It9GNa5JA==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/color-space/-/color-space-2.3.1.tgz", + "integrity": "sha512-5DJdKYwoDji3ik/i0xSn+SiwXsfwr+1FEcCMUz2GS5speGCfGSbBMOLd84SDUBOuX8y4CvdFJmOBBJuC4wp7sQ==", + "license": "MIT", "optional": true }, "node_modules/colors": { @@ -10012,7 +10017,8 @@ "node_modules/constructs": { "version": "10.4.2", "resolved": "https://registry.npmjs.org/constructs/-/constructs-10.4.2.tgz", - "integrity": "sha512-wsNxBlAott2qg8Zv87q3eYZYgheb9lchtBfjHzzLHtXbttwSrHPs1NNQbBrmbb1YZvYg2+Vh0Dor76w4mFxJkA==" + "integrity": "sha512-wsNxBlAott2qg8Zv87q3eYZYgheb9lchtBfjHzzLHtXbttwSrHPs1NNQbBrmbb1YZvYg2+Vh0Dor76w4mFxJkA==", + "license": "Apache-2.0" }, "node_modules/content-disposition": { "version": "0.5.4", @@ -11500,7 +11506,8 @@ "node_modules/flatbuffers": { "version": "24.3.25", "resolved": "https://registry.npmjs.org/flatbuffers/-/flatbuffers-24.3.25.tgz", - "integrity": "sha512-3HDgPbgiwWMI9zVB7VYBHaMrbOO7Gm0v+yD2FV/sCKj+9NDeVL7BOBYUuhWAQGKWOzBo8S9WdMvV0eixO233XQ==" + "integrity": "sha512-3HDgPbgiwWMI9zVB7VYBHaMrbOO7Gm0v+yD2FV/sCKj+9NDeVL7BOBYUuhWAQGKWOzBo8S9WdMvV0eixO233XQ==", + "license": "Apache-2.0" }, "node_modules/flatbush": { "version": "3.3.1", @@ -11511,9 +11518,10 @@ } }, "node_modules/flatgeobuf": { - "version": "3.33.0", - "resolved": "https://registry.npmjs.org/flatgeobuf/-/flatgeobuf-3.33.0.tgz", - "integrity": "sha512-d/Bca6T/jRI1qr3JXD4o16QeAVAQ3JTnbbeQqKbywU+hSjEghXjtqrhUgy4XrvFNVsOJE36zSquebiQ30PRB7g==", + "version": "3.36.0", + "resolved": "https://registry.npmjs.org/flatgeobuf/-/flatgeobuf-3.36.0.tgz", + "integrity": "sha512-vSKhQpClrZdguVLmD6QhVw4aKnqvcpEpeR5yBMTJmnRpBPBD1GLEE1MtGpBlBwdBfh3AzSnlcB3TS2MHelRwlQ==", + "license": "BSD-3-Clause", "dependencies": { "@repeaterjs/repeater": "3.0.6", "flatbuffers": "24.3.25", @@ -13703,6 +13711,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/lerc/-/lerc-3.0.0.tgz", "integrity": "sha512-Rm4J/WaHhRa93nCN2mwWDZFoRVF18G1f47C+kvQWyHGEZxFpTUi73p7lMVSAndyxGt6lJ2/CFbOcf9ra5p8aww==", + "license": "Apache-2.0", "optional": true }, "node_modules/loader-runner": { @@ -15027,16 +15036,17 @@ "integrity": "sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==" }, "node_modules/ol": { - "version": "10.2.1", - "resolved": "https://registry.npmjs.org/ol/-/ol-10.2.1.tgz", - "integrity": "sha512-2bB/y2vEnmzjqynP0NA7Cp8k86No3Psn63Dueicep3E3i09axWRVIG5IS/bylEAGfWQx0QXD/uljkyFoY60Wig==", + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/ol/-/ol-10.4.0.tgz", + "integrity": "sha512-gv3voS4wgej1WVvdCz2ZIBq3lPWy8agaf0094E79piz8IGQzHiOWPs2in1pdoPmuTNvcqGqyUFG3IbxNE6n08g==", + "license": "BSD-2-Clause", "optional": true, "dependencies": { - "@types/rbush": "3.0.3", + "@types/rbush": "4.0.0", "color-rgba": "^3.0.0", "color-space": "^2.0.1", "earcut": "^3.0.0", - "geotiff": "^2.0.7", + "geotiff": "^2.1.3", "pbf": "4.0.1", "rbush": "^4.0.0" }, @@ -15046,21 +15056,24 @@ } }, "node_modules/ol/node_modules/@types/rbush": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@types/rbush/-/rbush-3.0.3.tgz", - "integrity": "sha512-lX55lR0iYCgapxD3IrgujpQA1zDxwZI5qMRelKvmKAsSMplFVr7wmMpG7/6+Op2tjrgEex8o3vjg8CRDrRNYxg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/rbush/-/rbush-4.0.0.tgz", + "integrity": "sha512-+N+2H39P8X+Hy1I5mC6awlTX54k3FhiUmvt7HWzGJZvF+syUAAxP/stwppS8JE84YHqFgRMv6fCy31202CMFxQ==", + "license": "MIT", "optional": true }, "node_modules/ol/node_modules/earcut": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/earcut/-/earcut-3.0.0.tgz", - "integrity": "sha512-41Fs7Q/PLq1SDbqjsgcY7GA42T0jvaCNGXgGtsNdvg+Yv8eIu06bxv4/PoREkZ9nMDNwnUSG9OFB9+yv8eKhDg==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/earcut/-/earcut-3.0.1.tgz", + "integrity": "sha512-0l1/0gOjESMeQyYaK5IDiPNvFeu93Z/cO0TjZh9eZ1vyCtZnA7KMZ8rQggpsJHIbGSdrqYq9OhuveadOVHCshw==", + "license": "ISC", "optional": true }, "node_modules/ol/node_modules/geotiff": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/geotiff/-/geotiff-2.1.3.tgz", "integrity": "sha512-PT6uoF5a1+kbC3tHmZSUsLHBp2QJlHasxxxxPW47QIY1VBKpFB+FcDvX+MxER6UzgLQZ0xDzJ9s48B9JbOCTqA==", + "license": "MIT", "optional": true, "dependencies": { "@petamoriken/float16": "^3.4.7", @@ -15080,12 +15093,14 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/pako/-/pako-2.1.0.tgz", "integrity": "sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==", + "license": "(MIT AND Zlib)", "optional": true }, "node_modules/ol/node_modules/pbf": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/pbf/-/pbf-4.0.1.tgz", "integrity": "sha512-SuLdBvS42z33m8ejRbInMapQe8n0D3vN/Xd5fmWM3tufNgRQFBpaW2YVJxQZV4iPNqb0vEFvssMEo5w9c6BTIA==", + "license": "BSD-3-Clause", "optional": true, "dependencies": { "resolve-protobuf-schema": "^2.1.0" @@ -15098,12 +15113,14 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/quickselect/-/quickselect-3.0.0.tgz", "integrity": "sha512-XdjUArbK4Bm5fLLvlm5KpTFOiOThgfWWI4axAZDWg4E/0mKdZyI9tNEfds27qCi1ze/vwTR16kvmmGhRra3c2g==", + "license": "ISC", "optional": true }, "node_modules/ol/node_modules/rbush": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/rbush/-/rbush-4.0.1.tgz", "integrity": "sha512-IP0UpfeWQujYC8Jg162rMNc01Rf0gWMMAb2Uxus/Q0qOFw4lCcq6ZnQEZwUoJqWyUGJ9th7JjwI4yIWo+uvoAQ==", + "license": "MIT", "optional": true, "dependencies": { "quickselect": "^3.0.0" @@ -15113,6 +15130,7 @@ "version": "1.10.1", "resolved": "https://registry.npmjs.org/xml-utils/-/xml-utils-1.10.1.tgz", "integrity": "sha512-Dn6vJ1Z9v1tepSjvnCpwk5QqwIPcEFKdgnjqfYOABv1ngSofuAhtlugcUC3ehS1OHdgDWSG6C5mvj+Qm15udTQ==", + "license": "CC0-1.0", "optional": true }, "node_modules/on-finished": { @@ -15557,6 +15575,7 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/parse-headers/-/parse-headers-2.0.5.tgz", "integrity": "sha512-ft3iAoLOB/MlwbNXgzy43SWGP6sQki2jQvAyBg/zDFAgr9bfNWZIUj42Kw2eJIl8kEi4PbgE6U1Zau/HwI75HA==", + "license": "MIT", "optional": true }, "node_modules/parse-json": { @@ -16424,6 +16443,7 @@ "version": "6.1.2", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-6.1.2.tgz", "integrity": "sha512-AAFUA5O1d83pIHEhJwWCq/RQcRukCkn/NSm2QsTEMle5f2hP0ChI2+3Xb051PZCkLryI/Ir1MVKviT2FIloaTQ==", + "license": "MIT", "optional": true, "engines": { "node": ">=12" @@ -20351,18 +20371,11 @@ "defaults": "^1.0.3" } }, - "node_modules/web-streams-polyfill": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0.tgz", - "integrity": "sha512-0zJXHRAYEjM2tUfZ2DiSOHAa2aw1tisnnhU3ufD57R8iefL+DcdJyRBRyJpG+NUimDgbTI/lH+gAE1PAvV3Cgw==", - "engines": { - "node": ">= 8" - } - }, "node_modules/web-worker": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.3.0.tgz", - "integrity": "sha512-BSR9wyRsy/KOValMgd5kMyr3JzpdeoR9KVId8u5GVlTTAtNChlsE4yTxeY7zMdNSyOmoKBv8NH2qeRY9Tg+IaA==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.5.0.tgz", + "integrity": "sha512-RiMReJrTAiA+mBjGONMnjVDP2u3p9R1vkcGz6gDIrOMT3oGuYwX2WRMYI9ipkphSuE5XKEhydbhNEJh4NY9mlw==", + "license": "Apache-2.0", "optional": true }, "node_modules/webidl-conversions": { @@ -21030,6 +21043,7 @@ "version": "0.1.0", "resolved": "https://registry.npmjs.org/zstddec/-/zstddec-0.1.0.tgz", "integrity": "sha512-w2NTI8+3l3eeltKAdK8QpiLo/flRAr2p8AGeakfMZOXBxOg9HIu4LVDxBi81sYgVhFhdJjv1OrB5ssI8uFPoLg==", + "license": "MIT AND BSD-3-Clause", "optional": true }, "node_modules/zx": { diff --git a/package.json b/package.json index e708fd2..23fb858 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@babel/preset-env": "^7.25.4", "@babel/preset-react": "^7.24.7", "@babel/preset-typescript": "^7.24.7", - "@seasketch/geoprocessing": "7.0.0-beta.9", + "@seasketch/geoprocessing": "7.0.2-experimental-socketError.3", "@storybook/addon-essentials": "^8.2.9", "@storybook/addon-interactions": "^8.2.9", "@storybook/addon-links": "^8.2.9", diff --git a/project/datasources.json b/project/datasources.json index 862468e..0bddb58 100644 --- a/project/datasources.json +++ b/project/datasources.json @@ -188,7 +188,7 @@ "layerName": "nearshore_dissolved", "classKeys": [], "created": "2024-10-18T17:42:19.342Z", - "lastUpdated": "2024-10-18T17:42:19.342Z", + "lastUpdated": "2025-02-03T23:39:22.325Z", "src": "data/src/Analytics/nearshore_dissolved.shp", "propertiesToKeep": [], "explodeMulti": true @@ -1062,17 +1062,17 @@ "src": "data/src/Analytics/SiteSuitability/wind_float1.tif" }, { - "src": "data/src/Analytics/SiteSuitability/wave_energy1.tif", - "band": 1, - "geo_type": "raster", "datasourceId": "wave", + "geo_type": "raster", "formats": [ "tif" ], + "precalc": true, + "measurementType": "quantitative", + "band": 1, + "noDataValue": -3.4e+38, "created": "2024-10-24T20:02:03.953Z", "lastUpdated": "2024-10-24T20:02:03.953Z", - "noDataValue": -3.4e+38, - "measurementType": "quantitative", - "precalc": true + "src": "data/src/Analytics/SiteSuitability/wave_energy1.tif" } ] diff --git a/project/geoprocessing.json b/project/geoprocessing.json index ce46aaf..586b3d0 100644 --- a/project/geoprocessing.json +++ b/project/geoprocessing.json @@ -14,11 +14,7 @@ "source": "src/clients/SizeReport.tsx" } ], - "preprocessingFunctions": [ - "src/functions/clipToOceanEez.ts", - "src/functions/clipToLand.ts", - "src/functions/clipToOcean.ts" - ], + "preprocessingFunctions": ["src/functions/clipToOceanEez.ts"], "geoprocessingFunctions": [ "src/functions/boundaryAreaOverlap.ts", "src/functions/existingProtections.ts", diff --git a/src/components/ExistingProtections.tsx b/src/components/ExistingProtections.tsx index 5449968..5c9c7e7 100644 --- a/src/components/ExistingProtections.tsx +++ b/src/components/ExistingProtections.tsx @@ -6,24 +6,18 @@ import { LayerToggle, ReportError, ResultsCard, - SketchClassTable, useSketchProperties, } from "@seasketch/geoprocessing/client-ui"; import { GeogProp, - Metric, - MetricGroup, ReportResult, - flattenBySketchAllClass, metricsWithSketchId, roundDecimal, - roundLower, squareMeterToMile, - toNullSketchArray, toPercentMetric, } from "@seasketch/geoprocessing/client-core"; import project from "../../project/projectClient.js"; -import { AreaSketchTableStyled } from "./SizeCard.js"; +import { genSketchTable } from "../util/genSketchTable.js"; /** * ExistingProtections component @@ -35,7 +29,7 @@ export const ExistingProtections: React.FunctionComponent = ( props, ) => { const { t } = useTranslation(); - const [{ isCollection }] = useSketchProperties(); + const [{ isCollection, id, childProperties }] = useSketchProperties(); const curGeography = project.getGeographyById(props.geographyId, { fallbackGroup: "default-boundary", }); @@ -67,7 +61,7 @@ export const ExistingProtections: React.FunctionComponent = ( const valueMetrics = metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), - [data.sketch.properties.id], + [id], ); const percentMetrics = toPercentMetric(valueMetrics, precalcMetrics, { metricIdOverride: percMetricIdName, @@ -136,7 +130,12 @@ export const ExistingProtections: React.FunctionComponent = ( {isCollection && ( - {genSketchTable(data, metricGroup, precalcMetrics)} + {genSketchTable( + data, + metricGroup, + precalcMetrics, + childProperties || [], + )} )} @@ -145,28 +144,3 @@ export const ExistingProtections: React.FunctionComponent = ( ); }; - -const genSketchTable = ( - data: ReportResult, - metricGroup: MetricGroup, - precalcMetrics: Metric[], -) => { - // Build agg metric objects for each child sketch in collection with percValue for each class - const childSketches = toNullSketchArray(data.sketch); - const childSketchIds = childSketches.map((sk) => sk.properties.id); - const childSketchMetrics = toPercentMetric( - metricsWithSketchId( - data.metrics.filter((m) => m.metricId === metricGroup.metricId), - childSketchIds, - ), - precalcMetrics, - ); - const sketchRows = flattenBySketchAllClass( - childSketchMetrics, - metricGroup.classes, - childSketches, - ); - return ( - - ); -}; diff --git a/src/components/HabitatRestoration.tsx b/src/components/HabitatRestoration.tsx index 589ec1c..010a910 100644 --- a/src/components/HabitatRestoration.tsx +++ b/src/components/HabitatRestoration.tsx @@ -5,21 +5,17 @@ import { Collapse, ReportError, ResultsCard, - SketchClassTable, useSketchProperties, } from "@seasketch/geoprocessing/client-ui"; import { GeogProp, - Metric, - MetricGroup, ReportResult, - flattenBySketchAllClass, metricsWithSketchId, squareMeterToMile, - toNullSketchArray, toPercentMetric, } from "@seasketch/geoprocessing/client-core"; import project from "../../project/projectClient.js"; +import { genSketchTable } from "../util/genSketchTable.js"; const Number = new Intl.NumberFormat("en", { style: "decimal" }); @@ -33,7 +29,7 @@ export const HabitatRestoration: React.FunctionComponent = ( props, ) => { const { t } = useTranslation(); - const [{ isCollection }] = useSketchProperties(); + const [{ isCollection, id, childProperties }] = useSketchProperties(); const curGeography = project.getGeographyById(props.geographyId, { fallbackGroup: "default-boundary", }); @@ -64,7 +60,7 @@ export const HabitatRestoration: React.FunctionComponent = ( const valueMetrics = metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), - [data.sketch.properties.id], + [id], ); const percentMetrics = toPercentMetric(valueMetrics, precalcMetrics, { metricIdOverride: percMetricIdName, @@ -140,7 +136,12 @@ export const HabitatRestoration: React.FunctionComponent = ( {isCollection && ( - {genSketchTable(data, metricGroup, precalcMetrics)} + {genSketchTable( + data, + metricGroup, + precalcMetrics, + childProperties || [], + )} )} @@ -175,28 +176,3 @@ export const HabitatRestoration: React.FunctionComponent = ( ); }; - -const genSketchTable = ( - data: ReportResult, - metricGroup: MetricGroup, - precalcMetrics: Metric[], -) => { - // Build agg metric objects for each child sketch in collection with percValue for each class - const childSketches = toNullSketchArray(data.sketch); - const childSketchIds = childSketches.map((sk) => sk.properties.id); - const childSketchMetrics = toPercentMetric( - metricsWithSketchId( - data.metrics.filter((m) => m.metricId === metricGroup.metricId), - childSketchIds, - ), - precalcMetrics, - ); - const sketchRows = flattenBySketchAllClass( - childSketchMetrics, - metricGroup.classes, - childSketches, - ); - return ( - - ); -}; diff --git a/src/components/NearshoreHabitat.tsx b/src/components/NearshoreHabitat.tsx index d44df50..631ebe0 100644 --- a/src/components/NearshoreHabitat.tsx +++ b/src/components/NearshoreHabitat.tsx @@ -6,23 +6,17 @@ import { LayerToggle, ReportError, ResultsCard, - SketchClassTable, useSketchProperties, VerticalSpacer, } from "@seasketch/geoprocessing/client-ui"; import { GeogProp, - Metric, - MetricGroup, ReportResult, - flattenBySketchAllClass, metricsWithSketchId, - roundDecimal, - squareMeterToMile, - toNullSketchArray, toPercentMetric, } from "@seasketch/geoprocessing/client-core"; import project from "../../project/projectClient.js"; +import { genSketchTable } from "../util/genSketchTable.js"; /** * NearshoreHabitat component @@ -32,7 +26,7 @@ import project from "../../project/projectClient.js"; */ export const NearshoreHabitat: React.FunctionComponent = (props) => { const { t } = useTranslation(); - const [{ isCollection }] = useSketchProperties(); + const [{ isCollection, id, childProperties }] = useSketchProperties(); const curGeography = project.getGeographyById(props.geographyId, { fallbackGroup: "default-boundary", }); @@ -62,7 +56,7 @@ export const NearshoreHabitat: React.FunctionComponent = (props) => { const valueMetrics = metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), - [data.sketch.properties.id], + [id], ); const percentMetrics = toPercentMetric(valueMetrics, precalcMetrics, { metricIdOverride: percMetricIdName, @@ -119,7 +113,12 @@ export const NearshoreHabitat: React.FunctionComponent = (props) => { {isCollection && ( - {genSketchTable(data, metricGroup, precalcMetrics)} + {genSketchTable( + data, + metricGroup, + precalcMetrics, + childProperties || [], + )} )} @@ -140,28 +139,3 @@ export const NearshoreHabitat: React.FunctionComponent = (props) => { ); }; - -const genSketchTable = ( - data: ReportResult, - metricGroup: MetricGroup, - precalcMetrics: Metric[], -) => { - // Build agg metric objects for each child sketch in collection with percValue for each class - const childSketches = toNullSketchArray(data.sketch); - const childSketchIds = childSketches.map((sk) => sk.properties.id); - const childSketchMetrics = toPercentMetric( - metricsWithSketchId( - data.metrics.filter((m) => m.metricId === metricGroup.metricId), - childSketchIds, - ), - precalcMetrics, - ); - const sketchRows = flattenBySketchAllClass( - childSketchMetrics, - metricGroup.classes, - childSketches, - ); - return ( - - ); -}; diff --git a/src/components/OffshoreHabitat.tsx b/src/components/OffshoreHabitat.tsx index c041a02..7b17249 100644 --- a/src/components/OffshoreHabitat.tsx +++ b/src/components/OffshoreHabitat.tsx @@ -5,24 +5,17 @@ import { Collapse, ReportError, ResultsCard, - SketchClassTable, useSketchProperties, } from "@seasketch/geoprocessing/client-ui"; import { GeogProp, - Metric, - MetricGroup, ReportResult, - flattenBySketchAllClass, metricsWithSketchId, - squareMeterToMile, - toNullSketchArray, toPercentMetric, valueFormatter, } from "@seasketch/geoprocessing/client-core"; import project from "../../project/projectClient.js"; - -const Number = new Intl.NumberFormat("en", { style: "decimal" }); +import { genSketchTable } from "../util/genSketchTable.js"; /** * OffshoreHabitat component @@ -32,7 +25,7 @@ const Number = new Intl.NumberFormat("en", { style: "decimal" }); */ export const OffshoreHabitat: React.FunctionComponent = (props) => { const { t } = useTranslation(); - const [{ isCollection }] = useSketchProperties(); + const [{ isCollection, id, childProperties }] = useSketchProperties(); const curGeography = project.getGeographyById(props.geographyId, { fallbackGroup: "default-boundary", }); @@ -63,7 +56,7 @@ export const OffshoreHabitat: React.FunctionComponent = (props) => { const valueMetrics = metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), - [data.sketch.properties.id], + [id], ); const percentMetrics = toPercentMetric(valueMetrics, precalcMetrics, { metricIdOverride: percMetricIdName, @@ -128,7 +121,12 @@ export const OffshoreHabitat: React.FunctionComponent = (props) => { {isCollection && ( - {genSketchTable(data, metricGroup, precalcMetrics)} + {genSketchTable( + data, + metricGroup, + precalcMetrics, + childProperties || [], + )} )} @@ -149,28 +147,3 @@ export const OffshoreHabitat: React.FunctionComponent = (props) => { ); }; - -const genSketchTable = ( - data: ReportResult, - metricGroup: MetricGroup, - precalcMetrics: Metric[], -) => { - // Build agg metric objects for each child sketch in collection with percValue for each class - const childSketches = toNullSketchArray(data.sketch); - const childSketchIds = childSketches.map((sk) => sk.properties.id); - const childSketchMetrics = toPercentMetric( - metricsWithSketchId( - data.metrics.filter((m) => m.metricId === metricGroup.metricId), - childSketchIds, - ), - precalcMetrics, - ); - const sketchRows = flattenBySketchAllClass( - childSketchMetrics, - metricGroup.classes, - childSketches, - ); - return ( - - ); -}; diff --git a/src/components/OusGear.tsx b/src/components/OusGear.tsx index efd4501..bf999cf 100644 --- a/src/components/OusGear.tsx +++ b/src/components/OusGear.tsx @@ -5,20 +5,16 @@ import { Collapse, ReportError, ResultsCard, - SketchClassTable, useSketchProperties, } from "@seasketch/geoprocessing/client-ui"; import { GeogProp, - Metric, - MetricGroup, ReportResult, - flattenBySketchAllClass, metricsWithSketchId, - toNullSketchArray, toPercentMetric, } from "@seasketch/geoprocessing/client-core"; import project from "../../project/projectClient.js"; +import { genSketchTable } from "../util/genSketchTable.js"; /** * OusGear component @@ -28,7 +24,7 @@ import project from "../../project/projectClient.js"; */ export const OusGear: React.FunctionComponent = (props) => { const { t } = useTranslation(); - const [{ isCollection }] = useSketchProperties(); + const [{ isCollection, id, childProperties }] = useSketchProperties(); const curGeography = project.getGeographyById(props.geographyId, { fallbackGroup: "default-boundary", }); @@ -44,9 +40,7 @@ export const OusGear: React.FunctionComponent = (props) => { // Labels const titleLabel = t("Ocean Use - By Gear Type"); const mapLabel = t("Map"); - const withinLabel = t("Within Plan"); const percWithinLabel = t("% Value Within Plan"); - const unitsLabel = t("units"); return ( = (props) => { const valueMetrics = metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), - [data.sketch.properties.id], + [id], ); const percentMetrics = toPercentMetric(valueMetrics, precalcMetrics, { metricIdOverride: percMetricIdName, @@ -117,7 +111,12 @@ export const OusGear: React.FunctionComponent = (props) => { {isCollection && ( - {genSketchTable(data, metricGroup, precalcMetrics)} + {genSketchTable( + data, + metricGroup, + precalcMetrics, + childProperties || [], + )} )} @@ -152,28 +151,3 @@ export const OusGear: React.FunctionComponent = (props) => { ); }; - -const genSketchTable = ( - data: ReportResult, - metricGroup: MetricGroup, - precalcMetrics: Metric[], -) => { - // Build agg metric objects for each child sketch in collection with percValue for each class - const childSketches = toNullSketchArray(data.sketch); - const childSketchIds = childSketches.map((sk) => sk.properties.id); - const childSketchMetrics = toPercentMetric( - metricsWithSketchId( - data.metrics.filter((m) => m.metricId === metricGroup.metricId), - childSketchIds, - ), - precalcMetrics, - ); - const sketchRows = flattenBySketchAllClass( - childSketchMetrics, - metricGroup.classes, - childSketches, - ); - return ( - - ); -}; diff --git a/src/components/OusSector.tsx b/src/components/OusSector.tsx index a71c952..a944d95 100644 --- a/src/components/OusSector.tsx +++ b/src/components/OusSector.tsx @@ -5,20 +5,16 @@ import { Collapse, ReportError, ResultsCard, - SketchClassTable, useSketchProperties, } from "@seasketch/geoprocessing/client-ui"; import { GeogProp, - Metric, - MetricGroup, ReportResult, - flattenBySketchAllClass, metricsWithSketchId, - toNullSketchArray, toPercentMetric, } from "@seasketch/geoprocessing/client-core"; import project from "../../project/projectClient.js"; +import { genSketchTable } from "../util/genSketchTable.js"; /** * OusSector component @@ -28,7 +24,7 @@ import project from "../../project/projectClient.js"; */ export const OusSector: React.FunctionComponent = (props) => { const { t } = useTranslation(); - const [{ isCollection }] = useSketchProperties(); + const [{ isCollection, id, childProperties }] = useSketchProperties(); const curGeography = project.getGeographyById(props.geographyId, { fallbackGroup: "default-boundary", }); @@ -45,7 +41,6 @@ export const OusSector: React.FunctionComponent = (props) => { const titleLabel = t("Ocean Use - By Sector"); const mapLabel = t("Map"); const percWithinLabel = t("% Value Within Plan"); - const unitsLabel = t("units"); return ( = (props) => { const valueMetrics = metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), - [data.sketch.properties.id], + [id], ); const percentMetrics = toPercentMetric(valueMetrics, precalcMetrics, { metricIdOverride: percMetricIdName, @@ -116,7 +111,12 @@ export const OusSector: React.FunctionComponent = (props) => { {isCollection && ( - {genSketchTable(data, metricGroup, precalcMetrics)} + {genSketchTable( + data, + metricGroup, + precalcMetrics, + childProperties || [], + )} )} @@ -151,28 +151,3 @@ export const OusSector: React.FunctionComponent = (props) => { ); }; - -const genSketchTable = ( - data: ReportResult, - metricGroup: MetricGroup, - precalcMetrics: Metric[], -) => { - // Build agg metric objects for each child sketch in collection with percValue for each class - const childSketches = toNullSketchArray(data.sketch); - const childSketchIds = childSketches.map((sk) => sk.properties.id); - const childSketchMetrics = toPercentMetric( - metricsWithSketchId( - data.metrics.filter((m) => m.metricId === metricGroup.metricId), - childSketchIds, - ), - precalcMetrics, - ); - const sketchRows = flattenBySketchAllClass( - childSketchMetrics, - metricGroup.classes, - childSketches, - ); - return ( - - ); -}; diff --git a/src/components/RenewableEnergy.tsx b/src/components/RenewableEnergy.tsx index 0586828..bb34163 100644 --- a/src/components/RenewableEnergy.tsx +++ b/src/components/RenewableEnergy.tsx @@ -19,6 +19,7 @@ import { toPercentMetric, } from "@seasketch/geoprocessing/client-core"; import project from "../../project/projectClient.js"; +import { genSketchTable } from "../util/genSketchTable.js"; /** * RenewableEnergy component @@ -28,7 +29,7 @@ import project from "../../project/projectClient.js"; */ export const RenewableEnergy: React.FunctionComponent = (props) => { const { t } = useTranslation(); - const [{ isCollection }] = useSketchProperties(); + const [{ isCollection, id, childProperties }] = useSketchProperties(); const curGeography = project.getGeographyById(props.geographyId, { fallbackGroup: "default-boundary", }); @@ -44,9 +45,7 @@ export const RenewableEnergy: React.FunctionComponent = (props) => { // Labels const titleLabel = t("Renewable Energy"); const mapLabel = t("Map"); - const withinLabel = t("Within Plan"); const percWithinLabel = t("% Within Plan"); - const unitsLabel = t("units"); return ( = (props) => { const valueMetrics = metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), - [data.sketch.properties.id], + [id], ); const percentMetrics = toPercentMetric(valueMetrics, precalcMetrics, { metricIdOverride: percMetricIdName, @@ -115,7 +114,12 @@ export const RenewableEnergy: React.FunctionComponent = (props) => { {isCollection && ( - {genSketchTable(data, metricGroup, precalcMetrics)} + {genSketchTable( + data, + metricGroup, + precalcMetrics, + childProperties || [], + )} )} @@ -148,28 +152,3 @@ export const RenewableEnergy: React.FunctionComponent = (props) => { ); }; - -const genSketchTable = ( - data: ReportResult, - metricGroup: MetricGroup, - precalcMetrics: Metric[], -) => { - // Build agg metric objects for each child sketch in collection with percValue for each class - const childSketches = toNullSketchArray(data.sketch); - const childSketchIds = childSketches.map((sk) => sk.properties.id); - const childSketchMetrics = toPercentMetric( - metricsWithSketchId( - data.metrics.filter((m) => m.metricId === metricGroup.metricId), - childSketchIds, - ), - precalcMetrics, - ); - const sketchRows = flattenBySketchAllClass( - childSketchMetrics, - metricGroup.classes, - childSketches, - ); - return ( - - ); -}; diff --git a/src/components/Shipwrecks.tsx b/src/components/Shipwrecks.tsx index 77bb797..6b0c1aa 100644 --- a/src/components/Shipwrecks.tsx +++ b/src/components/Shipwrecks.tsx @@ -1,7 +1,6 @@ import React from "react"; -import { Trans, useTranslation } from "react-i18next"; +import { useTranslation } from "react-i18next"; import { - ClassTable, Collapse, KeySection, LayerToggle, @@ -15,12 +14,11 @@ import { Metric, MetricGroup, ReportResult, + SketchProperties, flattenBySketchAllClass, isMetricArray, metricsWithSketchId, percentWithEdge, - roundLower, - toNullSketchArray, toPercentMetric, } from "@seasketch/geoprocessing/client-core"; import project from "../../project/projectClient.js"; @@ -34,7 +32,7 @@ import precalcMetrics from "../../data/bin/shipwrecksPrecalc.json"; */ export const Shipwrecks: React.FunctionComponent = (props) => { const { t } = useTranslation(); - const [{ isCollection }] = useSketchProperties(); + const [{ isCollection, id, childProperties }] = useSketchProperties(); const curGeography = project.getGeographyById(props.geographyId, { fallbackGroup: "default-boundary", }); @@ -46,10 +44,6 @@ export const Shipwrecks: React.FunctionComponent = (props) => { // Labels const titleLabel = t("Shipwrecks"); - const mapLabel = t("Map"); - const withinLabel = t("Within Plan"); - const percWithinLabel = t("% Within Plan"); - const unitsLabel = t("units"); return ( = (props) => { const valueMetrics = metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), - [data.sketch.properties.id], + [id], ); const percentMetrics = toPercentMetric(valueMetrics, precalcMetrics, { metricIdOverride: percMetricIdName, @@ -92,7 +86,11 @@ export const Shipwrecks: React.FunctionComponent = (props) => { {isCollection && ( - {genSketchTable(data, metricGroup)} + {genSketchTable( + data.metrics, + metricGroup, + childProperties || [], + )} )} @@ -102,18 +100,22 @@ export const Shipwrecks: React.FunctionComponent = (props) => { ); }; -const genSketchTable = (data: ReportResult, metricGroup: MetricGroup) => { - // Build agg metric objects for each child sketch in collection with percValue for each class - const childSketches = toNullSketchArray(data.sketch); - const childSketchIds = childSketches.map((sk) => sk.properties.id); +const genSketchTable = ( + metrics: Metric[], + metricGroup: MetricGroup, + childProperties: SketchProperties[], +) => { + const childSketchIds = childProperties + ? childProperties.map((skp) => skp.id) + : []; const childSketchMetrics = metricsWithSketchId( - data.metrics.filter((m) => m.metricId === metricGroup.metricId), + metrics.filter((m) => m.metricId === metricGroup.metricId), childSketchIds, ); const sketchRows = flattenBySketchAllClass( childSketchMetrics, metricGroup.classes, - childSketches, + childProperties, ); return ; }; diff --git a/src/components/SpeciesProtection.tsx b/src/components/SpeciesProtection.tsx index 9ef17a2..4582af0 100644 --- a/src/components/SpeciesProtection.tsx +++ b/src/components/SpeciesProtection.tsx @@ -5,21 +5,17 @@ import { Collapse, ReportError, ResultsCard, - SketchClassTable, useSketchProperties, } from "@seasketch/geoprocessing/client-ui"; import { GeogProp, - Metric, - MetricGroup, ReportResult, - flattenBySketchAllClass, metricsWithSketchId, - toNullSketchArray, toPercentMetric, valueFormatter, } from "@seasketch/geoprocessing/client-core"; import project from "../../project/projectClient.js"; +import { genSketchTable } from "../util/genSketchTable.js"; /** * SpeciesProtection component @@ -29,7 +25,7 @@ import project from "../../project/projectClient.js"; */ export const SpeciesProtection: React.FunctionComponent = (props) => { const { t } = useTranslation(); - const [{ isCollection }] = useSketchProperties(); + const [{ isCollection, id, childProperties }] = useSketchProperties(); const curGeography = project.getGeographyById(props.geographyId, { fallbackGroup: "default-boundary", }); @@ -58,7 +54,7 @@ export const SpeciesProtection: React.FunctionComponent = (props) => { const valueMetrics = metricsWithSketchId( data.metrics.filter((m) => m.metricId === metricGroup.metricId), - [data.sketch.properties.id], + [id], ); const percentMetrics = toPercentMetric(valueMetrics, precalcMetrics, { metricIdOverride: percMetricIdName, @@ -125,7 +121,12 @@ export const SpeciesProtection: React.FunctionComponent = (props) => { {isCollection && ( - {genSketchTable(data, metricGroup, precalcMetrics)} + {genSketchTable( + data, + metricGroup, + precalcMetrics, + childProperties || [], + )} )} @@ -156,28 +157,3 @@ export const SpeciesProtection: React.FunctionComponent = (props) => { ); }; - -const genSketchTable = ( - data: ReportResult, - metricGroup: MetricGroup, - precalcMetrics: Metric[], -) => { - // Build agg metric objects for each child sketch in collection with percValue for each class - const childSketches = toNullSketchArray(data.sketch); - const childSketchIds = childSketches.map((sk) => sk.properties.id); - const childSketchMetrics = toPercentMetric( - metricsWithSketchId( - data.metrics.filter((m) => m.metricId === metricGroup.metricId), - childSketchIds, - ), - precalcMetrics, - ); - const sketchRows = flattenBySketchAllClass( - childSketchMetrics, - metricGroup.classes, - childSketches, - ); - return ( - - ); -}; diff --git a/src/functions/clipToLand.ts b/src/functions/clipToLand.ts deleted file mode 100644 index cbbf84e..0000000 --- a/src/functions/clipToLand.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { - PreprocessingHandler, - Feature, - Sketch, - isPolygonFeature, - ValidationError, - clipToPolygonFeatures, - DatasourceClipOperation, - DefaultExtraParams, -} from "@seasketch/geoprocessing"; -import project from "../../project/projectClient.js"; -import { genClipLoader } from "@seasketch/geoprocessing/dataproviders"; - -/** - * Preprocessor takes a Polygon feature/sketch and returns the portion that - * overlaps with land. If results in multiple polygons then returns the largest. - */ -export async function clipToLand( - feature: Feature | Sketch, - extraParams: DefaultExtraParams = {}, -): Promise { - if (!isPolygonFeature(feature)) { - throw new ValidationError("Input must be a polygon"); - } - - /** - * Subtract parts of feature/sketch that don't overlap with land. Uses global OSM land polygons - * unionProperty is specific to subdivided datasets. When defined, it will fetch - * and rebuild all subdivided land features overlapping with the feature/sketch - * with the same gid property (assigned one per country) into one feature before clipping. - * This is useful for preventing slivers from forming and possible for performance. - * unionProperty will optionally filter the land features by one or more country ID so you can - * constrain it to a specific country. - */ - const keepLand: DatasourceClipOperation = { - datasourceId: "global-clipping-osm-land", - operation: "intersection", - options: { - unionProperty: "gid", // gid is assigned per country - propertyFilter: { - property: "gid", - values: extraParams?.countryIds || [project.basic.planningAreaId] || [], - }, - }, - }; - - // Create a function that will perform the clip operations in order - const clipLoader = genClipLoader(project, [keepLand]); - - // Wrap clip function into preprocessing function with additional clip options - return clipToPolygonFeatures(feature, clipLoader, { - maxSize: 500_000 * 1000 ** 2, // Default 500,000 KM - enforceMaxSize: false, - ensurePolygon: true, - }); -} - -export default new PreprocessingHandler(clipToLand, { - title: "clipToLand", - description: "Clips portion of feature or sketch not overlapping land", - timeout: 40, - requiresProperties: [], - memory: 4096, -}); diff --git a/src/functions/clipToLandSmoke.test.ts b/src/functions/clipToLandSmoke.test.ts deleted file mode 100644 index 517be81..0000000 --- a/src/functions/clipToLandSmoke.test.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @vitest-environment node - */ -import handler, { clipToLand } from "./clipToLand.js"; -import { polygonPreprocessorSmokeTest } from "@seasketch/geoprocessing/scripts/testing"; - -// polygonPreprocessorSmokeTest(clipToLand, handler.options.title, { -// timeout: 30000, -// debug: true, -// }); diff --git a/src/functions/clipToOcean.ts b/src/functions/clipToOcean.ts deleted file mode 100644 index 75c1e91..0000000 --- a/src/functions/clipToOcean.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { - PreprocessingHandler, - Feature, - Sketch, - isPolygonFeature, - ValidationError, - clipToPolygonFeatures, - DatasourceClipOperation, - DefaultExtraParams, -} from "@seasketch/geoprocessing"; -import project from "../../project/projectClient.js"; -import { genClipLoader } from "@seasketch/geoprocessing/dataproviders"; - -/** - * Preprocessor takes a Polygon feature/sketch and returns the portion that - * is in the ocean (not on land) and within one or more EEZ boundaries. - * If results in multiple polygons then returns the largest. - */ -export async function clipToOcean( - feature: Feature | Sketch, - extraParams: DefaultExtraParams = {}, // eslint-disable-line @typescript-eslint/no-unused-vars -): Promise { - if (!isPolygonFeature(feature)) { - throw new ValidationError("Input must be a polygon"); - } - - /** - * Subtract parts of feature/sketch that overlap with land. Uses global OSM land polygons - * unionProperty is specific to subdivided datasets. When defined, it will fetch - * and rebuild all subdivided land features overlapping with the feature/sketch - * with the same gid property (assigned one per country) into one feature before clipping - */ - const removeLand: DatasourceClipOperation = { - datasourceId: "global-clipping-osm-land", - operation: "difference", - options: { - unionProperty: "gid", // gid is assigned per country - }, - }; - - // Create a function that will perform the clip operations in order - const clipLoader = genClipLoader(project, [removeLand]); - - // Wrap clip function into preprocessing function with additional clip options - return clipToPolygonFeatures(feature, clipLoader, { - maxSize: 500_000 * 1000 ** 2, // Default 500,000 KM - enforceMaxSize: false, - ensurePolygon: true, - }); -} - -export default new PreprocessingHandler(clipToOcean, { - title: "clipToOcean", - description: "Clips feature or sketch to ocean, removing land", - timeout: 40, - requiresProperties: [], - memory: 4096, -}); diff --git a/src/functions/clipToOceanEez.ts b/src/functions/clipToOceanEez.ts index e6f920b..c34ce38 100644 --- a/src/functions/clipToOceanEez.ts +++ b/src/functions/clipToOceanEez.ts @@ -1,15 +1,17 @@ import { - PreprocessingHandler, Feature, + FeatureClipOperation, + MultiPolygon, + Polygon, + PreprocessingHandler, Sketch, - isPolygonFeature, - ValidationError, clipToPolygonFeatures, - DatasourceClipOperation, - DefaultExtraParams, + ensureValidPolygon, + isVectorDatasource, + loadFgb, } from "@seasketch/geoprocessing"; import project from "../../project/projectClient.js"; -import { genClipLoader } from "@seasketch/geoprocessing/dataproviders"; +import { bbox } from "@turf/turf"; /** * Preprocessor takes a Polygon feature/sketch and returns the portion that @@ -17,56 +19,41 @@ import { genClipLoader } from "@seasketch/geoprocessing/dataproviders"; */ export async function clipToOceanEez( feature: Feature | Sketch, - extraParams: DefaultExtraParams = {}, ): Promise { - if (!isPolygonFeature(feature)) { - throw new ValidationError("Input must be a polygon"); - } + // throws if not valid with specific message + ensureValidPolygon(feature, { + minSize: 1, + enforceMinSize: false, + maxSize: 500_000 * 1000 ** 2, // Default 500,000 KM + enforceMaxSize: false, + }); - /** - * Subtract parts of feature/sketch that overlap with land. Uses global OSM land polygons - * unionProperty is specific to subdivided datasets. When defined, it will fetch - * and rebuild all subdivided land features overlapping with the feature/sketch - * with the same gid property (assigned one per country) into one feature before clipping. - * This is useful for preventing slivers from forming and possible for performance. - */ - const removeLand: DatasourceClipOperation = { - datasourceId: "global-clipping-osm-land", - operation: "difference", - options: { - unionProperty: "gid", // gid is assigned per country - }, - }; + const featureBox = bbox(feature); - // Optionally, subtract parts of feature/sketch that are outside of one - // or more EEZ's. Using a runtime-provided list of EEZ's via extraParams.eezFilterByNames - // allows this preprocessor to work for any set of EEZ's. Using a project-configured - // planningAreaId allows this preprocessor to work for a specific EEZ. - const removeOutsideEez: DatasourceClipOperation = { - datasourceId: "global-clipping-eez-land-union", + const ds = project.getDatasourceById("nearshore_dissolved"); + if (!isVectorDatasource(ds)) + throw new Error(`Expected vector datasource for ${ds.datasourceId}`); + const url = project.getDatasourceUrl(ds); + + // Keep portion of sketch within EEZ + const features: Feature[] = await loadFgb( + url, + featureBox, + ); + + const keepInsideEez: FeatureClipOperation = { operation: "intersection", - options: { - propertyFilter: { - property: "UNION", - values: extraParams?.eezNames || [project.basic.planningAreaId] || [], - }, - }, + clipFeatures: features, }; - // Create a function that will perform the clip operations in order - const clipLoader = genClipLoader(project, [removeLand, removeOutsideEez]); - - // Wrap clip function into preprocessing function with additional clip options - return clipToPolygonFeatures(feature, clipLoader, { - maxSize: 500_000 * 1000 ** 2, // Default 500,000 KM - enforceMaxSize: false, // throws error if feature is larger than maxSize - ensurePolygon: true, // don't allow multipolygon result, returns largest if multiple + return clipToPolygonFeatures(feature, [keepInsideEez], { + ensurePolygon: true, }); } export default new PreprocessingHandler(clipToOceanEez, { title: "clipToOceanEez", - description: "Example-description", + description: "Clips sketches to state waters", timeout: 40, requiresProperties: [], memory: 4096, diff --git a/src/util/genSketchTable.tsx b/src/util/genSketchTable.tsx new file mode 100644 index 0000000..4b1cd41 --- /dev/null +++ b/src/util/genSketchTable.tsx @@ -0,0 +1,37 @@ +import React from "react"; +import { + flattenBySketchAllClass, + Metric, + MetricGroup, + metricsWithSketchId, + ReportResult, + SketchProperties, + toPercentMetric, +} from "@seasketch/geoprocessing/client-core"; +import { SketchClassTable } from "@seasketch/geoprocessing/client-ui"; + +export const genSketchTable = ( + data: ReportResult, + metricGroup: MetricGroup, + precalcMetrics: Metric[], + childProperties: SketchProperties[], +) => { + const childSketchIds = childProperties + ? childProperties.map((skp) => skp.id) + : []; + const childSketchMetrics = toPercentMetric( + metricsWithSketchId( + data.metrics.filter((m) => m.metricId === metricGroup.metricId), + childSketchIds, + ), + precalcMetrics, + ); + const sketchRows = flattenBySketchAllClass( + childSketchMetrics, + metricGroup.classes, + childProperties, + ); + return ( + + ); +};