Example 1:

Open a shape file that contains trail information (i.e.features) for the Olympic National Park and extract the corresponding location(i.e. geometry) for each trail.

Example 2:

This example was generated by Chris Garrard for a class on "Geoprocessing with Python using Open Source GIS". It illustrates creating a new shapefile file and copying selected features from an old shapefile to the new one.

Example 3:

This example was generated by Chris Garrard for a class on "Geoprocessing with Python using Open Source GIS". It illustrates creating a new shapefile file, creating polygons from vertices in a text file, and writing the resulting geometries to the new shapefile.

Example 4:

This example was generated by Chris Garrard for a class on "Geoprocessing with Python using Open Source GIS". It illustrates reprojecting a shapefile (unprojected geographic coordinates/NAD83 datum)created in example 3 to the UTM projection, Zone 12N/NAD83.

Example 5:

Takes the modified raw text trail information generated in example 1 and reformates it into a new shape file

Example 6:

Merge lake features from several diverse (e.g. different projections and area coverage)files into one consistent shape file

OGR Attributes

ogrConstants  Constants provided by OGR
 

Class Summary

OGR classes provides tools to handle vector datasources.
ogr

ORG provides a set of useful utility functions
Example: aDriver=org.GetDriverByName('ESRI Shapefile')

Driver Class Driver is an uninstanciable class providing various methods to represent an operational format driver.
Example:DataSource = aDriver.Open('nad27_trails.shp')
DataSource This class represents a data source.
Example:line_layer = DataSource.GetLayerByIndex(index=0) #index is always 0 and optional for shapefiles
#Make sure to close the DataSource with Destroy() at the end so things get written
FieldDefn Definition of an attribute of a FeatureDefn.
Examples:fieldDefn = ogr.FieldDefn('trail_name', ogr.OFTString) ; fieldDefn.SetWidth(10)#often used with a Layer object to create a field [e.g. line_layer.CreateField(fieldDefn) ] in a layer
Layer This class represents a layer of simple features, with access methods.
Examples: line_layer.CreateField(fieldDefn) ; a_feature = line_layer.GetNextFeature()
FeatureDefn

'This object contains schema information for a set of Feature. In table based systems, a FeatureDefn is essentially a layer. In more object oriented approaches (such as SF CORBA) this can represent a class of features but doesn't necessarily relate to all of a layer, or just one layer. This object also can contain some other information such as a name, the base geometry type and potentially other metadata.'
example:featureDefn = layer.GetLayerDefn() #Get it from the layer after adding any fields to the layer object;
Often used in creating a new Feature object [e.g. a_new_feature = ogr.Feature (featureDefn)]

Feature A simple feature, including geometry and attributes.
Examples:a_Geometry =a_feature.GetGeometryRef().Clone() ; trail_name=a_feature.GetFieldAsString(5)
Geometry Abstract base class for all geometry classes.
Example 1:(x,y,z)=a_Geometry.GetPoint(k) #get point number k in the set;
Example 2:line = ogr.Geometry(ogr.wkbLineString); line.AddPoint(10,10);make a new line object and add the first point
 

OSR Attributes

Interface Summary
osrConstants  Constants provided by OSR
 

Class Summary

OSR classes provides tools necessary to handle spatial reference systems and transformation between them.
osr OSR provides a set of useful utility functions.
SpatialReference This class respresents a OpenGIS Spatial Reference System, and contains methods for converting between this object organization and well known text (WKT) format.
Example 1: sourceSR=osr.SpatialReference(); sourceSR.ImportFromEPSG( 3717) #NAD83 UTM zone 10N
Example 2: :targetSR = osr.SpatialReference() ;targetSR.ImportFromEPSG( 26710 ) #NAD27 / UTM zone 10N
CoordinateTransformation Object for transforming between coordinate systems.
Example 1: coordTrans =osr.CoordinateTransformation(sourceSR,targetSR)#use with Geometery.Transform(coordTrans)