I am new to stack overflow and javascript, so apologies in advance.
The overall aim: calculate the NDVI change over time (inter- and intra-annual) at 8 sites using the landsat 8 image collection. Rather than do calculations on each one separately, I want to group the sites together and then do the NDVI calculation on all the sites at once (but get results for each site separately).
Initial aim: filter for individual sites. So, before doing the NDVI calcs, I need to first filter and reduce the landsat 8 image collection (to remove cloud, get the right dates, etc), including using .filterBounds()
to filter spatially by site, as in the code below. When I run the code, only one image from the last site (site 5D) listed appears in the map window, and there are no error messages in the console.
//import the image collection
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_RT');
//define a list of geometry points with co-ordinates as the 8 distinct sites
var siteList = [
ee.Feature(/* color: #166f12 */ee.Geometry.Point (135.78877, -15.146215), {name: 'site1A'}),
ee.Feature(/* color: #1f921a */ee.Geometry.Point (135.836993, -15.171145), {name: 'site1B'}),
ee.Feature(/* color: #1c73d5 */ee.Geometry.Point (136.434148, -15.647369), {name: 'site2A'}),
ee.Feature(/* color: #144882 */ee.Geometry.Point (136.441971, -15.650919), {name: 'site2B'}),
ee.Feature(/* color: #de2626 */ee.Geometry.Point (140.853576, -17.422561), {name: 'site4A'}),
ee.Feature(/* color: #911919 */ee.Geometry.Point (140.89625, -17.340024), {name: 'site4B'}),
ee.Feature(/* color: #23cf7b */ee.Geometry.Point (141.665424, -15.027324), {name: 'site5A'}),
ee.Feature(/* color: #228c58 */ee.Geometry.Point (141.660919, -14.996538), {name: 'site5D'})
];
// Create a FeatureCollection from the list and print it.
var sites = ee.FeatureCollection(siteList);
print(sites);
//Define the image
var image = ee.Image(l8
.filterDate("2014-07-01", "2016-09-30")
.filterBounds(sites)
.sort("CLOUD_COVER")
.first());
print("Landsat 8:", image);
var vis = {min: 0, max: 14000, bands:['B5', 'B4', 'B3']};
Map.addLayer(image, vis,'Sites test');
The question: As the script shows, and following the GEE tutorials and other SO answers, I have defined the sites as point geometries, put them in a list, then defined a ee.FeatureCollection()
as the list of sites. But something is obviously incorrect. How do I change the script to make it work?
I considered a possible workaround being filtering the image collection by WRS_PATH
and WRS_ROW
to get the images taken nearest the sites. Then define 'roi's' as polygon geometries and do the NDVI calcs within the polygons (I guess clip()
image to polygon.
Hope that's enough info.