Raster, GeoTIFF and WebGL · Angular, React and OpenLayers

A GeoTIFF on a turned grid

Render a 20-degree rotated Sentinel-2 GeoTIFF placed by its ModelTransformation tag over OpenStreetMap in OpenLayers with rotated TileDebug.

OpenStreetMap of Kraków with a square Sentinel-2 image of its centre turned by 20° over it: the Planty ring, the Vistula and the Błonia meadow, and Show tiles unticked below.
A screenshot of the example. Contains modified Copernicus Sentinel data 2024. Map data © OpenStreetMap contributors.

What this example shows

Over an OpenStreetMap street backdrop of central Kraków—showing the Planty ring, Wawel bend of the Vistula and Błonia meadow—a local Sentinel-2 crop (assets/krakow/rotated-sentinel.tif) stored on an oblique pixel grid rotated by 20 degrees renders in exact geographic alignment at 80% opacity.

Checking the Show tiles box beneath the map overlays a rotated TileDebug wireframe that follows the GeoTIFF’s tilted internal tile grid rather than OpenStreetMap’s north-up grid.

When you need it

Flight-line aerial strips, synthetic-aperture radar (SAR) swaths and unrectified engineering scans frequently orient their pixel rows along a sensor track or building axis, storing an affine rotation matrix inside the GeoTIFF ModelTransformation tag instead of resampling pixels north-up.

Supporting ModelTransformation directly in WebGL places oblique rasters accurately without destructive double-resampling in desktop GIS beforehand.

The code

The example uses cc-openlayers, my Angular component library for OpenLayers: each aol-… element creates the OpenLayers object it names, updates it from its inputs and disposes of it with the component.

cog-modeltransformation.ts
import { ChangeDetectionStrategy, Component, DestroyRef, inject, signal, viewChild } from '@angular/core';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  LayerTileComponent,
  MapComponent,
  SourceOsmComponent,
  SourceTileDebugComponent,
  ViewComponent,
} from 'cc-openlayers';
import { LayerWebGLTileComponent } from 'cc-openlayers/webgl';
import { transformExtent } from 'ol/proj';
import GeoTIFF from 'ol/source/GeoTIFF';

/**
 * A COG whose grid is turned against its projection: the sample holds Sentinel-2's true-colour image of Kraków's
 * centre on a grid turned by 20°, which its ModelTransformation tag places in UTM zone 34N. OpenLayers reprojects it
 * to the map, and a debug source given the image's source outlines its tiles, turned with them.
 */
@Component({
  selector: 'app-cog-modeltransformation',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    LayerTileComponent,
    LayerWebGLTileComponent,
    MapComponent,
    SourceOsmComponent,
    SourceTileDebugComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="480px">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="13">
        <aol-coordinate [x]="19.9373" [y]="50.0617" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-tile><aol-source-osm /></aol-layer-tile>
      <aol-layer-webgltile [sources]="[image]" [opacity]="0.8" />
      <aol-layer-webgltile [visible]="showTiles()">
        <aol-source-tiledebug [source]="image" />
      </aol-layer-webgltile>
    </aol-map>
    <form class="example-controls">
      <label>
        <input type="checkbox" id="show-tiles" [checked]="showTiles()" (change)="showTiles.set(!showTiles())" />
        Show tiles
      </label>
    </form>
  `,
})
export class CogModeltransformation {
  readonly showTiles = signal(false);
  protected readonly image = new GeoTIFF({
    sources: [{ url: 'assets/krakow/rotated-sentinel.tif' }],
    attributions: 'Contains modified Copernicus Sentinel data 2024',
  });
  private readonly map = viewChild.required(MapComponent);

  constructor() {
    // The file names its projection by code, EPSG:32634: OpenLayers builds the UTM zones itself, without proj4.
    let destroyed = false;
    inject(DestroyRef).onDestroy(() => (destroyed = true));
    void this.image.getView().then(({ extent, projection }) => {
      if (destroyed) return;
      const view = this.map().instance.getView();
      if (extent && projection) view.fit(transformExtent(extent, projection, view.getProjection()));
    });
  }
}

Architecture and OpenLayers mechanics

image instantiates new GeoTIFF over assets/krakow/rotated-sentinel.tif (whose GeoKeys declare EPSG:32634 alongside a 20° affine ModelTransformation matrix). In the constructor—guarded by a destroyed flag wired to DestroyRef—image.getView() resolves the scene’s native extent and projection so view.fit(transformExtent(extent, projection, view.getProjection())) frames the tilted footprint on the Web Mercator view.

Two aol-layer-webgltile layers share the same image instance: the first renders the imagery via [sources]="[image]" at [opacity]="0.8", and the second ([visible]="showTiles()") wraps <aol-source-tiledebug [source]="image" /> to outline the rotated source tiles.

How it works

  • image creates a new GeoTIFF for assets/krakow/rotated-sentinel.tif, whose ModelTransformation tag rotates its EPSG:32634 grid by 20°.
  • Two aol-layer-webgltile layers share image: one drawing imagery at [opacity]="0.8" over OpenStreetMap, and one drawing <aol-source-tiledebug [source]="image" />.
  • Checkbox state drives [visible]="showTiles()" on the debug layer (unchecked initially).
  • Once image.getView() resolves, view.fit(transformExtent(extent, projection, view.getProjection())) frames the rotated scene cleanly unless already destroyed via DestroyRef.

Pitfalls

  • OpenLayers resolves standard UTM EPSG codes such as EPSG:32634 natively without proj4, whereas custom national CRS codes require registering a proj4 definition before transformExtent can project their bounds.
  • Mounting aol-source-tiledebug without [source]="image" draws north-up Web Mercator XYZ squares instead of the rotated GeoTIFF grid.

The same feature in the OpenLayers examples .

Background: state and lifecycle of maps in Angular with OpenLayers, which the components of cc-openlayers take care of.