Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Intro

ESA

There are multiple ways to interactivcely visualise COG files and their pyramids, a lot of which rely on some sort of http connection or local file server running. There are generally more ways to visaulisae data, so long as you are happy viewing it in web mercator.

No data transformation are required as building the pyramids and overviews is part of the cog specification.

We present three ways:

  • Using local tile server, which is a lightweight tile server that shows data locally

  • HV Plot to interactively plot. HV plot is popular and part of the pangeo package and good for small and high resoulition datasets

  • Open Layers. Open layers is a Javascript library to generate dynamic maps and works in multple projections and from many data sources cog, parquet, geozarr , etc.

Generate the cog data from the OceanSoda Sample

Loading...

Tile server quick view

HV plot - raw data plotting

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
CRS: EPSG:4326
Bounds: BoundingBox(left=-6.0, bottom=46.0, right=36.0, top=30.25)
Native shape: 63 x 168
Overview factors: []
Displayed shape: 63 x 168
/home/krasen/hackathon_websites/ocean_hackathon/.pixi/envs/default/lib/python3.13/site-packages/cartopy/io/__init__.py:242: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_0_boundary_lines_land.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
Loading...

OpenLayers COG viewer

For open layers you need to a remote file or to create an http server that allows cross origin requests using python for example, that will server the files. The javascript code should use the new open layers functionality, the correct crs and basemap.


const cogSource = new ol.source.GeoTIFF({
  normalize: false,
  interpolate: true,
  sources: [
    {
      url: COG_URL,
      nodata: NODATA
    }
  ]
});

const band = ["band", 1];

const validData = [
  "all",
  ["==", band, band], // filters NaN
  [">", band, NODATA_THRESHOLD]
];

const cogLayer = new ol.layer.WebGLTile({
  title: "Air-sea fCO₂ difference",
  source: cogSource,
  opacity: OPACITY,

  style: {
    color: [
      "case",
      validData,

      [
        "interpolate",
        ["linear"],
        band,

        // RdBu_r-style diverging colour scale
        -100, ["color", 5, 48, 97, 0.90],
        -75,  ["color", 33, 102, 172, 0.90],
        -50,  ["color", 67, 147, 195, 0.90],
        -25,  ["color", 146, 197, 222, 0.90],

        0,    ["color", 247, 247, 247, 0.90],

        25,   ["color", 244, 165, 130, 0.90],
        50,   ["color", 214, 96, 77, 0.90],
        75,   ["color", 178, 24, 43, 0.90],
        100,  ["color", 103, 0, 31, 0.90]
      ],

      // Transparent outside valid data
      ["color", 0, 0, 0, 0]
    ]
  }
});

const projection = "EPSG:3857";

const dataExtent = ol.proj.transformExtent(
  [-6, 30, 36, 46],
  "EPSG:4326",
  projection
);

const map = new ol.Map({
  target: "map",

  layers: [
    basemap,
    cogLayer
  ],

  view: new ol.View({
    projection,

    // Center around the middle of the raster
    center: ol.proj.fromLonLat([15, 38]),

    zoom: 4,
    minZoom: 2,
    maxZoom: 12,

    // Optional: constrain navigation to roughly the data region
    extent: dataExtent
  }),

  controls: ol.control.defaults.defaults().extend([
    new ol.control.ScaleLine()
  ])
});