Raster Data

Raster Data

In this section, we revisit the gdalworkshop/world.tif dataset.

ArchGDAL.registerdrivers() do
    ArchGDAL.read(filepath) do dataset
        print(dataset)
    end
end

A description of the display is available in Raster Datasets.

Raster Bands

We can examine an individual raster band

ArchGDAL.registerdrivers() do
    ArchGDAL.read(filepath) do dataset
        band = ArchGDAL.getband(dataset, 1)
        print(band)
    end
end

You can programmatically retrieve the information in the header using

You can get additional attribute information using

Note

GDAL contains a concept of the natural block size of rasters so that applications can organized data access efficiently for some file formats. The natural block size is the block size that is most efficient for accessing the format. For many formats this is simple a whole scanline in which case *pnXSize is set to GetXSize(), and *pnYSize is set to 1.

However, for tiled images this will typically be the tile size.

Note that the X and Y block sizes don't have to divide the image size evenly, meaning that right and bottom edge blocks may be incomplete.

Finally, you can obtain overviews:

Raster I/O

Reading Raster Values

The general operative method for reading in raster values from a dataset or band is to use ArchGDAL.read().

You can also specify the subset of rows and columns (provided as UnitRanges) to read:

On other occasions, it might be easier to first specify a position (xoffset,yoffset) to read from, and the size (xsize, ysize) of the window to read:

You might have an existing buffer that you wish to read the values into. In such cases, the general API for doing so is to write ArchGDAL.read!(source, buffer, args...) instead of ArchGDAL.read(source, args...).

Writing Raster Values

For writing values from a buffer to a raster dataset or band, the following methods are available:

Windowed Reads and Writes

Following the description in mapbox/rasterio's documentation, a window is a view onto a rectangular subset of a raster dataset. This is useful when you want to work on rasters that are larger than your computers RAM or process chunks of large rasters in parallel.

For that purpose, we have a method called ArchGDAL.windows(band) which iterates over the windows of a raster band, returning the indices corresponding to the rasterblocks within that raster band for efficiency:

ArchGDAL.registerdrivers() do
    ArchGDAL.read(filepath) do dataset
        band = ArchGDAL.getband(dataset, 1)
        for (cols,rows) in ArchGDAL.windows(band)
            println((cols,rows))
        end
    end
end

Alternatively, we have another method called ArchGDAL.blocks(band) which iterates over the windows of a raster band, returning the offset and size corresponding to the rasterblocks within that raster band for efficiency:

ArchGDAL.registerdrivers() do
    ArchGDAL.read(filepath) do dataset
        band = ArchGDAL.getband(dataset, 1)
        for (xyoffset,xysize) in ArchGDAL.blocks(band)
            println((xyoffset,xysize))
        end
    end
end
Note

These methods are often used for reading/writing a block of image data efficiently, as it accesses "natural" blocks from the raster band without resampling, or data type conversion.