klokantech / ol3raster

OL3 Raster Reprojection
Other
0 stars 0 forks source link

Implementation of the reprojection process #1

Closed petrsloup closed 9 years ago

petrsloup commented 9 years ago

Two warping functions sharing most of the code: a) For tile sources: ol.reproj.createTile(sourceProj, sourceTileGrid, targetProj, targetTileGrid, x, y, z, pixelRatio, getTileFunction) -> ol.Tile b) For image sources: ol.reproj.createImage(sourceProj, targetProj, targetExtent, targetResolution, pixelRatio, getImageFunction) -> ol.ImageBase

  1. Target extent triangulation
    • target extent is broken into smaller pieces (triangles) to minimize the reprojection error
      • constant number of triangles (compile-time constant) (see #2 for improved solution)
    • triangulation vertices transformed from targetProjection to sourceProjection
  2. Loading of source data
    • calculates source resolution (constant for the whole target extent - tile or image)
    • ideal source resolution at the center of the target extent: targetProj.getMetersPerUnit() * targetProj.getPointResolution(targetResolution, extentCenter) / sourceProj.getMetersPerUnit()
    • extent from the triangulation vertices (bounding box)
    • start loading the data
      • a) find nearest resolution in the source TileGrid and determine z + getTileRangeForExtentAndResolution to determine which tiles are required
      • b) directly pass the resolution and extent to the getImageFunction
  3. Reprojection
    • creates the off-screen canvas for the output and returns appropriate class instance (extending a) ol.Tile b) ol.ImageBase) with state set to LOADING
    • after all the inputs are loaded (listening for change events on all inputs if needed (not cached))
    • renders all of the triangles one by one:
      • using the affine transform (same for all the inputs)
      • clipped by the triangle boundary
      • renders each input inside the triangle (with proper offset)
    • sets the output class state to LOADED
klokan commented 9 years ago

There is a need to support non-tiled source #9 as well.

petrsloup commented 9 years ago

Updated the description to support (non-tiled) image sources as well.

petrsloup commented 9 years ago

Instead of the ol.reproj.createTile and ol.reproj.createImage methods, new classes were implemented: ol.reproj.Tile and ol.reproj.Image with the constructor parameters being the same as the arguments described above.

Since the reprojection process is asynchronous (waiting for the input data), it is much cleaner to maintain the reprojection data, state and callbacks inside the instance rather than creating several closure from the createX methods and modifying the instance. (For example, after reprojecting the data, there was no natural way to change the state of the Tile/Image -- the instance should be responsible for its own state.)

klokan commented 9 years ago

This initial work is now practically finished - all code is in rasterreproj branch.

Demo is visible at: http://klokantech.github.io/ol3raster/examples/reprojection.html