[GIS] Extracting only some properties of each feature from a feature collection and creating a new a feature collection from them using Google Earth Engine

extractgoogle-earth-engine

I have a feature collection but I need to make a new feature collection from it by taking only some columns , I am new to google earth engine and am unable to do so ,the code is

NDVI=NDVI.map(function(
    f=ee.Feature(f)
    return ee.Feature(f.toDictionary(dates).values(dates))
 })
print(NDVI)

here NDVI is the main feature collection and
dates is a list of properties that I want to extract per feature, the error I am getting is

FeatureCollection (Error)
Collection.map: A mapped algorithm must return a Feature or Image.

Best Answer

I think this should work:

var dates = ee.List(["property1", "property2"]);

var new_NDVI=NDVI.map(function(f){
    f = ee.Feature(f);
    return ee.Feature(null, f.toDictionary(dates));
 });

First of all, you have some syntax errors in your example code. You need to give the inputs of the function, here that is "(f)", after the "function" statement. Then you also forgot the curly opening bracket "{".

The documentation for "ee.Feature" says you need to give a geometry first, and then a dictionary with properties for the respective feature. In this case we say the geometry is non-existant, i.e. "null". The dictionary is create by calling the "toDictionary" method on the input feature "f". Dates needs to be a list of property names that exist in the features of the NDVI feature-collection.

Also note that there is no need to call the ".values(dates)" method, because that will turn the dictionary into a list.