Personal tools
You are here: Home For Developers Tutorials How to work with maps Raster IO

Raster IO

A raster is a data file representing a rectangular grid of pixels. Each pixel must have 1 or more bands, for example, a color picture has 3-band pixel - one band for each red, green and blue color components of RGB pattern.
To work with rasters, IRasterFactory, IInputRaster and IOutputRaster interfaces are incorporated in LANDIS-II.
To read pixels form a raster file use IRasterFactory.OpenRaster() method, which returns IInputRaster object. Then use the last's  ReadPixel() method.
To write pixel to a raster file use IRasterFactory.CreateRaster() method, which returns IOutputRaster object. Then use the last's WritePixel() method.

Example from Wind plug-in:

// Write wind severity map
IOutputRaster map = Model.Core.CreateRaster<SeverityPixel>(path,
                                            Model.Core.Landscape.Dimensions,
                                            Model.Core.LandscapeMapMetadata);
using (map)
{
    SeverityPixel pixel = new SeverityPixel();
    foreach (Site site in Model.Core.Landscape.AllSites)
    {
        if (site.IsActive)
        {
            if (SiteVars.Disturbed[site])
            {
// active site disturbed by wind
                pixel.Band0 = (byte) (SiteVars.Severity[site] + 1);
            }
            else
            {
                // undisturbed active site
                pixel.Band0 = 1;
            }
        }
        else
        {
            // inactive site
            pixel.Band0 = 0;
        }
        map.WritePixel(pixel);
    }
}

For more information refer to Landis.RasterIO Namespace in the LANDIS-II Help File for Developers.

< Page 1 | Page 2
Document Actions