gaitapi

script GEE Lineas de Costa Sentinal 2018 a 2024 ej Solis Chico

Jul 27th, 2025 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. // ===================== 1. ÁREA DE INTERÉS ======================
  2. var centro = ee.Geometry.Point([-55.70237, -34.78015]);
  3. var radio_m = 2000;
  4. var aoi = centro.buffer(radio_m);
  5.  
  6. // ===================== 2. PARÁMETROS ======================
  7. var anios = ee.List.sequence(2017, 2024);
  8. var cloudMax = 10;
  9. var threshold = 0.0;
  10. var scale = 10;
  11. var simplTolerance = 20; // en metros
  12. var minArea = 1000; // m²
  13.  
  14. // ===================== 3. FUNCIÓN DE PROCESAMIENTO POR AÑO ======================
  15. var extraerLineaAnual = function(anio) {
  16. anio = ee.Number(anio);
  17. var inicio = ee.Date.fromYMD(anio, 1, 1);
  18. var fin = inicio.advance(1, 'year');
  19.  
  20. var s2 = ee.ImageCollection("COPERNICUS/S2_SR")
  21. .filterBounds(aoi)
  22. .filterDate(inicio, fin)
  23. .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', cloudMax))
  24. .map(function(img) {
  25. var ndwi = img.normalizedDifference(['B3', 'B8']).rename('NDWI');
  26. return img.addBands(ndwi).copyProperties(img, ['system:time_start']);
  27. });
  28.  
  29. var ndwiCollection = s2.select('NDWI');
  30. var conteo = ndwiCollection.size();
  31.  
  32. return ee.Algorithms.If(
  33. conteo.gt(0),
  34. (function() {
  35. var ndwiMedian = ndwiCollection.median().clip(aoi);
  36. var waterMask = ndwiMedian.gt(threshold);
  37.  
  38. var polygons = waterMask.reduceToVectors({
  39. geometry: aoi,
  40. geometryType: 'polygon',
  41. scale: scale,
  42. maxPixels: 1e12,
  43. eightConnected: false
  44. });
  45.  
  46. var filtrado = polygons.map(function(f) {
  47. var area = f.geometry().area(1);
  48. return f.set('area_m2', area);
  49. }).filter(ee.Filter.gt('area_m2', minArea));
  50.  
  51. var linea = filtrado.map(function(f) {
  52. var linea = f.geometry().simplify(simplTolerance);
  53. return ee.Feature(linea, {
  54. 'anio': anio,
  55. 'area_m2': f.get('area_m2'),
  56. 'fuente': 'Sentinel2'
  57. });
  58. });
  59.  
  60. return linea;
  61. })(),
  62. ee.FeatureCollection([])
  63. );
  64. };
  65.  
  66. // ===================== 4. APLICAR A CADA AÑO ======================
  67. var coleccionAnual = anios.map(function(a) {
  68. return extraerLineaAnual(a);
  69. });
  70. var lineasFinal = ee.FeatureCollection(coleccionAnual).flatten();
  71.  
  72. // ===================== 5. VISUALIZACIÓN ======================
  73. Map.centerObject(aoi, 13);
  74. Map.addLayer(lineasFinal, {color: 'blue'}, 'Líneas de costa por año');
  75.  
  76. // ===================== 6. EXPORTACIÓN ======================
  77. Export.table.toDrive({
  78. collection: lineasFinal,
  79. description: 'LineasCosta_SolisChico_2017_2024',
  80. fileFormat: 'GeoJSON'
  81. });
  82.  
Advertisement
Add Comment
Please, Sign In to add comment