Skip to Content
Web Mapping Illustrated
book

Web Mapping Illustrated

by Tyler Mitchell
June 2005
Beginner to intermediate
372 pages
10h 1m
English
O'Reilly Media, Inc.
Content preview from Web Mapping Illustrated

Accessing Spatial Data from PostGIS in Other Applications

Visualizing results isn't always the end goal of a spatial query. Often, someone just needs to write a report or provide a statistic. However, figures often help explain the data in a way that a report can't, which is why mapping is such a useful tool for communication.

If you want to visualize the results of PostGIS queries, you have a few options. Depending on what software you use, the simplest method may be to export the data from PostGIS to another format, such as a GML file or an ESRI shapefile. Or you may want to view the data directly in a desktop viewer such as OpenEV or put it in a MapServer web map application.

Exporting PostGIS Data into a Shapefile or GML

You can use the ogr2ogr utility to convert from PostGIS into many other formats. As discussed in Chapter 7, it is run from the command line. Here is an example of how to convert the mycounties view from PostGIS into a shapefile, though any OGR-supported output format can be used:

> ogr2ogr -f "ESRI Shapefile" mycounties.shp "PG:dbname=project1" mycounties

The -f parameter specifies what the output data format will be. The output dataset name will be mycounties.shp. The source dataset is the project1 database. The final word, mycounties, is the name of the layer to request from PostGIS. In this case it is a PostgreSQL view, but it can also be a table.

The shapefile can then be loaded into any GIS or mapping product that supports shapefiles. This format is fairly ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg

Publisher Resources

ISBN: 0596008651Supplemental ContentErrata Page