PacktLib: PostGIS Cookbook

PostGIS Cookbook


About the Authors

About the Reviewers


Moving Data In and Out of PostGIS


Importing nonspatial tabular data (CSV) using PostGIS functions

Importing nonspatial tabular data (CSV) using GDAL

Importing shapefiles with shp2pgsql

Importing and exporting data with the ogr2ogr GDAL command

Handling batch importing and exporting of datasets

Exporting data to the shapefile with the pgsql2shp PostGIS command

Importing OpenStreetMap data with the osm2pgsql command

Importing raster data with the raster2pgsql PostGIS command

Importing multiple rasters at a time

Exporting rasters with the gdal_translate and gdalwarp GDAL commands

Structures that Work


Using geospatial views

Using triggers to populate a geometry column

Structuring spatial data with table inheritance

Extending inheritance – table partitioning

Normalizing imports

Normalizing internal overlays

Using polygon overlays for proportional census estimates

Working with Vector Data – The Basics


Working with GPS data

Fixing invalid geometries

GIS analysis with spatial joins

Simplifying geometries

Measuring distances

Merging polygons using a common attribute

Computing intersections

Clipping geometries to deploy data

Simplifying geometries with PostGIS topology

Working with Vector Data – Advanced Recipes


Improving proximity filtering with KNN

Improving proximity filtering with KNN – advanced

Rotating geometries

Improving ST_Polygonize

Translating, scaling, and rotating geometries – advanced

Generating detailed building footprints from LiDAR

Using external scripts to embed new functionality in order to calculate a Voronoi diagram

Using external scripts to embed other libraries in order to calculate a Voronoi diagram – advanced

Working with Raster Data


Getting and loading rasters

Working with basic raster information and analysis

Performing simple map-algebra operations

Combining geometries with rasters for analysis

Converting between rasters and geometries

Processing and loading rasters with GDAL VRT

Warping and resampling rasters

Performing advanced map-algebra operations

Executing DEM operations

Sharing and visualizing rasters through SQL

Working with pgRouting


Startup – Dijkstra routing

Loading data from OpenStreetMap and finding the shortest path using A*

Driving distance/service area calculation

Calculating demographics using driving distance

Extracting the centerlines of polygons

Into the Nth Dimension


Importing LiDAR data

Performing 3D queries on a LiDAR point cloud

Constructing and serving buildings 2.5 D

Using ST_Extrude to extrude building footprints

Creating arbitrary 3D objects for PostGIS

Exporting models as X3D for the Web

Reconstructing Unmanned Aerial Vehicle (UAV) image footprints with PostGIS 3D

UAV photogrammetry in PostGIS – point cloud

UAV photogrammetry in PostGIS – orthorectification

UAV photogrammetry in PostGIS – DSM creation

PostGIS Programming


Writing PostGIS vector data with Psycopg

Writing PostGIS vector data with OGR Python bindings

Writing PostGIS functions with PL/Python

Geocoding and reverse-geocoding using the GeoNames datasets

Geocoding using the OSM datasets with trigrams

Geocoding with geopy and PL/Python

Importing netCDF datasets with Python and GDAL

PostGIS and the Web


Creating WMS and WFS services with MapServer

Creating WMS and WFS services with GeoServer

Creating a WMS Time with MapServer

Consuming WMS services with OpenLayers

Consuming WMS services with Leaflet

Consuming WFS-T services with OpenLayers

Developing web applications with GeoDjango – part 1

Developing web applications with GeoDjango – part 2

Maintenance, Optimization, and Performance Tuning


Organizing the database

Setting up the correct data privilege mechanism

Backing up the database

Using indexes

Clustering for efficiency

Optimizing SQL queries

Migrating a PostGIS database to a different server

Replicating a PostGIS database with streaming replication

Using Desktop Clients


Adding PostGIS layers – QGIS

Using the Database Manager plugin – QGIS

Adding PostGIS layers – OpenJUMP GIS

Running database queries – OpenJUMP GIS

Adding PostGIS layers – gvSIG

Adding PostGIS layers – uDig