r-spatial / rgee

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

ee_as_sf() maxFeatures only works for maxFeatures>5000 #229

Closed MatthieuStigler closed 2 years ago

MatthieuStigler commented 2 years ago

It looks like the argument maxFeatures in ee_as_sf() is assumed to be always bigger than 5000. If it is less than 5000, this will trigger an error message: Export too large. Specified 5000 features (max: 10) In the example below, the true FC has 5 features, and I am setting maxFeatures = 10, so this should work?

Looking at rgee:::ee_fc_to_sf_getInfo_batch, the problem seems clear: it is assuming that fc_size <- 5000, and only computing the true value of fc_size when maxFeatures > 5000.

library(rgee)
packageVersion("rgee")
#> [1] '1.1.2'

ee_Initialize( drive = TRUE, gcs = TRUE)
#> ── rgee 1.1.2 ─────────────────────────────────────── earthengine-api 0.1.248 ── 
#>  ✓ Google Drive credentials: ✓ Google Drive credentials:  FOUND
#>  ✓ GCS credentials: ✓ GCS credentials:  FOUND
#>  ✓ Initializing Google Earth Engine: ✓ Initializing Google Earth Engine:  DONE!
#> ────────────────────────────────────────────────────────────────────────────────

# TIGER: US Census Blocks Dataset
blocks <- ee$FeatureCollection("TIGER/2010/Blocks")
subset <- blocks$limit(5)
subset$size()$getInfo()
#> [1] 5

sf_subset <- ee_as_sf(x = subset, maxFeatures = 10)
#> Registered S3 method overwritten by 'geojsonsf':
#>   method        from   
#>   print.geojson geojson
#> Error in ee_fc_to_sf_getInfo_batch(x_fc = x_fc, dsn = dsn, maxFeatures = maxFeatures, : Export too large. Specified 5000 features (max: 10). Specify a higher maxFeatures value if you intend to export a large area.
csaybar commented 2 years ago

Hi @MatthieuStigler thank you for reporting this bug. It was solved in the last commit. Let us know if the issue persists.

MatthieuStigler commented 2 years ago

I see, the option I had in mind was rather to simply change if (maxFeatures > 5000) to if (maxFeatures != 5000), allowing the user to choose the maxFeatures herself, rather than silently setting maxFeatures back to 5000.

Bonus point: if you do it this way, the error message is hilarious!