|
| 1 | +// Example script showing how to visualize |
| 2 | +// all the bands of an image |
| 3 | +// 1. Filmstrip: Create a tiled image with all the bands |
| 4 | +// 2. Animation: Create a video with a frame for each band |
| 5 | + |
| 6 | +var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED'); |
| 7 | +var geometry = ee.Geometry.Polygon([[ |
| 8 | + [77.57018, 12.96010], |
| 9 | + [77.57018, 12.93953], |
| 10 | + [77.59988, 12.93953], |
| 11 | + [77.59988, 12.96010]] |
| 12 | +]); |
| 13 | + |
| 14 | +var filteredS2 = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30)) |
| 15 | + .filter(ee.Filter.date('2019-01-01', '2020-01-01')) |
| 16 | + .filter(ee.Filter.bounds(geometry)); |
| 17 | + |
| 18 | +// Sort the collection and pick the least cloudy image |
| 19 | +var filteredS2Sorted = filteredS2.sort('CLOUDY_PIXEL_PERCENTAGE'); |
| 20 | +var image = filteredS2Sorted.first(); |
| 21 | + |
| 22 | +// Convert the multi-band image to an ImageCollection |
| 23 | +var bands = image.select('B.*').bandNames(); |
| 24 | + |
| 25 | +// Remove the 'Cirrus' band |
| 26 | +var bandsToUse = bands.remove('B10'); |
| 27 | + |
| 28 | +// Tip: change the bandsToUse variable to a smaller list |
| 29 | +// such as ['B1', 'B2', 'B3', 'B4] to create shorter |
| 30 | +// filmstrips and repeat for other bands |
| 31 | + |
| 32 | +// map() a function on the list of bands |
| 33 | +var bandCol = ee.ImageCollection(bandsToUse.map(function(band) { |
| 34 | + // All images in a collection are expected to have the same bands |
| 35 | + // Set the name of hte bands to 'band' |
| 36 | + var bandImage = image.select([band]).rename('band'); |
| 37 | + // Set the image ID to the actual name of the band. i.e. B1, B2 etc. |
| 38 | + return bandImage.set('system:index', band); |
| 39 | +})); |
| 40 | + |
| 41 | +// Define arguments for the getFilmstripThumbURL function parameters. |
| 42 | +var filmArgs = { |
| 43 | + dimensions: 800, |
| 44 | + region: geometry, |
| 45 | + crs: 'EPSG:3857', |
| 46 | + min: 500, |
| 47 | + max: 2700, |
| 48 | + palette: ['black', 'white'] |
| 49 | +}; |
| 50 | + |
| 51 | +// Print a URL that will produce the filmstrip when accessed. |
| 52 | +print('Film Strip (click to view)', bandCol.getFilmstripThumbURL(filmArgs)); |
| 53 | + |
| 54 | +// Create an Animation |
| 55 | +var videoArgs = { |
| 56 | + dimensions: 800, |
| 57 | + region: geometry, |
| 58 | + crs: 'EPSG:3857', |
| 59 | + framesPerSeconds: 1, |
| 60 | + min: 500, |
| 61 | + max: 2700, |
| 62 | + palette: ['black', 'white'] |
| 63 | +}; |
| 64 | + |
| 65 | +print('Animation (click to view)', bandCol.getVideoThumbURL(videoArgs)); |
| 66 | + |
| 67 | +var rgbVis = {min: 0.0, max: 3000, bands: ['B4', 'B3', 'B2']}; |
| 68 | + |
| 69 | +Map.centerObject(geometry, 10); |
| 70 | +Map.addLayer(image, rgbVis, 'Image'); |
| 71 | + |
0 commit comments