Geographic Information Systems Asked by Matthew J Watts on December 5, 2020
I’m trying count the number of monthly water pixels from JRC Water History Collection using Google Earth Engine – Rgee, over a set of regions.
https://developers.google.com/earth-engine/datasets/catalog/JRC_GSW1_2_MonthlyHistory
This is what i am trying to achieve:
Select the image collection and filter by dates for the time series.
Select water only pixels and create masks containing only water pixels for each monthly image. Note this dataset uses a Bitmask:
Bits 0-1: Water detection
0: No data
1: Not water
2: Water
Count the number of water pixels in each region for each monthly image (create regional time-series)
I think something is going wrong in step 2 – as some pixel counts are missing, i’m not confident the results are correct, can anyone help?
library(rgee)
library(mapview)
library(sf)
ee_Initialize
wnf_shapes <- st_read("./wnf_shapes.shp")
# Step 1
filteredJRCDataset <- ee$ImageCollection("JRC/GSW1_2/MonthlyHistory")$
filterDate("2006-01-01", "2006-12-31")
# Step 2
surface_water <- filteredJRCDataset$map(function (image) {
waterImage <-image$select('water')$eq(2)
image = image$updateMask(waterImage)
})
# Step 3
ee_sw <- ee_extract(x = surface_water, y = wnf_shapes, scale = 100, fun = ee$Reducer$count(), sf = FALSE)
colnames(ee_sw) <- sprintf("%02d", 1:12)
ee_sw$id <- wnf_shapes$id
link to shapes files – https://drive.google.com/file/d/1oWJ_ZpEQ4bEYr7R73oOXrQc9UhOH_oCB/view?usp=sharing
I could also do this using Javascript or Python APIs for anyone not using Rgee.
Answer:
filteredJRCDataset <- ee$ImageCollection("JRC/GSW1_2/MonthlyHistory")$ filterDate("2006-01-01", "2006-12-31")
surface_water <- filteredJRCDataset$map(function (image) { waterImage <-image$select('water')$eq(2) # mask is already created here, 1 is returned for water and 0 all other observation
})
ee_sw <- ee_extract(x = surface_water, y = wnf_shapes, scale = 100, fun = ee$Reducer$sum(), sf = FALSE) # we just need to sum the 1s here instead of count observations
colnames(ee_sw) <- sprintf("%02d", 1:12) ee_sw$id <- wnf_shapes$id
Answered by Matthew J Watts on December 5, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP