GeoZarr
GeoZarr示例。 Zarr GeoZarr sentinel-2
GeoZarr 数据源可用于从遵循 GeoZarr 规范 的 Zarr 文件中读取多波段数据组。支持遵循 Multiscales 约定 的 GeoZarr。带有 OGC TileMatrixSet 定义的旧版 multiscales GeoZarr 也可以使用。
在本示例中,使用 Sentinel-2 L2A 的 B02(蓝)、B03(绿)和 B04(红)波段反射率值渲染真彩色合成影像。0 到 0.5 之间的反射率值被拉伸到 0 到 255 之间,用于 RGB 颜色通道。同时还进行了伽马校正以提亮图像。
要尝试不同的场景,可以浏览 EOPF Explorer 的 Sentinel-2 Level-2A 目录,找到一个 Zarr 存储,然后在上方的下拉列表中选择 "Custom...",粘贴包含组路径的 URL(例如 store.zarr/measurements/reflectance)。注意,只有包含 'b02'、'b03' 和 'b04' 波段的 GeoZarr 才能在不修改源代码的情况下正常工作。
main.js
js
import Map from 'ol/Map.js';
import {
getView,
withExtentCenter,
withHigherResolutions,
withLowerResolutions,
withZoom,
} from 'ol/View.js';
import TileLayer from 'ol/layer/WebGLTile.js';
import GeoZarr from 'ol/source/GeoZarr.js';
import OSM from 'ol/source/OSM.js';
const select = document.getElementById('url-select');
const input = document.getElementById('custom-url');
const button = document.getElementById('load-url');
function getUrl() {
return select.value === 'custom' ? input.value : select.value;
}
select.addEventListener('change', () => {
if (select.value === 'custom') {
input.style.display = '';
input.focus();
} else {
input.style.display = 'none';
}
});
let map;
function render() {
const url = getUrl();
if (!url) {
return;
}
const source = new GeoZarr({
url: url,
bands: ['b04', 'b03', 'b02'],
});
if (map) {
map.setTarget(null);
}
map = new Map({
layers: [
new TileLayer({
source: new OSM(),
}),
new TileLayer({
style: {
gamma: 1.5,
color: [
'color',
['interpolate', ['linear'], ['band', 1], 0, 0, 0.5, 255],
['interpolate', ['linear'], ['band', 2], 0, 0, 0.5, 255],
['interpolate', ['linear'], ['band', 3], 0, 0, 0.5, 255],
],
},
source,
}),
],
target: 'map',
view: getView(
source,
withLowerResolutions(1),
withHigherResolutions(2),
withExtentCenter(),
withZoom(2),
),
});
}
button.addEventListener('click', render);
render();index.html
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GeoZarr</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>
<div class="row mt-2">
<div class="col-auto">
<div class="input-group">
<label class="input-group-text" for="url-select">URL</label>
<select class="form-select" id="url-select">
<option value="https://s3.explorer.eopf.copernicus.eu/esa-zarr-sentinel-explorer-fra/tests-output/sentinel-2-l2a/S2C_MSIL2A_20260120T084301_N0511_R064_T36UXA_20260120T122910.zarr/measurements/reflectance">Sentinel-2 L2A (Krasnokuts'k)</option>
<option value="https://s3.explorer.eopf.copernicus.eu/esa-zarr-sentinel-explorer-fra/tests-output/sentinel-2-l2a/S2B_MSIL2A_20260120T125339_N0511_R138_T27VWL_20260120T131151.zarr/measurements/reflectance">Sentinel-2 L2A (Hvolsvöllur)</option>
<option value="custom">自定义...</option>
</select>
<input type="text" class="form-control" id="custom-url" placeholder="Enter Zarr URL" style="display: none; width: 300px;">
<button class="btn btn-outline-secondary" id="load-url" type="button">加载</button>
</div>
</div>
</div>
<script type="module" src="main.js"></script>
</body>
</html>package.json
json
{
"name": "geozarr",
"dependencies": {
"ol": "10.11.0"
},
"devDependencies": {
"vite": "^8.1.5"
},
"scripts": {
"start": "vite",
"build": "vite build"
}
}