Closed DavidDHofmann closed 2 years ago
Hi @DavidDHofmann you have to define the scale argument:
reduced2 <- ee_as_raster(reduced, dsn = "reduced.tif", scale = 1000)
The warnings appear because GEE retrieved your query using positive y spacing and raster
does not automatically support it. I recommend you use ee_as_stars
to avoid this problem. https://github.com/evetion/GeoArrays.jl/issues/53
Warning
In .rasterFromGDAL(x, band = band, objecttype, ...) :
data seems flipped. Consider using: flip(x, direction='y')
Hi @csaybar
Thank you for the swift reply! The code works when providing the scale
argument. Does this mean that it is not possible to download the data at its native resolution?
Hi @DavidDHofmann :)
In fact, you can!. The issue is that after applying a reducer collection$mean()$clip(aoi)
you will lose the image geotransform properties.
ee_print(collection)
ee_print(collection$mean())
It is a consequence of GEE lazy evaluation. The client library API does not know if after applying your "selected reducer" (mean) you are conserving the image geometric properties it's something that will be evaluated at the server-side. My advice would be to store the properties before the reducer.
# Load required packages
library(rgee)
library(terra)
# Init
ee_Initialize()
# Specify an area of interest
aoi <- ee$Geometry$Polygon(
list(
c(23.4976149678726, -19.649075296214)
, c(23.4976149678726, -19.2680589256603)
, c(23.93394016641, -19.2680589256603)
, c(23.93394016641, -19.649075296214)
)
)
# Query sentinel 2 data
collection <- ee$ImageCollection("COPERNICUS/S2_SR")$
filterDate("2021-04-05", "2021-04-06")$
filterBounds(aoi)$
select("B2")
collection$first()$projection()$nominalScale()$getInfo()
#10
Ah okey cool, I wasn't aware of this. This also explains why the estimated image size becomes unreasonably small after applying the reudcer. Thank you very much for the clarification. The download works perfectly fine now :)
At submit an issue, please attached the following information of your
rgee
session:[X] You have the Python API installed (from terminal):
[X] You can find the credentials file on your system:
[X] You can run a simple EE command from R:
Description
Hi there!
I'm trying to download Sentinel-2 data for a specific date. For the date and area of interest, Earth Engine returns an image-collection with two images that overlap in extent. I then try to reduce the collection into a single image using a median-reducer. Ultimately, I clip the reduced image to my area of interest and download the data. Oddly enough,
ee_print(reduced)
shows that the image only contains one pixel per band. Nevertheless, the image looks fine when displayed on the map. Only when downloaded, the bands contain only one value per band. To me, it seems that the reducer does not apply the median per pixel across bands, but across the entire band. The coordinates of the final image also do not exactly match my specified aoi and I get a warning after download saying:I'm not quite sure what I'm doing wrong. Any suggestions?
What I Did