GDAL Datasets

Data Model

GDAL Datasets

The following code demonstrates the general workflow for reading in a dataset:

ArchGDAL.read(filename) do dataset
    # work with dataset
end

We defer the discussion on ArchGDAL.read(filename) to the section on Working with Files.

Vector Datasets

In this section, we work with the data/point.geojson dataset:

dataset = ArchGDAL.read("data/point.geojson")
GDAL Dataset (Driver: GeoJSON/GeoJSON)
File(s): 

Number of feature layers: 1
  Layer 0: point (wkbPoint)

The display indicates

You can also programmatically retrieve them using

For more on working with features and vector data, see the Section on Feature Data.

Raster Datasets

In this section, we work with the gdalworkshop/world.tif dataset:

dataset = ArchGDAL.read("gdalworkshop/world.tif")
GDAL Dataset (Driver: GTiff/GeoTIFF)
File(s): 

Dataset (width x height): 2048 x 1024 (pixels)
Number of raster bands: 3
  [GA_ReadOnly] Band 1 (Red): 2048 x 1024 (UInt8)
  [GA_ReadOnly] Band 2 (Green): 2048 x 1024 (UInt8)
  [GA_ReadOnly] Band 3 (Blue): 2048 x 1024 (UInt8)

The display indicates

You can also programmatically retrieve them using

For more on working with raster data, see the Section on Raster Data.

Working with Files

We provide the following methods for working with files:

In GDAL, datasets are closed by calling GDAL.close(). This will result in proper cleanup, and flushing of any pending writes. Forgetting to call GDAL.close() on a dataset opened in update mode in a popular format like GTiff will likely result in being unable to open it afterwards.

In ArchGDAL, the closing of datasets is handled by the API and not by the user. ArchGDAL provides two methods for working with datasets.

The first is to use a do-block:

ArchGDAL.<copy/create/read/update>(...) do dataset
    # work with dataset
end

The second is to call the method directly:

dataset = ArchGDAL.<copy/create/read/update>(...)
# work with dataset
Note

This pattern of using do-blocks to manage context plays a big way into the way we handle memory in this package. For details, see the section on Memory Management.