From 05f765a3512dfe78ee4e1a1be01ec94f505d8cb9 Mon Sep 17 00:00:00 2001 From: sofia Date: Tue, 5 Nov 2024 12:38:36 +0100 Subject: [PATCH] addition of gridded livestock layers --- .../src/geeAssets/common-styles-utils.ts | 17 +++++++++++ .../geeAssets/gridded-livestock-buffalo.ts | 30 +++++++++++++++++++ .../src/geeAssets/gridded-livestock-cattle.ts | 30 +++++++++++++++++++ .../src/geeAssets/gridded-livestock-goat.ts | 30 +++++++++++++++++++ .../src/geeAssets/gridded-livestock-horse.ts | 30 +++++++++++++++++++ .../src/geeAssets/gridded-livestock-sheep.ts | 30 +++++++++++++++++++ .../earth_engine_tiler/src/index.ts | 12 +++++++- .../src/tile-request.dto.ts | 7 ++++- 8 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 cloud_functions/earth_engine_tiler/src/geeAssets/common-styles-utils.ts create mode 100644 cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-buffalo.ts create mode 100644 cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-cattle.ts create mode 100644 cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-goat.ts create mode 100644 cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-horse.ts create mode 100644 cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-sheep.ts diff --git a/cloud_functions/earth_engine_tiler/src/geeAssets/common-styles-utils.ts b/cloud_functions/earth_engine_tiler/src/geeAssets/common-styles-utils.ts new file mode 100644 index 0000000..ef633e3 --- /dev/null +++ b/cloud_functions/earth_engine_tiler/src/geeAssets/common-styles-utils.ts @@ -0,0 +1,17 @@ +export const GriddedLivestockCommonStyles = + +'' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + +'' \ No newline at end of file diff --git a/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-buffalo.ts b/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-buffalo.ts new file mode 100644 index 0000000..f8dbce5 --- /dev/null +++ b/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-buffalo.ts @@ -0,0 +1,30 @@ +import { CategoricalDataset } from './earth-engine-dataset'; +import ee from '@google/earthengine'; +import { EarthEngineUtils } from "../earth-engine-utils"; +import { GriddedLivestockCommonStyles} from "./common-styles-utils"; + +export const GriddedLivestockBuffalo: CategoricalDataset = { + assetPath: { + default: "projects/gmvad-grass/assets/5_Bf_2015_Da" + }, + + bandName: 'b1', + + sldStyles: GriddedLivestockCommonStyles, + + + areYearsValid(startYear?: number, endYear?: number): boolean { + // This Asset is static, and year selector is irrelevant + return true; + }, + + getEEAsset() { + return ee.Image(this.assetPath.default); + }, + + async getMapUrl(z, x, y) { + const image = this.getEEAsset().select(this.bandName).sldStyle(this.sldStyles); + const mapId = await EarthEngineUtils.getMapId(image); + return ee.data.getTileUrl(mapId, x, y, z); + }, +}; diff --git a/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-cattle.ts b/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-cattle.ts new file mode 100644 index 0000000..b3890fc --- /dev/null +++ b/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-cattle.ts @@ -0,0 +1,30 @@ +import { CategoricalDataset } from './earth-engine-dataset'; +import ee from '@google/earthengine'; +import { EarthEngineUtils } from "../earth-engine-utils"; +import { GriddedLivestockCommonStyles} from "./common-styles-utils"; + +export const GriddedLivestockCattle: CategoricalDataset = { + assetPath: { + default: "projects/gmvad-grass/assets/5_Ct_2015_Da" + }, + + bandName: 'b1', + + sldStyles: GriddedLivestockCommonStyles, + + + areYearsValid(startYear?: number, endYear?: number): boolean { + // This Asset is static, and year selector is irrelevant + return true; + }, + + getEEAsset() { + return ee.Image(this.assetPath.default); + }, + + async getMapUrl(z, x, y) { + const image = this.getEEAsset().select(this.bandName).sldStyle(this.sldStyles); + const mapId = await EarthEngineUtils.getMapId(image); + return ee.data.getTileUrl(mapId, x, y, z); + }, +}; diff --git a/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-goat.ts b/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-goat.ts new file mode 100644 index 0000000..d3ea674 --- /dev/null +++ b/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-goat.ts @@ -0,0 +1,30 @@ +import { CategoricalDataset } from './earth-engine-dataset'; +import ee from '@google/earthengine'; +import { EarthEngineUtils } from "../earth-engine-utils"; +import { GriddedLivestockCommonStyles} from "./common-styles-utils"; + +export const GriddedLivestockGoat: CategoricalDataset = { + assetPath: { + default: "projects/gmvad-grass/assets/5_Gt_2015_Da" + }, + + bandName: 'b1', + + sldStyles: GriddedLivestockCommonStyles, + + + areYearsValid(startYear?: number, endYear?: number): boolean { + // This Asset is static, and year selector is irrelevant + return true; + }, + + getEEAsset() { + return ee.Image(this.assetPath.default); + }, + + async getMapUrl(z, x, y) { + const image = this.getEEAsset().select(this.bandName).sldStyle(this.sldStyles); + const mapId = await EarthEngineUtils.getMapId(image); + return ee.data.getTileUrl(mapId, x, y, z); + }, +}; diff --git a/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-horse.ts b/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-horse.ts new file mode 100644 index 0000000..48a08b4 --- /dev/null +++ b/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-horse.ts @@ -0,0 +1,30 @@ +import { CategoricalDataset } from './earth-engine-dataset'; +import ee from '@google/earthengine'; +import { EarthEngineUtils } from "../earth-engine-utils"; +import { GriddedLivestockCommonStyles} from "./common-styles-utils"; + +export const GriddedLivestockHorse: CategoricalDataset = { + assetPath: { + default: "projects/gmvad-grass/assets/5_Ho_2015_Da" + }, + + bandName: 'b1', + + sldStyles: GriddedLivestockCommonStyles, + + + areYearsValid(startYear?: number, endYear?: number): boolean { + // This Asset is static, and year selector is irrelevant + return true; + }, + + getEEAsset() { + return ee.Image(this.assetPath.default); + }, + + async getMapUrl(z, x, y) { + const image = this.getEEAsset().select(this.bandName).sldStyle(this.sldStyles); + const mapId = await EarthEngineUtils.getMapId(image); + return ee.data.getTileUrl(mapId, x, y, z); + }, +}; diff --git a/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-sheep.ts b/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-sheep.ts new file mode 100644 index 0000000..f077fc7 --- /dev/null +++ b/cloud_functions/earth_engine_tiler/src/geeAssets/gridded-livestock-sheep.ts @@ -0,0 +1,30 @@ +import { CategoricalDataset } from './earth-engine-dataset'; +import ee from '@google/earthengine'; +import { EarthEngineUtils } from "../earth-engine-utils"; +import { GriddedLivestockCommonStyles} from "./common-styles-utils"; + +export const GriddedLivestockSheep: CategoricalDataset = { + assetPath: { + default: "projects/gmvad-grass/assets/5_Sh_2015_Da" + }, + + bandName: 'b1', + + sldStyles: GriddedLivestockCommonStyles, + + + areYearsValid(startYear?: number, endYear?: number): boolean { + // This Asset is static, and year selector is irrelevant + return true; + }, + + getEEAsset() { + return ee.Image(this.assetPath.default); + }, + + async getMapUrl(z, x, y) { + const image = this.getEEAsset().select(this.bandName).sldStyle(this.sldStyles); + const mapId = await EarthEngineUtils.getMapId(image); + return ee.data.getTileUrl(mapId, x, y, z); + }, +}; diff --git a/cloud_functions/earth_engine_tiler/src/index.ts b/cloud_functions/earth_engine_tiler/src/index.ts index 7b75937..53f4340 100644 --- a/cloud_functions/earth_engine_tiler/src/index.ts +++ b/cloud_functions/earth_engine_tiler/src/index.ts @@ -8,6 +8,11 @@ import {ModisNetPrimaryProductionChange} from './geeAssets/modis-net-primary-pro import {AnthropogenicBiomes} from './geeAssets/anthropogenic-biomes'; import {LivestockProductionSystems} from './geeAssets/livestock-production-systems'; import {ForestLoss} from './geeAssets/forest-loss'; +import {GriddedLivestockCattle} from './geeAssets/gridded-livestock-cattle'; +import {GriddedLivestockGoat} from './geeAssets/gridded-livestock-goat'; +import {GriddedLivestockHorse} from './geeAssets/gridded-livestock-horse'; +import {GriddedLivestockBuffalo} from './geeAssets/gridded-livestock-buffalo'; +import {GriddedLivestockSheep} from './geeAssets/gridded-livestock-sheep'; import {EarthEngineDataset} from "./geeAssets/earth-engine-dataset"; import {TileRequestDTO, Tilesets} from "./tile-request.dto"; import {default as fetch , Response as FetchResponse} from "node-fetch"; @@ -20,7 +25,12 @@ const assets: Record = { [Tilesets.modis_net_primary_production_change]: ModisNetPrimaryProductionChange, [Tilesets.anthropogenic_biomes]: AnthropogenicBiomes, [Tilesets.livestock_production_systems]: LivestockProductionSystems, - [Tilesets.forest_loss]: ForestLoss + [Tilesets.forest_loss]: ForestLoss, + [Tilesets.gridded_livestock_cattle]: GriddedLivestockCattle, + [Tilesets.gridded_livestock_goat]: GriddedLivestockGoat, + [Tilesets.gridded_livestock_horse]: GriddedLivestockHorse, + [Tilesets.gridded_livestock_buffalo]: GriddedLivestockBuffalo, + [Tilesets.gridded_livestock_sheep]: GriddedLivestockSheep, } //We're using express to simplify path parameter parsing for the Tiles endpoint diff --git a/cloud_functions/earth_engine_tiler/src/tile-request.dto.ts b/cloud_functions/earth_engine_tiler/src/tile-request.dto.ts index b56947c..fc70818 100644 --- a/cloud_functions/earth_engine_tiler/src/tile-request.dto.ts +++ b/cloud_functions/earth_engine_tiler/src/tile-request.dto.ts @@ -6,7 +6,12 @@ export enum Tilesets { modis_net_primary_production_change = "modis_net_primary_production_change", anthropogenic_biomes = "anthropogenic_biomes", livestock_production_systems = "livestock_production_systems", - forest_loss = "forest_loss" + forest_loss = "forest_loss", + gridded_livestock_cattle = "gridded_livestock_cattle", + gridded_livestock_goat = "gridded_livestock_goat", + gridded_livestock_horse = "gridded_livestock_horse", + gridded_livestock_buffalo = "gridded_livestock_buffalo", + gridded_livestock_sheep = "gridded_livestock_sheep" }