> For the complete documentation index, see [llms.txt](https://isbm.savimbo.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://isbm.savimbo.com/methodology/zh-cn/fu-lu/fu-lugkai-yuan-dai-ma-he-ji-suan-yang-ben.md).

# 附录G：开源代码和计算样本

用于生物多样性信用计算的开源代码可供公众在以下位置获取： [Savimbo GitHub](https://github.com/savimbo).&#x20;

我们有意使该代码更易于使用，并在 2024 年开始生物多样性认证后，通过一个接口向 IP 和 LC 项目提供自动生成信用、并可对接免费的 Airtable 数据库。免费 Airtable [注册 ](https://airtable.com/invite/r/fxsn6mcE)现已开放。IP 项目现在可通过该界面注册候补名单，并发送电子邮件至 <ops@savimbo.com> 获取 Airtable 数据库模板

演示计算亦可获得。Google Earth Engine 已承诺向参与气候变化的原住民群体提供免费账户。非商业用途 [注册](https://earthengine.google.com/noncommercial/) 可用。&#x20;

**图11。Google Earth Engine 代码示例**&#x20;

<figure><img src="https://lh6.googleusercontent.com/rVQ0Wv_v9_eXa7qOghqAvJhwResowct17qRiUSD-lO_eatzZqyiNhfpKmprKNcRWdVXXkv2FuYyAetkdA1BzOcf6d7EWeGqmRpKVVMGmk89gLOQd8i1K-Ia4A7ixXu0Xo2XSlovBPF8KPN24COHu6a4" alt=""><figcaption><p><em><strong>图11</strong></em>. Google Earth Engine 代码示例</p></figcaption></figure>

代码示例，代码正在外部修订中。可通过 Google Earth Engine 在此 [链接访问。](https://code.earthengine.google.com/e914e4bf1b4fd252f4ad90318ca2371e) 或在 Savimbo GitHub 在此 [链接访问。](https://github.com/savimbo) 联系 ***ops at savimbo.co**m* 如您希望成为代码审阅人。&#x20;

```markup
// 加载 plot18 多边形
var plot18_data = require("users/drea/map:plot18_data");
var plot18 = plot18_data.polygon;

// 以公顷为单位计算样地面积
var plotArea = plot18.area();
var plotAreaHectares = plotArea.divide(10000);

// 加载美洲豹点位
var points_jaguar_data = require("users/drea/map:points_jaguar_data");
var puntos = points_jaguar_data.points;
var radios = [];
var sumMultipliedArea = ee.Number(0);

// 定义用于存储交集多边形的要素集合
var intersectionPolygons = ee.FeatureCollection([]);

// 定义 assignedArea 函数
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));
};

// 计算每个点的半径和缓冲区
for (var i = 0; i < puntos.length; i++) {
  var point = puntos[i].geometry;
  var date = puntos[i].date;

  // 通过减去 30 天计算开始日期
  var startDate = ee.Date(date).advance(-30, 'day');
  
  // 通过增加 30 天计算结束日期
  var endDate = ee.Date(date).advance(30, 'day');
  
  // 创建一个以点几何和日期为属性的要素
  var feature = ee.Feature(point, { date: date });
  
  var pointBuffer = feature.buffer(800);
  radios.push(pointBuffer);
  
  // 计算与 plot18 的交集
  var intersection = pointBuffer.intersection(plot18);
  
  // 计算面积，以公顷为单位
  var area = intersection.area().divide(10000);
  
  // 获取日期的月份和年份
  var month = ee.Date(date).get('month');
  var year = ee.Date(date).get('year');
  
  // 生成月份和年份标签
  var monthYearLabel = ee.String(month).cat('-').cat(year).cat(' 公顷 N°');
  
  // 计算当前点与 plot18 的交集
  var intersectionPlot18 = pointBuffer.intersection(plot18);
  
  // 计算与 plot18 交集的面积，以公顷为单位
  var intersectionArea = intersectionPlot18.area().divide(10000);
  var multipliedArea = intersectionArea.multiply(60);
  
  // 将 multipliedArea 加到总和中
  sumMultipliedArea = sumMultipliedArea.add(multipliedArea);
  
  // 定义美洲豹活动范围的日期区间
  var jaguarRange = endDate.difference(startDate, 'day');
  
 // 将 intersectionArea 值分配给美洲豹范围内的每一天
  var assignedArea = ee.FeatureCollection(ee.List.sequence(0, jaguarRange.subtract(1)).map(assignedAreaFunction));
  
  // 打印每个点的结果
  print('美洲豹：', i + 1);
  print('图像获取日期：', date);
  print('开始日期：', startDate.format('YYYY-MM-dd'));
  print('结束日期：', endDate.format('YYYY-MM-dd'));
  print('每日总交集面积（公顷）：', intersectionArea);
  print('交集面积 × 60：', multipliedArea);
  print('每日分配面积：', assignedArea);
  print('----------------------');
  
  // 以蓝色将当前点缓冲区添加到地图
  Map.addLayer(pointBuffer, { color: 'blue' }, '半径 ' + (i + 1));
  
  // 将交集几何添加到 intersectionPolygons
  intersectionPolygons = intersectionPolygons.merge(intersection);
}

// 执行多边形并集以避免重复
var unionPolygons = intersectionPolygons.union();

// 计算去重后的交集总面积
var totalIntersectionArea = unionPolygons.geometry().area().divide(10000);

// 显示结果
print('总交集面积（公顷）：', totalIntersectionArea);
print('plot18 面积（公顷）：', plotAreaHectares);
print('交集面积乘以 60 天的总和（公顷）：', sumMultipliedArea);

// 将 plot18 图层添加到地图
Map.addLayer(plot18, { color: 'gold' }, "plot18");
Map.centerObject(plot18);

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://isbm.savimbo.com/methodology/zh-cn/fu-lu/fu-lugkai-yuan-dai-ma-he-ji-suan-yang-ben.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
