Google Earth Engine Python API – Collecting Pixel Level Values from FeatureCollection

google-earth-enginegoogle-earth-engine-python-api

I would like to collect pixel level value of country from the featureCollection "USDOS/LSIB_SIMPLE/2017". I use reduceToImage function to reduce featureCollection to ImageCollection and use getRegion to get pixel value of country.

# Get country boundary
country = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017")
country_img = country.reduceToImage(['abbreviati'], ee.Reducer.first())

# Define geographic domain
world_geometry = ee.Geometry.Polygon([
        -180, 90,
        0, 90, 
        180, 90, 
        180, -90, 
        0, -90,
        -180, -90], None, False) 
#Get pixel values
img_get_region = ee.ImageCollection(country_img).getRegion(world_geometry, scale = 30000).getInfo()
# Convert to dataframe 
img_get_region_df = pd.DataFrame(img_get_region[1:len(img_get_region)], columns = img_get_region[0]).drop(['id', 'time'], axis = 1)

However, I get the error "EEException: Collection.reduceToImage: Property 'abbreviati' not a numeric type." It seems that reduceToImage only accepts numeric features. So how can I collect string feature in this function?

Best Answer

In Earth Engine, image pixel values can be numbers, or arrays of numbers. They cannot be strings.

You will have to add a numeric ID property of some sort, and convert that to strings after the getRegion().

Related Question