LibGrid

Example

Programming API | | Linkage with CMake

Programming Example

The following sample code shows how to load a layer, manipulate it, and save it back. It is pretty much self-explanatory, so the code is left to the user to explore on their own.

#include <grid/grid.h>

void main()
   {
   grid_resampler resampler;
   grid_layer *layer;

   // load layer
   layer=resampler.load("path","input_filename.tif");
   if (layer==NULL) exit(1);

   // check for elevation data
   //  images are cell-centered
   //  height fields are grid-centered
   if (!layer->grid_cell_centered)
      {
      // replace elevation values in the range [0..1000] with no-data
      layer->replace_range(data_value(0.0),data_value(100.0),nodata_value());

      // save to geotiff format (lzw compressed by default)
      if (!resampler.save("path","output_filename.tif",layer)) exit(1);
      }
   }

Also have a look at the applications in the tools directory, in particular the “gridinfo” tool, which illustrates how to retrieve basic properties such as size and spacing from a grid layer.

Programming API | | Linkage with CMake

Options: