Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ===================== 1. ÁREA DE INTERÉS ======================
- var centro = ee.Geometry.Point([-55.70237, -34.78015]);
- var radio_m = 2000;
- var aoi = centro.buffer(radio_m);
- // ===================== 2. PARÁMETROS ======================
- var anios = ee.List([2013, 2014, 2015, 2017]);
- var cloudMax = 30;
- var threshold = 0.0;
- var scale = 30;
- var simplTolerance = 30;
- var minArea = 1000; // m²
- // ===================== 3. FUNCIÓN PARA OBTENER COLECCIÓN POR AÑO ======================
- function getLandsatCollection(anio) {
- anio = ee.Number(anio);
- var fechaInicio = ee.Date.fromYMD(anio, 1, 1);
- var fechaFin = fechaInicio.advance(1, 'year');
- var col;
- if (anio.eq(2017)) {
- col = ee.ImageCollection('LANDSAT/LE07/C02/T1_L2')
- .filterDate(fechaInicio, fechaFin)
- .map(function(img) {
- var toa = img.multiply(0.0000275).add(-0.2);
- var ndwi = toa.normalizedDifference(['SR_B2', 'SR_B4']).rename('NDWI');
- return img.addBands(ndwi).copyProperties(img, ['system:time_start']);
- });
- } else {
- col = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
- .filterDate(fechaInicio, fechaFin)
- .map(function(img) {
- var toa = img.multiply(0.0000275).add(-0.2);
- var ndwi = toa.normalizedDifference(['SR_B3', 'SR_B5']).rename('NDWI');
- return img.addBands(ndwi).copyProperties(img, ['system:time_start']);
- });
- }
- return col.filterBounds(aoi)
- .filter(ee.Filter.lt('CLOUD_COVER', cloudMax));
- }
- // ===================== 4. FUNCIÓN DE PROCESAMIENTO POR AÑO ======================
- var extraerLineaAnual = function(anio) {
- anio = ee.Number(anio);
- var coleccion = getLandsatCollection(anio);
- var conteo = coleccion.size();
- return ee.Algorithms.If(
- conteo.gt(0),
- (function() {
- var ndwiMedian = coleccion.select('NDWI').median().clip(aoi);
- var waterMask = ndwiMedian.gt(threshold);
- var polygons = waterMask.reduceToVectors({
- geometry: aoi,
- geometryType: 'polygon',
- scale: scale,
- maxPixels: 1e12,
- eightConnected: false
- });
- var filtrado = polygons.map(function(f) {
- var area = f.geometry().area(1);
- return f.set('area_m2', area);
- }).filter(ee.Filter.gt('area_m2', minArea));
- var linea = filtrado.map(function(f) {
- var linea = f.geometry().simplify(simplTolerance);
- return ee.Feature(linea, {
- 'anio': anio,
- 'area_m2': f.get('area_m2'),
- 'fuente': ee.Algorithms.If(anio.eq(2017), 'Landsat7', 'Landsat8')
- });
- });
- return linea;
- })(),
- ee.FeatureCollection([])
- );
- };
- // ===================== 5. APLICAR Y EXPORTAR ======================
- var coleccionAnual = anios.map(function(a) {
- return extraerLineaAnual(a);
- });
- var lineasFinal = ee.FeatureCollection(coleccionAnual).flatten();
- Map.centerObject(aoi, 13);
- Map.addLayer(lineasFinal, {color: 'green'}, 'Línea de costa 2013–2015 y 2017');
- Export.table.toDrive({
- collection: lineasFinal,
- description: 'LineasCosta_SolisChico_Landsat8_7_2013_2017',
- fileFormat: 'GeoJSON'
- });
Advertisement
Add Comment
Please, Sign In to add comment