OGR's main modules and classes

The OGR library consists of two main modules—ogr and osr. Both are sub-modules inside of the osgeo module. The ogr sub-module deals with vector geometry, while osr is all about projections. In the Reading and writing vector data with OGR section in Chapter 4Data Types, Storage, and Conversion, we already saw some examples of how to make use of both.

OGR offers the following seven classes:

  • Geometry
  • Spatial Reference
  • Feature
  • Feature Class Definition
  • Layer
  • Dataset
  • Drivers

The class names are mostly self-explanatory, but it's good to have an overview of how OGR is structured. In the following examples, we'll see how to access and make use of these classes. OGR's modules, classes, and functions are documented on the GDAL website (www.gdal.org/python) but offer no code examples, which makes it hard to get started. What's good to know at this point is that other Python libraries fill in the gap and offer a more user-friendly way to deal with GDAL's capabilities (such as Fiona and GeoPandas). Also, both ogrinfo and ogr2ogr might be preferable over using Python in some use cases, for example, when reprojecting vector data.

Let's look at a few OGR examples.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset