Reading raster data
All this documentation is about representing raster data. In GIS, a raster is basically a 2-dimension matrix with the value of a magnitude in each point. The position over the Globe for each pixel (or matrix position) is given by the GeoTransform, and those positions are in a specific projection.
Fortunately, the most used format, GeoTIFF, can be read using the geotiff.js library. Some options are still not implemented, but most of the files can be read perfectly, which is a great advance. To read the GeoTIFF file and create a matrix:
- Note that the GeoTIFF file data must be read as an arraybuffer
- If you don’t want to use d3js, try this option
- The example file has two layers (or bands). In the example, we want the second one, that represents temperature, so rasters is the actual array to be processed
- The example shows how to calculate the GeoTransform and the inverse geotransform (how to calculate the pixel from the geographic coordinates)
If used from nodejs, the form to read the file is slightly different, since the fs functions are used:
The other parts of the code are the same.