3.6. PostGIS

 < Day Day Up > 

PostgreSQL is a powerful enterprise-level relational database that is free and open source but also has commercial support options. It is the backbone of data repositories for many applications and web sites. Refractions Research (http://www.refractions.net) has created a product called PostGIS that extends PostgreSQL, allowing it to store several types of geographic data. The result is a robust and feature-rich database for storing and managing tabular and geographic data together. Having this ability makes PostgreSQL a spatial database, one in which the shapes of features are stored just like other tabular data.

PostgreSQL also has several native geometry data types, but according to Refractions, these aren't advanced enough for the kind of GIS data storage they needed. The PostGIS functions handle the PostGIS geometry types and not the native PostgreSQL geometry types.


This description is only part of the story. PostGIS isn't merely a geographic data storage extension. It has capabilities from other projects that allow it to manipulate geographic data directly in the database. The ability to manipulate data using simple SQL sets it ahead of many commercial alternatives that act only as proprietary data stores. Their geographic data is encoded so that only their proprietary tools can access and manipulate the data.

The more advanced PostGIS functions rely on an underlying set of libraries. These come from a Refraction project called Geometry Engine Open Source (GEOS). GEOS is a C++ library that meets the OGC specification for Simple Features for SQL. GEOS libraries can be used in custom applications and were not designed solely for use with PostGIS. For more information on GEOS, see http://geos.refractions.net/.


3.6.1. GIS Analysis with SQL

PostGIS allows you to use SQL statements to manipulate and create geographic data for example, to buffer points and create circles. This is just the tip of the iceberg. PostGIS can be a GIS in and of itself while at the same time, all the power of PostgreSQL as a tabular database is available. GIS overlays, projecting and reprojecting of features into other coordinate systems, and spatial proximity queries are all possible using PostGIS. It is possible to have all the standard GIS overlay and data manipulation processes available in a server-side database solution. Example 3-1 illustrates the marriage of SQL and GIS capabilities by selecting points contained by another shape. More examples are shown in Chapter 13.

Example 3-1. An SQL command that takes a polygon shape from one table and finds all the points that are within a feature in another table
 > SELECT town_name      FROM towns, ontario     WHERE Contains(ontario_polygon,#first feature                   town_points);    #containing the others      town_name -------------------  Port Hope Simpson  Hopedale  Makkovik  Churchill Falls  North West River  Rigolet  Cartwright  Tignish  Cheticamp  Sheet Harbour (10 rows)

PostGIS is increasingly used as a tool for map data storage and manipulation. It is ideal for situations in which multiple applications access information simultaneously. Regular processing tasks can be set up while also making the data available to a web mapping site.

Other GIS and mapping tools are able to interact with PostGIS data. OGR, for example, can read/write PostGIS data sources. MapServer can also access PostGIS data. Many people rely on this combination to serve up their maps. Some use custom MapServer applications to add or update information stored in PostGIS-enabled databases. A product called GeoServer (see http://geoserver.sourceforge.net) uses the OGC Transactional Web Feature Server (WFS-T) standard for read/write access to PostGIS and other formats. A PostGIS function exists for returning Scalable Vector Graphics (SVG) representations of geometries. The Quantum GIS (QGIS) desktop program (see http://www.qgis.org) can also read from PostGIS, and current development will extend that to also allow editing.

The internal programming capabilities of PostgreSQL (using related procedural languages such as Pl/Pgsql and Pl/Python) allow programmatic access to various PostGIS functions and PostGIS data. Many PostGIS functions allow for a range of manipulation as well as conversion into different data types (e.g., as simple text strings, binary, or even as SVG).

A PostGIS spatial has many of the functions of a normal database one being that they both use SQL commands to access data. With PostGIS, the information can also include the PostGIS geometry data. PostGIS functions can then manipulate, summarize, or create new spatial data.

You may wonder what the differences are between the spatial component of MySQL databases and PostGIS. The main difference is that MySQL lacks many of the spatial functions found in PostGIS. Also, MySQL doesn't support transactional integrity for spatial features.


     < 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