# Apéndice G: Ejemplo de cálculo y código de Google Earth Engine

El código de código abierto para los cálculos de créditos de biodiversidad está disponible para el público en el repositorio de [GitHub de Savimbo](https://github.com/savimbo).&#x20;

Nuestra intención es hacer este código más fácil de usar y disponible para proyectos IP y LC mediante una interfaz que pueda auto-registrar los créditos desde y hacia una base de datos gratuita de Airtable, una vez que comencemos con la certificación de biodiversidad en 2024. El [registro](https://airtable.com/invite/r/fxsn6mcE) gratuito en Airtable ya está disponible. Los proyectos IP pueden inscribirse en la lista de espera de esta interfaz ahora y obtener plantillas de bases de datos de Airtable enviando un correo electrónico a <ops@savimbo.com>.

Los cálculos de demostración también están disponibles en Google Earth Engine, que se ha comprometido a proporcionar cuentas gratuitas a los grupos indígenas involucrados en el cambio climático. El [registro ](https://earthengine.google.com/noncommercial/)no comercial está disponible.

***Figura 11*****. Ejemplo de codigo en GEE**

<figure><img src="https://lh6.googleusercontent.com/rVQ0Wv_v9_eXa7qOghqAvJhwResowct17qRiUSD-lO_eatzZqyiNhfpKmprKNcRWdVXXkv2FuYyAetkdA1BzOcf6d7EWeGqmRpKVVMGmk89gLOQd8i1K-Ia4A7ixXu0Xo2XSlovBPF8KPN24COHu6a4" alt=""><figcaption></figcaption></figure>

Muestra de código, código en revisión. Puede accederse a través de Google Earth Engine en este [enlace](https://code.earthengine.google.com/e914e4bf1b4fd252f4ad90318ca2371e). O en Savimbo GitHub en este [enlace](https://github.com/savimbo).

```markup
// Load plot18 polygon
var plot18_data = require("users/drea/map:plot18_data");
var plot18 = plot18_data.polygon;

// Calculate plot area in hectare
var plotArea = plot18.area();
var plotAreaHectares = plotArea.divide(10000);

// Load jaguar points
var points_jaguar_data = require("users/drea/map:points_jaguar_data");
var puntos = points_jaguar_data.points;
var radios = [];
var sumMultipliedArea = ee.Number(0);

// Define a feature collection to store intersection polygons
var intersectionPolygons = ee.FeatureCollection([]);

// Define the assignedArea function
var assignedAreaFunction = function(offset) {
  var day = startDate.advance(offset, 'day');
  var dayString = day.format('YYYY-MM-dd');
  var feature = ee.Feature(null, { date: dayString, intersectionArea: intersectionArea });
  return feature.set('date_area', ee.String(dayString).cat(' - ').cat(intersectionArea));
};

// Calculate radios and buffers for each point
for (var i = 0; i < puntos.length; i++) {
  var point = puntos[i].geometry;
  var date = puntos[i].date;

  // Calculate the start date by subtracting 30 days
  var startDate = ee.Date(date).advance(-30, 'day');
  
  // Calculate the end date by adding 30 days
  var endDate = ee.Date(date).advance(30, 'day');
  
  // Create a feature with the point geometry and date as properties
  var feature = ee.Feature(point, { date: date });
  
  var pointBuffer = feature.buffer(800);
  radios.push(pointBuffer);
  
  // Calculate intersection with plot18
  var intersection = pointBuffer.intersection(plot18);
  
  // Calculate area in hectares
  var area = intersection.area().divide(10000);
  
  // Get the month and year of the date
  var month = ee.Date(date).get('month');
  var year = ee.Date(date).get('year');
  
  // Generate a label for the month and year
  var monthYearLabel = ee.String(month).cat('-').cat(year).cat(' Hectarias N°');
  
  // Calculate intersection with plot18 for the current point
  var intersectionPlot18 = pointBuffer.intersection(plot18);
  
  // Calculate area in hectares for the intersection with plot18
  var intersectionArea = intersectionPlot18.area().divide(10000);
  var multipliedArea = intersectionArea.multiply(60);
  
  // Add multipliedArea to the sum
  sumMultipliedArea = sumMultipliedArea.add(multipliedArea);
  
  // Define the jaguar range of dates
  var jaguarRange = endDate.difference(startDate, 'day');
  
 // Assign intersectionArea value to each day of the jaguar range
  var assignedArea = ee.FeatureCollection(ee.List.sequence(0, jaguarRange.subtract(1)).map(assignedAreaFunction));
  
  // Print the results for each point
  print('Jaguar:', i + 1);
  print('Date of image capture:', date);
  print('Start Date:', startDate.format('YYYY-MM-dd'));
  print('End Date:', endDate.format('YYYY-MM-dd'));
  print('Total Intersection Area per day in hectares:', intersectionArea);
  print('Multiplied Intersection Area * 60:', multipliedArea);
  print('Assigned Area per day:', assignedArea);
  print('----------------------');
  
  // Add the current point buffer to the map in blue color
  Map.addLayer(pointBuffer, { color: 'blue' }, 'Radio ' + (i + 1));
  
  // Add the intersection geometry to intersectionPolygons
  intersectionPolygons = intersectionPolygons.merge(intersection);
}

// Perform polygon unions to avoid duplicates
var unionPolygons = intersectionPolygons.union();

// Calculate the total area of intersections without duplicates
var totalIntersectionArea = unionPolygons.geometry().area().divide(10000);

// Display the results
print('Total intersection area hectares:', totalIntersectionArea);
print('Plot18 area hectares:', plotAreaHectares);
print('Sum of Multiplied Intersection Area hectares * 60 days:', sumMultipliedArea);

// Add the plot18 layer to the map
Map.addLayer(plot18, { color: 'gold' }, "plot18");
Map.centerObject(plot18);

```

<br>
