Reputation: 3
I have two feature collections one containing point data with measurements and the other polygons marking the different clusters where several measurements were taken close together. In Google earth engine I am trying to create a new (point) feature collection (or edit the polygon features) which contain the average measured values for every seperate cluster.
I used the following code to join the two different feature collections (so that the polygons also contain the point data):
var mean = ee.Filter.intersects({
leftField: '.geo',
rightField: '.geo'
})
var saveAllJoin = ee.Join.saveAll({
matchesKey: 'Measurements',
})
var intersect = saveAllJoin.apply(Clusters, Measurements, mean)
However, since multiple measurements are taken within one cluster this results in a featurecollection that contains a list with the measurement points located within a specific cluster. Instead I am looking for the average measured values as a property of the polygons. What is the way to do this in Google earth engine (or possibly in QGIS)?
I have tried using ee.FeatureCollection.map
in order to calculate the mean value at every individual polygon:
var clust = ee.FeatureCollection(Clusters).map(function(feature) {
var meanClay = Measurements.reduceColumns({
reducer: ee.Reducer.mean(),
selectors: ['Clay']
})
return feature.set('mean', meanClay)
})
Now if I print the variable "clust" I get a featurecollection with mean values for the (measured) attribute clay. However, every feature gets the same value (the mean of all the measured points instead of just those within a specific cluster).
For clarity: I got a shapefile with 78 measurement locations (points) which are loaded into my script as a featurecollection and contain the measured values. Besides this I also have a shapefile with polygons indicating 16 areas where a cluster of measurements were performed (so around 4-5 measurements in each cluster). Now I am trying to get the average of all the measurements (points) within each polygon (cluster) for every individual polygon.
Upvotes: 0
Views: 1368
Reputation: 3
I solved it by using filterBounds()
on the point data. Here the filterBounds is used to filter the point data to only consist of the points within a specific cluster.
var clust = ee.FeatureCollection(Clusters).map(function(feature) {
var meanClay = ee.FeatureCollection(Measurements.filterBounds(feature.geometry()))
.reduceColumns({
reducer: ee.Reducer.mean(),
selectors: ['Clay']
})
return feature.set(meanClay)
})
Upvotes: 0