Skip to content

This WebAssembly library provides an API for extremely fast generation of isolines and isobands in GeoJSON format when given raw, raster data such as from a GeoTIFF file.

Notifications You must be signed in to change notification settings

zbennett10/wasm-marching-squares

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wasm-marching-squares

This library is a direct port of rveciana's raster-marching-squares to WebAssembly by way of C. The algorithm is implemented in C and currently generates GeoJSON isolines given raw data from a GeoTIFF file. Isobands will be supported in the future.

Usage

Import the library; import loadWasmMarchingSquaresModule from 'wasm-marching-squares';

Load the WASM library asyncronously: const WasmMarchingSquares = await loadWasmMarchingSquaresModule();

Create some isolines!

/**
 * rasterMatrix: number[][]
 * intervals: number[]
 * transform: number[] (six values -> please see https://gdal.org/user/raster_data_model.html#affine-geotransform)
 **/
const isolines = WasmMarchingSquares.generateIsolines(rasterMatrix, intervals, transform);

Caveats

  • Need to add a cleaner external API for ease of use.
  • Isoband generation is not implemented yet

Build

To properly build, you will need to download the Emscripten SDK.

  1. Compile the Jansson C JSON library using emcc

    • Remove CMakeCache.txt from `include/jansson-2.13.1 if it exists
    • cd include/jansson-2.13.1 && emcmake cmake -DCMAKE_INSTALL_PREFIX:PATH=./emcc-lib .
    • emmake make VERBOSE=1
    • emmake make check
    • emmake make install
  2. Generate the WASM code and JavaScript 'glue' code

./build

Test

C Library Unit Testing

  1. Compile the Jansson C JSON library using cmake

    • Remove CMakeCache.txt from `include/jansson-2.13.1 if it exists
    • cd include/jansson-2.13.1 && cmake .
    • emmake make VERBOSE=1
    • emmake make check
    • emmake make install
  2. Compile and run the unit tests

cd test && ./test

Functional Testing

  • Start a webserver and serve the test directory
  • Navigate to the index.html and click Test GeoJSON
  • You can test the vardah.tif file or the sfctmp.tif file by altering the test/map.js file.

TODO

  • Implement Isoband generation
  • Speed up lookups using a Quadtree

About

This WebAssembly library provides an API for extremely fast generation of isolines and isobands in GeoJSON format when given raw, raster data such as from a GeoTIFF file.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published