r-spatial / rgee

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

Error: Invalid GeoJSON geometry when filtering an ImageCollection by a multipolygon #171

Closed Sebastianmarzini closed 3 years ago

Sebastianmarzini commented 3 years ago

At submit an issue, please attached the following information of your rgee session:

library(rgee)

# Initialize the Earth Engine module.
ee_Initialize()

# Print metadata for a DEM dataset.
print(ee$Image('USGS/SRTMGL1_003')$getInfo())

Attach your Python (reticulate) configuration:

library(reticulate)
py_config()
python:         C:/Users/seba_/AppData/Local/r-miniconda/envs/rgee/python.exe
libpython:      C:/Users/seba_/AppData/Local/r-miniconda/envs/rgee/python39.dll
pythonhome:     C:/Users/seba_/AppData/Local/r-miniconda/envs/rgee
version:        3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:37:25) [MSC v.1916 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/Users/seba_/AppData/Local/r-miniconda/envs/rgee/Lib/site-packages/numpy
numpy_version:  1.21.0
ee:             C:\Users\seba_\AppData\Local\R-MINI~1\envs\rgee\lib\site-packages\ee\__init__.p

NOTE: Python version was forced by RETICULATE_PYTHON

Description

I'm new in using R and GEE and I have an issue that I think is very simple to resolve but I can't get it. I'm trying to filter a S1 ImageCollection using a shp that contains different polygons (more or less 60) In the shp, each row represent a different polygon and in the geometry column, the cell contains a list of vector of coordinates: list(c(11.3994273650556, 11.3997751322478, 11.398.... On GEE I don't get problem with these shapefiles.

What I Did

When I run the script it gives me an error related to the geometry (I think)

roi <-  st_read("C:/Users/seba_/OneDrive/StudioFenologia_Dati/GIS/Toscana/Repliche_Toscana.shp", quiet = TRUE)

fS1 <- ee$ImageCollection("COPERNICUS/S1_GRD")$
  filter(ee$Filter$listContains('transmitterReceiverPolarisation', 'VH'))$
  filter(ee$Filter$eq('instrumentMode', 'IW'))$
  filterDate("2015-01-01","2020-12-31")$
  #filterBounds(ee$features)
  filterBounds(roi)

> roi <- st_read("C:/Users/seba_/OneDrive/StudioFenologia_Dati/GIS/Toscana/Repliche_Toscana.shp", quiet = TRUE)
> 
> fS1 <- ee$ImageCollection("COPERNICUS/S1_GRD")$
+   filter(ee$Filter$listContains('transmitterReceiverPolarisation', 'VH'))$
+   filter(ee$Filter$eq('instrumentMode', 'IW'))$
+   filterDate("2015-01-01","2020-12-31")$
+   #filterBounds(ee$features)
+   filterBounds(roi)
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  EEException: Invalid GeoJSON geometry. 
#followed by a long detailed traceback:
Detailed traceback:
  File "C:\Users\seba_\AppData\Local\R-MINI~1\envs\rgee\lib\site-packages\ee\collection.py", line 94, in filterBounds
    return self.filter(filter.Filter.geometry(geometry))
  File "C:\Users\seba_\AppData\Local\R-MINI~1\envs\rgee\lib\site-packages\ee\filter.py", line 281, in geometry
    'rightValue': apifunction.ApiFunction.call_('Feature', geometry)
  File "C:\Users\seba_\AppData\Local\R-MINI~1\envs\rgee\lib\site-packages\ee\apifunction.py", line 81, in call_
    return cls.lookup(name).call(*args, **kwargs)
  File "C:\Users\seba_\AppData\Local\R-MINI~1\envs\rgee\lib\site-packages\ee\function.py", line 67, in call
    return self.apply(self.nameArgs(args, kwargs))
  File "C:\Users\seba_\AppData\Local\R-MINI~1\envs\rgee\lib\site-packages\ee\function.py", line 80, in apply
    result = computedobject.ComputedObject(self, self.promoteArgs(named_args))
  File "C:\Users\seba_\AppData\Local\R-MINI~1\envs\rgee\lib\site-p
csaybar commented 3 years ago

Something like this should work.

roi <-  st_read("C:/Users/seba_/OneDrive/StudioFenologia_Dati/GIS/Toscana/Repliche_Toscana.shp", quiet = TRUE)
ee_roi  <- roi %>% sf_as_ee()
fS1 <- ee$ImageCollection("COPERNICUS/S1_GRD")$
  filter(ee$Filter$listContains('transmitterReceiverPolarisation', 'VH'))$
  filter(ee$Filter$eq('instrumentMode', 'IW'))$
  filterDate("2015-01-01","2020-12-31")$
  #filterBounds(ee$features)
  filterBounds(ee_roi$geometry())
Sebastianmarzini commented 3 years ago

Thank you a lot! It works now!!