-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding new raster layers: water, population, forest gain
- Loading branch information
1 parent
2c67140
commit 71d31a1
Showing
5 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
cloud_functions/earth_engine_tiler/src/geeAssets/forest-gain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ContinuousDataset } from './earth-engine-dataset'; | ||
import ee from '@google/earthengine'; | ||
import { EarthEngineUtils } from "../earth-engine-utils"; | ||
|
||
export const ForestGain: ContinuousDataset = { | ||
assetPath: { | ||
default: "projects/glad/GLCLU2020/Forest_gain" | ||
}, | ||
|
||
vizParams: { | ||
bands: ['b1'], | ||
min: 0, | ||
max: 1, | ||
palette: ['#008000'] | ||
}, | ||
|
||
areYearsValid(startYear?: number, endYear?: number): boolean { | ||
// This Asset is static, and year selector is irrelevant | ||
return true; | ||
}, | ||
|
||
getEEAsset() { | ||
// Apply mask | ||
const rawImage = ee.Image(this.assetPath.default); | ||
const maskedImage = rawImage | ||
.select('b1') | ||
.updateMask(rawImage); // Mask out no-data pixels | ||
|
||
return maskedImage; | ||
}, | ||
|
||
async getMapUrl(z, x, y, startYear, endYear) { | ||
const image = this.getEEAsset() | ||
|
||
const mapId = await EarthEngineUtils.getMapId(image, this.vizParams); | ||
|
||
return ee.data.getTileUrl( mapId, x, y, z ); | ||
}, | ||
}; |
50 changes: 50 additions & 0 deletions
50
cloud_functions/earth_engine_tiler/src/geeAssets/population-count.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ContinuousDataset } from './earth-engine-dataset'; | ||
import ee from '@google/earthengine'; | ||
import { EarthEngineUtils } from "../earth-engine-utils"; | ||
|
||
export const PopulationCount: ContinuousDataset = { | ||
assetPath: { | ||
1975: "JRC/GHSL/P2023A/GHS_POP/1975", | ||
1990: "JRC/GHSL/P2023A/GHS_POP/1990", | ||
2020: "JRC/GHSL/P2023A/GHS_POP/2020" | ||
}, | ||
|
||
vizParams: { | ||
bands: ['population_count'], | ||
min: 0.0, | ||
max: 100.0, | ||
palette: ['000004', '320A5A', '781B6C', 'BB3654', 'EC6824', 'FBB41A', 'FCFFA4'] | ||
}, | ||
|
||
areYearsValid(startYear?: number, endYear?: number): boolean { | ||
const validYears = [1975, 1990, 2020]; | ||
if (!startYear || !validYears.includes(startYear)) { | ||
throw new Error(`Start Year '${startYear}' is not valid. Valid years are: ${validYears.join(", ")}`); | ||
} | ||
return true; | ||
}, | ||
|
||
getEEAsset(startYear: string) { // Change the parameter to string as per the type definition | ||
// Load the asset for the specified year | ||
const assetPath = this.assetPath[parseInt(startYear)]; // Convert the string to number if necessary | ||
if (!assetPath) { | ||
throw new Error(`Asset not found for year '${startYear}'`); | ||
} | ||
|
||
// Load the image and apply masking logic | ||
const rawImage = ee.Image(assetPath); | ||
return rawImage.updateMask(rawImage.gt(0)); // Mask out pixels with value 0 | ||
}, | ||
|
||
async getMapUrl(z: number, x: number, y: number, startYear: number, endYear?: number) { | ||
// Validate the year and get the asset | ||
this.areYearsValid(startYear, endYear); | ||
const image = this.getEEAsset(startYear); | ||
|
||
// Generate the mapId with visualization parameters | ||
const mapId = await EarthEngineUtils.getMapId(image, this.vizParams); | ||
|
||
// Return the Tile URL | ||
return ee.data.getTileUrl(mapId, x, y, z); | ||
}, | ||
}; |
34 changes: 34 additions & 0 deletions
34
cloud_functions/earth_engine_tiler/src/geeAssets/surface-water.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ContinuousDataset } from './earth-engine-dataset'; | ||
import ee from '@google/earthengine'; | ||
import {EarthEngineUtils} from "../earth-engine-utils"; | ||
|
||
|
||
export const SurfaceWater: ContinuousDataset = { | ||
assetPath: { | ||
default: "JRC/GSW1_4/GlobalSurfaceWater" | ||
}, | ||
|
||
vizParams: { | ||
bands: ['occurrence'], | ||
min: 0, | ||
max: 100, | ||
palette: ['ffffff', 'ffbbbb', '0000ff'] | ||
}, | ||
|
||
areYearsValid (startYear?: number, endYear?: number) : boolean { | ||
//This Asset is static, and year selector are irrelevant | ||
return true; | ||
}, | ||
|
||
getEEAsset() { | ||
return ee.Image(this.assetPath.default); | ||
}, | ||
|
||
async getMapUrl(z, x, y, startYear, endYear) { | ||
const image = this.getEEAsset() | ||
|
||
const mapId = await EarthEngineUtils.getMapId(image, this.vizParams); | ||
|
||
return ee.data.getTileUrl( mapId, x, y, z ); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters