Geographic Information Systems Asked by JMilner on July 31, 2021
I am trying to generate time series for a set of points in earth engine. I am attempting this for multiple datasets, but for now let’s do NDVI with Landsat 8. My problem lies (i think) in step 6. below, as the plot is generated, but with no sign of mutiple sites…
var l8sr = ee.Image('LANDSAT/LC08/C01/T1_SR')
The method I am trying to use is as follows:
roi
. N.B. The code presented in this question runs perfectly for a single point geometry, but not for multipointvar roi = ee.Geometry.MultiPoint([[146.007413888888,-17.6536194444444],
[146.061191666666,-17.4442805555555],
[145.960902777777,-17.7890055555555],
[151.937444444444,-24.3380305555555],
[150.468130555555,-23.1586194444444],
[148.506963888888,-21.088375],
[148.591619444444,-21.3626416666666],
[148.186125,-24.9189222222222]])
var timeField = 'system:time_start'
4.a Function to mask cloud using the pixel_qa (quality assurance) band of L8SR data. This is from the code editor example on cloud masking
function maskL8sr(image) {
var cloudShadowBitMask = 1 << 3
var cloudsBitMask = 1 << 5
var qa = image.select('pixel_qa')
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0))
return image.updateMask(mask).divide(10000)
.select('B[0-9]*')
.copyProperties(image,['system:time_start'])
}
4.b Create NDVI, time, and constant variables in data
var addVariables = function(image) {
var date = ee.Date(image.get(timeField))
var years = date.difference(ee.Date('1970-01-01'),'year')
return image
.addBands(image.normalizedDifference(['B5','B4']).rename('NDVI'))
.addBands(ee.Image(years).rename('t'))
.float()
.addBands(ee.Image.constant(1))
}
roi
var filteredLandsat = l8sr
.filterBounds(roi)
.map(maskL8sr)
.map(addVariables)
//Plot a time series of NDVI at a single location
var l8Chart = ui.Chart.image.seriesByRegion(filteredLandsat,
roi,
ee.Reducer.mean(),
'NDVI')
.setChartType('ScatterChart')
.setOptions({
title: 'Landsat 8 NDVI time series at ROI',
vAxis: {title: 'NDVI'},
lineWidth: 1,
pointSize: 4,
series: {
0: {color: '#FF0000'}, // Warrubellen
1: {color: '#FFFF00'}, // Ella Bay
2: {color: '#00FF00'}, // Nyleta Creek
3: {color: '#008000'}, // Deep Water
4: {color: '#00FFFF'}, // Mt Etna Quarry
5: {color: '#0000FF'}, // Eungella 1
6: {color: '#FF00FF'}, // Eungella 2
7: {color: '#800080'} // Carnavon
}
})
print(l8Chart)
Since posting this, (and with a helpful comment from @Sean Roulet) it seems the "correct" way to do this is to replace the ee.Geometry.MultiPoint()
with a ee.FeatureCollection()
containing several ee.Geometry.Point()
as follows:
var roi_list = [ee.Feature(ee.Geometry.Point(146.007413888888,-17.6536194444444), {name: 'Warrubellen'}),
ee.Feature(ee.Geometry.Point(146.061191666666,-17.4442805555555), {name: 'Ella Bay'}),
ee.Feature(ee.Geometry.Point(145.960902777777,-17.7890055555555), {name: 'Nyleta Creek'}),
ee.Feature(ee.Geometry.Point(151.937444444444,-24.3380305555555), {name: 'Deep Water'}),
ee.Feature(ee.Geometry.Point(150.468130555555,-23.1586194444444), {name: 'Mt Etna Quarry'}),
ee.Feature(ee.Geometry.Point(148.506963888888,-21.088375), {name: 'Eungella 1'}),
ee.Feature(ee.Geometry.Point(148.591619444444,-21.3626416666666), {name: 'Eungella 2'}),
ee.Feature(ee.Geometry.Point(148.186125,-24.9189222222222), {name: 'Carnavon'})]
var roi = ee.FeatureCollection(roi_list);
So now, the question presented here is more based on whether it is possible to do what I have done below, without using a FeatureCollection()
, and instead just using ee.Geometry.MultiPoint()
, or if not, why google earth engine is unable to do this...?
Correct answer by JMilner on July 31, 2021
I agree with the OP that it's weird that it's not easy to convert an ee.Geometry.MultiPoint
to an FeatureCollection
. One workaround is to extract the coordinates as a list and then map through the list rebuilding points wrapped in features.
So if you have a Multipoint in mypoints
you can get them as a FeatureCollection myfeats
like this:
var myfeats = ee.FeatureCollection(mypoints.coordinates().map(function(x) {return ee.Feature(ee.Geometry.Point(x))}))
Answered by gabrahao on July 31, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP