Structure

Features structure

The module [b]`girs.feat`` is a wrapper around ogr classes and functions with additional geoprocessing tools. It operates on vector data, which is represented by points, lines, and polygons. The terms vector and feature are used here interchangeably for vector data structures.

OGR can read vector data in many formats (see e.g., http://www.gdal.org/ogr_formats.html). The package girs.feat.layers provides individual classes to read, update and write vector data. girs.feat.layers.LayersSet is used to retrieve and to analyse but not to create or to edit data. The latter is accomplished by girs.feat.layers.LayersEditor, a sub-class of LayersSet. Data can be created on a new dataset or edited on an existing dataset. This is distinguished in two sub-classes of LayersEditor: girs.feat.layers.LayersWriter and girs.feat.layers.LayersUpdate.

The abstract class girs.feat.layers.LayersSet is a wrapper on OGRDataSet. It contains methods to process:

  • dataset
  • layer definition
  • layer
  • feature
  • field definition
  • field

OGR has the following structure:

  • A dataset:

    • is created or opened by a driver
    • contains one or more layers
  • A layer:

    • is associated to a layer definition
    • contains one or more features (rows, or records)
  • A layer definition has one or more field definitions

  • A feature contains field values correspondent to the field definitions

Layers

Layers structure:

  • girs.feat.layers.LayersSet: analyses dataset, layer definition, layer, feature, field definition, and field

    • girs.feat.layers.LayersReader: instantiate a read only dataset

    • girs.feat.layers.LayersEditor: provide methods to create and edit layer, feature, field definition, and field

      • girs.feat.layers.LayersUpdate: instantiate an exiting dataset for editing data
      • girs.feat.layers.LayersWriter: instantiate a new dataset for populating with new data

Layers numbers start at zero. Since some data formats allow only one layer (e.g., shapefile), girs’ methods set layer zero as default layer. Zero is the default layer number whenever no layer number is explicitly given.

A girs.feat.layers.LayersReader object consists of a set of individual layers. Each layer contains a layer definition, which basically defines the layer name, geometry type, field names, and field types. A layer contains also features, which correspond to rows (or records) as shown in Figure Shapefile attribute table.

A read-only Layers object reads an existing dataset. In most cases, a filename alone is sufficient to create a LayersReader object.

Datasets are provided in diverse formats. Most sources (file name or database name) are identified by their suffixes: for example, a shapefile has the suffix .shp. Some sources have either no suffix or ambiguous suffixes, i.e., same suffixes for different formats. For example, Memory or ODBC have no suffix, while the suffix mdb is used for both PGeo and Geomedia. In such cases, the driver must be also specified together with the source:

In the examples above, an object of the class LayersReader was created and set to the variable lrs. Using the python command dir, you can list all methods available in LayersReader, which will be discussed in this tutorial. The following example excludes the method starting with “__” (double underline), becaused they are assumed to be internal (private) class methods.

Raster structure

The package raster is a convenience wrapper around gdal. The module raster contains the classes RasterReader and RasterWriter.

The package girs.rast.raster provides individual classes to read, update and write raster data. girs.rast.raster.Raster is used to retrieve and to analyse but not to create or to edit data. The latter is accomplished by girs.rast.raster.RasterEditor, a sub-class of Raster. Data can be created on a new dataset or edited on an existing dataset. This is distinguished in two sub-classes of RasterEditor: girs.rast.raster.RasterWriter and girs.rast.raster.RasterUpdate.

  • girs.rast.raster.Raster: process dataset and arrays

    • girs.rast.raster.RasterReader: instantiate a read only dataset (gdal.Open(filename, GA_ReadOnly))

    • girs.rast.raster.RasterEditor: provide methods to set projection, array, and nodata

      • girs.rast.raster.RasterUpdate: instantiate an exiting dataset for editing data (gdal.Open(source, GA_Update))
      • girs.feat.layers.LayersWriter: instantiate a new dataset (drv.Create(…))

Raster band numbers start at one. Since rasters have at least on band and some rasters only one band, (e.g., digital elevation model, satellite precipitation products, climate products, etc.), girs’ methods set band one as default band number. Band one is the band number number whenever no band number is explicitally given.