0

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.

jerry_88
  • 1
  • 1

1 Answers1

0

You're only seeing one image because you only select one image using the first function.

There is a lot you need to do here, but here are some goalposts:

  1. Create an NDVI composite for each image in the image collection using map and a custom function.
  2. Mosaic the composites for a single date within the image collection (will be a little tricky, you'll probably have to define and iterate over the specific image dates).
  3. Create an image from the composites-by-date by using e.g. iterate and addBands. (You'll have to store the date in the image name somehow so you know which date each band refers to in the final product).
  4. Use reduceRegions on the feature collection and the multiband image you created to get values for each point for each image band.
Jesse Anderson
  • 4,507
  • 26
  • 36