3.5. OGR Simple Features Library

 < Day Day Up > 

OGR is part of the FWTools package that's available at http://fwtools.maptools.org. The OGR project home page (http://www.gdal.org/ogr) describes OGR as:

... a C++ open source library (and command line tools) providing read (and sometimes write) access to a variety of vector file formats including ESRI Shapefiles, S-57, SDTS, PostGIS, Oracle Spatial, and Mapinfo mid/mif and TAB formats.

The historical definition of the acronym OGR is irrelevant today, but it's used throughout the code base, making it difficult to change.


OGR supports more than 16 different vector formats and has utilities similar to GDAL's raster utilities.

3.5.1. Vector Formats Supported by OGR

The following list of the vector data formats supported by OGR was taken from the OGR formats web page at http://www.gdal.org/ogr/ogr_formats.html. The web page also shows which formats can be written or only read by OGR.

Arc/Info Binary Coverage
ESRI shapefile
DODS/OPeNDAP
FMEObjects Gateway
GML
IHO S-57 (ENC)
Mapinfo file
Microstation DGN
OGDI vectors
ODBC
Oracle Spatial
PostgreSQL
SDTS
UK .NTF
U.S. Census TIGER/Line
VRT: Virtual Datasource

OGR is part of the GDAL/OGR project and is packaged with GDAL. GDAL deals with raster or image data, and OGR deals with vector data. GDAL is to painting as OGR is to connect-the-dot drawings. These data access and conversion libraries cover the breadth of mapping data.

3.5.2. OGR Utilities and Examples

Like GDAL, OGR consists of a set of libraries that can be used in applications. It also comes with some powerful utilities:


ogrinfo

Interrogates a vector dataset and gives information about the features. This can be done with any format supported by OGR. The following code shows ogrinfo being used to show information about a shapefile:

     # ogrinfo -summary placept.shp placept     Had to open data source read-only.     INFO: Open of `placept.shp'     using driver `ESRI Shapefile' successful.     Layer name: placept     Geometry: Point     Feature Count: 497     Extent: (-140.873489, 42.053455) - (-52.808067, 82.431976)     Layer SRS WKT:     (unknown)     AREA: Real (12.3)     PERIMETER: Real (12.3)     PACEL_: Integer (10.0)     PACEL_ID: Integer (10.0)     UNIQUE_KEY: String (5.0)     NAME: String (50.0)     NAME_E: String (50.0)     NAME_F: String (50.0)     UNIQUE_KEY: String (5.0)     UNIQUE_KEY: String (5.0)     REG_CODE: Integer (2.0)     NTS50: String (7.0)     POP91: Integer (7.0)     SGC_CODE: Integer (7.0)     CAPITAL: Integer (3.0)     POP_RANGE: Integer (3.0) 

This example shows many vital pieces of information including geographic extent of features, a list of the attributes, their types, and how many features are in the file. Additional parameters can be added that help access desired information more specifically.

Running it in different modes (the example shows summary mode) will reveal more or less detail. A complete listing of all the values and geographic locations of the features is possible if you remove the -summary option. You can also specify criteria using standard database query statements (SQL), as shown in the following code. This is a very powerful feature that provides access to spatial data using a common database querying language. Even file-based OGR data sources can be queried using SQL statements. This function isn't limited to database data sources. For more information on OGR's SQL query capabilities, see http://www.gdal.org/ogr/ogr_sql.html.

     # ogrinfo placept.shp -sql "select NAME, NTS50, LAT, LONG, POP91 from placept     where NAME = 'Williams Lake'"     OGRFeature(placept):389       NAME (String) = Williams Lake       NTS50 (String) = 093B01       POP91 (Integer) = 10395       POINT (-122.16555023 52.16541672) 


ogr2ogr

Takes an input OGR-supported dataset, and converts it to another format. It can also be used to reproject the data while converting into the output format. Additional actions such as filtering remove certain features and retain only desired attributes. The following code shows a simple conversion of a shapefile into GML format.

     # ogr2ogr -f "GML" places.gml placept.shp 

This code takes an ESRI shapefile and easily converts it to GML format or from/into any of the other formats that OGR supports writing to. The power of these capabilities is surpassed by few commercially available packages, most notably SAFE Software's Feature Manipulation Engine (FME).

Note that the syntax for ogr2ogr puts the destination/output filename first, then the source/input filename. This order can be confusing when first using the tool. Many command-line tools specify input and then output.


OGR, like GDAL, aids in accessing, converting, and manipulating data, specifically vector data. OGR can also be used with scripting languages, allowing programmatic manipulation of data. GDAL/OGR packages typically come with OGR modules for Python. In addition to Python bindings, Java and C# support for GDAL/OGR are in development as of Spring 2005. Perl and PHP support may also be available in the future.

A PHP extension for OGR is available but isn't supported or actively developed. It was developed independent of the main GDAL/OGR project and is available at: http://dl.maptools.org/dl/php_ogr/. If you can't wait for official PHP support through the GDAL/OGR project, give this one a try.


     < Day Day Up > 


    Web Mapping
    Web Mapping Illustrated: Using Open Source GIS Toolkits
    ISBN: 0596008651
    EAN: 2147483647
    Year: 2005
    Pages: 138

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net