r-spatial / rgee

Google Earth Engine for R
https://r-spatial.github.io/rgee/
Other
677 stars 146 forks source link

`ee_extract` fails with feature collection > 5k features no matter how `via` is set #259

Closed zackarno closed 2 years ago

zackarno commented 2 years ago

Hello,

I noticed ee_extract fails with feature collection > 5k features no matter how via is set. I think it is because of how rgee::ee_as_sf is called without the the option to change the default maxFeatures argument in rgee::ee_extract . I've copied this section of the code below. I think a simple solution could be to let the user supply a maxFeatures argument to rgee::ee_extract which would then be passed to rgee::ee_as_sf

  else if (any(ee_get_spatial_objects("Table") %in% class(y))) {
    ee_y <- ee$FeatureCollection(y)
    sf_y <- ee_as_sf(y, quiet = TRUE)
  }

Below is a reprex:

library(rgee)
library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
ee_Initialize()
#> -- rgee 1.1.2.9000 ---------------------------------- earthengine-api 0.1.295 -- 
#>  v user: not_defined
#>  v Initializing Google Earth Engine: v Initializing Google Earth Engine:  DONE!
#>  v Earth Engine account: users/zackarno 
#> --------------------------------------------------------------------------------

chirps_link <- "UCSB-CHG/CHIRPS/DAILY"
chirps <- ee$ImageCollection(chirps_link)

pt_mali <- data.frame(y= -5.292484,x= 14.289664) |>
  sf::st_as_sf(coords=c("y","x"), crs=4326)

pt_mali_buffered_5k <- pt_mali |>
  sf::st_transform(crs=32629) |>
  sf::st_buffer(dist = 5000) |>
  sf::st_transform(crs=4326)

rnd_pts <- sf::st_sample(x = pt_mali_buffered_5k,size = 5001)

rnd_pts_ee <- rgee::sf_as_ee(rnd_pts)
#> Registered S3 method overwritten by 'geojsonsf':
#>   method        from   
#>   print.geojson geojson

preicp_at_pts <-  rgee::ee_extract(x = chirps$first(),
                                  y = rnd_pts_ee,
                                  fun = ee$Reducer$median(),
                                  scale=5000,
                                  via = "drive"
                                  )
#> Error in value[[3L]](cond): Specify higher maxFeatures value if you intend to export a large area via getInfo.
#> Entered: 5001
#> maxFeatures: C:\Users\ZACK~1.ARN\AppData\Local\Temp\RtmpqAXyT5/no_tableid.geojson

Created on 2022-05-05 by the reprex package (v2.0.1)

csaybar commented 2 years ago

Hi, I added a message to inform users about this issue. THanks!

zackarno commented 2 years ago

@csaybar - I seems like you coded a check to make sure that maxFeatures value is less than 10000 . I'm not sure why? Is there a reason this is the limit? I understand the 5000 limit on via="getinfo", but not sure on why a 10000 limit would be enforced for the other via methods. I was suggesting that the user be able to supply the maxFeatures argument directly in ee_extract - is there a reason this doesn't make sense?

jfsmenezes commented 1 year ago

Hi I'm suffering from the same issue. Even if you set via="gcs" I still get an error stating that features cannot be greater than 10,000. I think the check is happening too early on the function.