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.sequence(2017, 2024);
- var cloudMax = 10;
- var threshold = 0.0;
- var scale = 10;
- var simplTolerance = 20; // en metros
- var minArea = 1000; // m²
- // ===================== 3. FUNCIÓN DE PROCESAMIENTO POR AÑO ======================
- var extraerLineaAnual = function(anio) {
- anio = ee.Number(anio);
- var inicio = ee.Date.fromYMD(anio, 1, 1);
- var fin = inicio.advance(1, 'year');
- var s2 = ee.ImageCollection("COPERNICUS/S2_SR")
- .filterBounds(aoi)
- .filterDate(inicio, fin)
- .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', cloudMax))
- .map(function(img) {
- var ndwi = img.normalizedDifference(['B3', 'B8']).rename('NDWI');
- return img.addBands(ndwi).copyProperties(img, ['system:time_start']);
- });
- var ndwiCollection = s2.select('NDWI');
- var conteo = ndwiCollection.size();
- return ee.Algorithms.If(
- conteo.gt(0),
- (function() {
- var ndwiMedian = ndwiCollection.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': 'Sentinel2'
- });
- });
- return linea;
- })(),
- ee.FeatureCollection([])
- );
- };
- // ===================== 4. APLICAR A CADA AÑO ======================
- var coleccionAnual = anios.map(function(a) {
- return extraerLineaAnual(a);
- });
- var lineasFinal = ee.FeatureCollection(coleccionAnual).flatten();
- // ===================== 5. VISUALIZACIÓN ======================
- Map.centerObject(aoi, 13);
- Map.addLayer(lineasFinal, {color: 'blue'}, 'Líneas de costa por año');
- // ===================== 6. EXPORTACIÓN ======================
- Export.table.toDrive({
- collection: lineasFinal,
- description: 'LineasCosta_SolisChico_2017_2024',
- fileFormat: 'GeoJSON'
- });
Advertisement
Add Comment
Please, Sign In to add comment