2

I'm using the Earth Engine Python API to extract wind speeds at point locations for different days depending on the date associated with each point. I've written a script that (I thought) does this properly, by using the .map function and iterating over the feature collection.

However, when attempting to export the output feature collection (tried several options: to drive, to asset, to pandas via geemap) I always get the same error: "Parameter 'crs' is required". I don't see why a crs parameter is necessary as the input feature collection is a table that has no reference system associated with it. Passing in a crs parameter does not solve the problem.

Furthermore, when inspecting the output feature collection, I see that the data type for the wind_speed field is a feature collection (inside a feature collection?), not a float as I would expect.

Here is my code. I suspect there is something wrong with the final return line of my function, the way I'm using it with .Map, or perhaps my point_value variable is the wrong data type?

# wildfire points with date field
WF_pts = ee.FeatureCollection('users/allanbkapoor/wildfires2')

# retrieve geometry for california
ca = ee.FeatureCollection('TIGER/2018/States').filterMetadata('NAME', 'equals', 'California').geometry()

# clip GRIDMENT image to california geometry
GRIDMET = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET').filterBounds(ca)

# selects dataset to be mapped
windspeed = GRIDMET.select('vs')

# Clip to bounds of geometry
windspeed_ca = windspeed.map(lambda image: image.clip(ca))

# define function that gets pixels value for a single feature based on long/lat and date
def get_single_date_value(feat):
    #convert feat to ee.feature
    feature = ee.Feature(feat)
    
    #get data for that feature from date column
    date = ee.Date(feature.get('DISCOVERY_DT'))
    
    #for single date: filter image collection to just the image for the feature's date
    windImage = windspeed_ca.filterDate(date).mean()
    
    #get point value at the feature's location
    point = ee.Geometry.Point(feature.get('LONGITUDE'), feature.get('LATITUDE'))
    scale = 30
    point_value = windImage.sample(point, scale)
    
    #return point_value
    return feature.set({'wind_speed': point_value})

#map the function over the feature collection
WF_pts_wind = WF_pts.map(get_single_date_value)

7
  • 2
    The docs state ee.Image.sample method returns a FeatureCollection. The sample method requires a CRS, try: windImage.sample(point, scale, 'EPSG:4326').
    – user2856
    Jul 11 at 22:09
  • Thanks, I tried windImage.sample(point, scale, 'EPSG:4326') and windImage.sample(point, scale, projection='EPSG:4326') Now I can run the script without any error message but when I try to export to drive task_wind = ee.batch.Export.table.toDrive(collection=WF_pts_wind, description='Wind_test', fileFormat='CSV') it fails with a similar error message in the Task manager: "Projection: Parameter 'crs' is required" so I'm not sure if thats the issue Jul 12 at 3:26
  • 1
    You still need to extract the specific property from the sampled point using ee.FeatureCollection.get("name_of_property"). Also, I don't see why you need convert feat to ee.Feature? Jul 12 at 12:53
  • @user2856 I tried "crs" and it didn't understand that parameter. From the docs I saw the parameter name is actually "projection" and it requires a ee.projection object. I tried that and I am no longer getting that error (although the script is still not working correctly per my comment above). I'll add this as part of the solution once other issues are sorted. Jul 12 at 14:19
  • @malin-fischer good call. When I look at the properties for the feature collection I see {'type': 'FeatureCollection', 'columns': {'vs': 'Float'}, 'properties': {'band_order': ['vs']}, 'features': []} - how do I access the properties for ? I want the value from 'vs' and tried val = point_value.get("vs") but this is returning "None" when tested for a single point. Jul 12 at 14:39
1

To fix the error mentioned in the question title, I modified the code to refer to a ee.projection object:

#get point value at the feature's location
coordinates = [feat.get('LATITUDE'),feat.get('LONGITUDE')]
projection_obj = ee.Projection('EPSG:4326')
point = ee.Geometry.Point(coords=coordinates, proj=projection_obj)

While this addressed the projection error issue, it does not address the output data type issue, which is seperate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.