I want to join two featureCollections and remove the ID field in order to run linearRegression in GEE. I found codes to clean the featureCollection after innerJoin, and snippet to remove properties from FC. However, when I try on my own data, all the properties from FC were removed!
// Create the primary collection.
var primaryFeatures = ee.FeatureCollection([
ee.Feature(null, {foo: 0, label: 'a'}),
ee.Feature(null, {foo: 1, label: 'b'}),
ee.Feature(null, {foo: 1, label: 'c'}),
ee.Feature(null, {foo: 2, label: 'd'}),
]);
print('primary fc',primaryFeatures);
// Create the secondary collection.
var secondaryFeatures = ee.FeatureCollection([
ee.Feature(null, {bar: 1, label: 'e'}),
ee.Feature(null, {bar: 1, label: 'f'}),
ee.Feature(null, {bar: 2, label: 'g'}),
ee.Feature(null, {bar: 3, label: 'h'}),
]);
print('2nd fc',secondaryFeatures);
// Use an equals filter to specify how the collections match.
var toyFilter = ee.Filter.equals({
leftField: 'foo',
rightField: 'bar'
});
// Define the join.
var innerJoin = ee.Join.inner('primary', 'secondary');
// Apply the join.
var toyJoin = innerJoin.apply(primaryFeatures, secondaryFeatures, toyFilter);
// Print the result.
print('Inner join toy example:', toyJoin);
// I tried
// clean the join
// this snippet is from stackexchange
function cleanJoin(feature){
return ee.Feature(feature.get('primary')).copyProperties(feature.get('secondary'));
}
var Joined = toyJoin.map(cleanJoin);
print('joined',Joined)
// remove one properties
// this snippet is also from https://gis.stackexchange.com/questions/321724/removing-property-from-feature-or-featurecollection-using-google-earth-engine
var removeProperty = function(feat, property) {
var properties = feat.propertyNames()
print(properties);
var selectProperties = properties.filter(ee.Filter.neq('item', property))
return feat.select(selectProperties)
}
var removeJoined = removeProperty(Joined,'foo');
print('remove joined',removeJoined) // all properties were removed!!
