Background:
I have an ee.FeatureCollection of Point objects and I'm trying to map() over them to get raster values from one or more ee.ImageCollections. I haven't had problems getting topographical values for my thousands of points, but I'm getting errors when collecting other attributes:
First example:
def get_airTemp(feat):
date = ee.Date(feat.get('fireDate'))
imgCol = ee.ImageCollection('ECMWF/ERA5_LAND/DAILY_AGGR') \
.filterDate(date) \
.select("temperature_2m")
img = imgCol.mean()
airTemp = img.sample(feat.geometry(),scale=10).first().get('temperature_2m')
return feat.set({'airTemp':airTemp})
featCol = geemap.geopandas_to_ee(gdf)
airTempCol = featCol.map(get_airTemp)
gdf = geemap.ee_to_geopandas(airTempCol)
Exception: Error in map(ID=157):
Element.get: Parameter 'object' is required.
When I inspect the Feature with ID=7, I find:
id:157
type:Point
coordinates: [-118.10600753, 33.73946364]
Punching the coordinates into Google Maps reveals a point in Seal Beach about 100 meters away from the coast. I don't really have any understanding of how the ERA5 land reanalysis is put together, but it makes intuitive sense that I might have an issue with air temperature immediately next to the coastline. This also happened with another point right next to the coastline in a different city.
Second example:
def get_ndvi(feat):
f_date = ee.Date(feat.get('fireDate'))
i_date = f_date.advance(-1,'year')
imgCol = ee.ImageCollection("MODIS/MOD09GA_006_NDVI") \
.filterDate(i_date,f_date)
img = imgCol.mean()
ndvi = img.sample(feat.geometry(),scale=10).first().get('NDVI')
return feat.set({'NDVI':ndvi})
featCol = geemap.geopandas_to_ee(gdf)
ndviCol = featCol.map(get_ndvi)
gdf_results = geemap.ee_to_geopandas(ndviCol)
Exception: Error in map(ID=7):
Element.get: Parameter 'object' is required.
When I inspect the Feature with ID=7, I find:
id:7
type:Point
coordinates: \[-119.7843, 37.6769\]
Punching the coordinates into Google Maps reveals a point just outside Yosemite Valley, 300 meters north of the Merced River. No idea why this is an issue.
What I've tried:
I'm fine with dropping these points from the dataset as they come up, but I haven't been able to figure out how. I tried setting the map() argument opt_dropNulls to True, but the same error pops up. I also tried to use ee.Algorithms.If() but I played around and can't seem to figure out a conditional to return null, because it seems the server can't or won't even begin to start .get() without an object.