Reputation: 43
I'm trying to calculate the mean of all pixels at the county level for an image in Google Earth Engine and am using the rgee package in R Studio.
I've tried following the example here: https://github.com/csaybar/rgee/blob/examples/image/image_stats_by_band.R
The code runs but results in a long print out in R of feature$geometry$coordinates, feature$properties, etc., and I just want the mean value of the band and would like to use the mean value in subsequent calculations. I think I want one of the value in one of the last lines that is printed: $features[[1]]$properties$data
#GY16 is an image covering a U.S. state with 1 band and I would like to calculate the mean of that image at the county level. shp1 is the county geometry.
geometry <- shp1
means <- GY16$reduceRegions(
collection = geometry,
reducer = ee$Reducer$mean()$forEachBand(GY16),
scale=10
)
print(means$getInfo())
Any advice is appreciated. Thank you!
Upvotes: 0
Views: 444
Reputation: 179
This example was made in rgee early versions, now you can use ee_extract:
library(rgee)
# remotes::install_github("r-spatial/rgee") please install rgee v1.0.9
ee_Initialize()
image <- ee$Image("USDA/NAIP/DOQQ/m_3712213_sw_10_1_20140613")
geometry <- image$geometry()
ee_extract(image, geometry, scale = 100, sf = FALSE)
Upvotes: 0