Edit

NDVI+NDWI from two 16-bit COGs

cog11 ndvi3 ndwi1 sentinel1 geotiff1

将 NDVI+NDWI 计算为绿色和蓝色的值.

本例中的GeoTIFF层从两个经过云优化的Sentinel 2 GeoTIFF计算归一化植被指数(NDVI) 和归一化水分指数(NDWI):一个是10米分辨率和红色及近红外波段, 另一个是60米分辨率和短波红外通道。NDVI显示为绿色,NDWI显示为蓝色。 第4个波段是阿尔法波段,当一个来源配置了节点数据值时,它就会被添加进来。 本示例中的 GeoTIFF 图层从两个经过云优化(cloud-optimized)的 Sentinel 2 GeoTIFFs 计算归一化植被指数(NDVI)和归一化水分指数(NDWI): 一个是10米分辨率的红色及近红外波段, 一个是60米分辨率的短波红外通道。 NDVI 显示为绿色,NDWI 显示为蓝色。 第4个波段是阿尔法波段,当一个资源配置了 nodata 数据值时,它就会被添加进来。

main.js
import GeoTIFF from 'ol/source/GeoTIFF.js';
import Map from 'ol/Map.js';
import TileLayer from 'ol/layer/WebGLTile.js';

const source = new GeoTIFF({
  sources: [
    {
      url: 'https://s2downloads.eox.at/demo/Sentinel-2/3857/R10m.tif',
      bands: [3, 4],
      min: 0,
      nodata: 0,
      max: 65535,
    },
    {
      url: 'https://s2downloads.eox.at/demo/Sentinel-2/3857/R60m.tif',
      bands: [9],
      min: 0,
      nodata: 0,
      max: 65535,
    },
  ],
});
source.setAttributions(
  "<a href='https://s2maps.eu'>Sentinel-2 cloudless</a> by <a href='https://eox.at/'>EOX IT Services GmbH</a> (Contains modified Copernicus Sentinel data 2019)"
);

const ndvi = [
  '/',
  ['-', ['band', 2], ['band', 1]],
  ['+', ['band', 2], ['band', 1]],
];

const ndwi = [
  '/',
  ['-', ['band', 3], ['band', 1]],
  ['+', ['band', 3], ['band', 1]],
];

const map = new Map({
  target: 'map',
  layers: [
    new TileLayer({
      style: {
        color: [
          'color',
          // red: | NDVI - NDWI |
          ['*', 255, ['abs', ['-', ndvi, ndwi]]],
          // green: NDVI
          ['*', 255, ndvi],
          // blue: NDWI
          ['*', 255, ndwi],
          // alpha
          ['band', 4],
        ],
      },
      source,
    }),
  ],
  view: source.getView(),
});
index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>NDVI+NDWI from two 16-bit COGs</title>
    <link rel="stylesheet" href="node_modules/ol/ol.css">
    <style>
      .map {
        width: 100%;
        height: 400px;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>
    <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
    <script src="./resources/elm-pep.js"></script>
    <script type="module" src="main.js"></script>
  </body>
</html>
package.json
{
  "name": "cog-math-multisource",
  "dependencies": {
    "ol": "7.3.0"
  },
  "devDependencies": {
    "vite": "^3.2.3"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build"
  }
}