-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathExample_Code.txt
72 lines (57 loc) · 1.73 KB
/
Example_Code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//upload CSV as a fusion table
//declare it as a variable
var points = ee.FeatureCollection("ft:197TBk5hVl_MrOdL8R_x53otnJnRzrmWNwv-NPIRY");
// Zoom to a location.
Map.centerObject(points, 10);
//Visualize points on map
Map.addLayer(points, {}, 'samples');
print(points);
//Pick a data source - Landsat 8 7 5
var l8 = ee.ImageCollection('LANDSAT/LC8_L1T_TOA');
//Filter by date
var l8_2015 = l8.filterDate('2016-01-01', '2016-12-31');
//Filter by boundaries
//First draw a polygon
var l815s = l8_2015.filterBounds(geometry);
// This will sort from least to most cloudy.
var sorted = l815s.sort('CLOUD_COVER');
// Get the first (least cloudy) image.
var scene = ee.Image(sorted.first());
//add true color composite
var visParams = {bands: ['B4', 'B3', 'B2'], max: 0.3};
Map.addLayer(scene, visParams, 'true-color composite');
//get NDVI
var ndvi = scene.normalizedDifference(['B5', 'B4']).rename('NDVI');
//Adding NDVI to a collection as another band
var addVI = function(image) {
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI')
return image
.addBands([ndvi])
};
var collection1 = l8_2015.map(addVI);
//get min NDVI
var median = collection1.reduce(ee.Reducer.median());
//Export NDVI values to a table in drive
print(median);
Map.addLayer(median.select('NDVI_median'), {min: -0.8, max: 0.8, palette: 'black, green'},'NDVI')
var medianV = median.reduceRegions({
reducer: ee.Reducer.median(),
collection: points,
scale: 30,
});
Export.table.toDrive({
collection: medianV,
fileNamePrefix: 'xx',
folder: 'xx',
description: 'xx',
fileFormat: 'CSV'
});
Export.image.toDrive({
image: median,
description: 'xx',
folder: 'xx',
fileNamePrefix: 'xx',
'maxPixels': 1e13,
scale: 30,
region: geometry
});