-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sentinel-2-PRD
40 lines (28 loc) · 1.95 KB
/
Sentinel-2-PRD
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
// first draw an aoi using the tools in the map window
// Now select your image type!
//112.7-114.7, 21.7-23.7, ab,12
//var geometry = ee.Geometry.Rectangle(113.7, 22.7, 114.7, 23.7); PRD
//var geometry = ee.Geometry.Rectangle(-4.5,48.2,-3.9,48.5);
var geometry = ee.Geometry.Rectangle(-119.0, 33.48, -117.2, 34.58); // Los Angeles
var geometry = ee.Geometry.Rectangle(-119.2, 33.40, -117.2, 35.05); // Greater LA
var collection = ee.ImageCollection('COPERNICUS/S2') // searches all sentinel 2 imagery pixels...
.filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 10)) // ...filters on the metadata for pixels less than 10% cloud
.filterDate('2018-01-01' ,'2019-12-31') //... chooses only pixels between the dates you define here
.filterBounds(geometry) // ... that are within your aoi
print(collection) // this generates a JSON list of the images (and their metadata) which the filters found in the right-hand window.
/// so far this is finding all the images in the collection which meets the critera- the latest on top. To get a nice blended-looking mosaic,
// try some of the tools for 'reducing' these to one pixel (or bands of pixels in a layer stack).
var medianpixels = collection.median() // This finds the median value of all the pixels which meet the criteria.
var medianpixelsclipped = medianpixels.clip(geometry).toInt() // this cuts up the result so that it fits neatly into your aoi
// and divides so that values between 0 and 1
// Now visualise the mosaic as a natural colour image.
Map.addLayer(medianpixelsclipped, {bands: ['B8', 'B4', 'B3'], min: 0, max: 10000, gamma: 1.5}, 'Sentinel_2 mosaic')
// export it to your googledrive as a tiff for use in QGIS
// Export the image, specifying scale and region.
Export.image.toDrive({
image: medianpixelsclipped.select("B2","B3","B4","B8","B11","B12"),
description: 'Sentinel-2_1',
scale: 10,
maxPixels: 1e13,
region: geometry
});