OGR/PHP Extension

 

Introduction

The OGR library is 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 C API is generally easy to call from other languages which allow call out to DLLs functions, such as Visual Basic, or Delphi.

The OGR/PHP extension enables PHP users to access the functionalities included in the OGR library.  This extension can be used as built-in PHP or as dynamic library (".dll" on Windows or ".so" on Unix).

This extension was developed and is currently being maintained by DM Solutions Group. Special thanks go to Lars V. Nielsen and Hvenegaard & Meklenborg for funding the initial development of this extension and allowing it to remain open source.
 

Installation

The php_ogr.dll is located in /ms4w/Apache/php/extensions.

Testing

To verify that the OGR/PHP extension was installed properly, check PHP's list of loaded extensions by clicking here.

If the PHP/OGR extension was successfully loaded, you should see an "OGR" table stating that OGR support is enabled.
 

Functions documentation

The C API documentation  was created using Doxygen and is part of the GDAL/OGR documentation.  In addition to OGR functions, four CPL functions for handling error are made available to the user:  CPLErrorReset, CPLGetLastErrorNo, CPLGetLastErrorMsg and CPLGetLastErrorType.  Information on these functions can be found on this page.

Information and bug reporting

The gdal-dev@lists.osgeo.org mailing list can be used for discussion of development and user issues related to OGR and related technologies. Subscriptions can be done, and archives reviewed on the web.

Examples

There are a few examples showing how to use the functions in the PHP/OGR extension module.  Consult the README_EXAMPLES.TXT in the /ms4w/apps/php_ogr/examples directory to get more information on what is the purpose of each example.

Each example must be invoked from the command-line.

Example:  ./php -q ogr2tab.php /path/to/outputfilename.tab /path/to/sourcefilename.tab

"ogr2ogr.php" shows mostly the following:
 

"ogr2tab.php" is accomplishing the same operations as "ogr2ogr.php" but is concerned especially with the MapInfo File format.

"ogr_spatialfilter.php" shows mostly how to set a spatial filter and an attribute filter.

"ogr2tab_spatialfilter.php" is accomplishing the same operations as "ogr_spatialfilter.php" but is used exclusively with MapInfo File format.

"ogr_sql.php" demonstrates how to build an SQL statement and apply an SQL request to a data source.

"ogr2tab_sql.php" is a copy of "ogr_sql.php" and is concerned with the MapInfo File format.

"ogr_update.php" demonstrates the following items:


"ogr2tab_update.php" is a copy of "ogr_update.php" but is concerned with the MapInfo File format.

"ogr_dump.php" shows the following functionalities:

"ogr_write.php" demonstrates the following functionalities: "ogr_setgetfield.php" shows how to get and to set field values of various types inside a feature.