You are previewing PostGIS Cookbook.
O'Reilly logo
PostGIS Cookbook

Book Description

For web developers and software architects this book will provide a vital guide to the tools and capabilities available to PostGIS spatial databases. Packed with hands-on recipes and powerful concepts.

In Detail

PostGIS is a spatial database that integrates advanced storage and analysis of vector and raster data, and is remarkably flexible and powerful. PostGIS provides support for geographic objects to the PostgreSQL object-relational database and is currently the most popular open source spatial databases. If you want to explore the complete range of PostGIS techniques and expose the related extensions, this book is a must-have.

This book is a deep-dive into the full range of PostGIS topics, with practical applications of the concepts and code. It is a comprehensive guide on PostGIS tools and concepts which are required to manage, manipulate, and analyse spatial data in PostGIS. This book is packed with systematic instructions of hands-on examples and in-depth explanations. Even for experienced users, this book will serve as a great source of reference by providing new ways of working with PostGIS through the book's easy-to-follow approach.

This hands-on guide looks at key spatial data manipulation tasks, explaining not only how each task is performed, but also why. It provides practical guidance allowing you to safely take advantage of the advanced technology in PostGIS in order to simplify your spatial database administration tasks.

This practical book will help you take advantage of basic and advanced vector, raster, and routing approaches. You will learn to use the concepts of data maintenance, optimization, and performance, which will help you to integrate these into a large ecosystem of desktop and web tools.

With this comprehensive guide, you will be armed with all the tools and instructions you need to both manage the spatial database system and make better decisions as your project's requirements evolve.

What You Will Learn

  • Import and export geographic data from the PostGIS database using the available tools
  • Structure spatial data using the functionality provided by the combination of PostgreSQL and PostGIS
  • Work with a set of PostGIS functions to perform basic and advanced vector analyses
  • Connect PostGIS with Python
  • Learn to use programming frameworks around PostGIS
  • Maintain, optimize, and fine-tune spatial data for long-term viability
  • Explore the 3D capabilities of PostGIS, including LiDAR point clouds and point clouds derived from Structure from Motion (SfM) techniques
  • Distribute 3D models through the Web using the X3D standard
  • Use PostGIS to develop powerful GIS web applications using Open Geospatial Consortium web standards
  • Master PostGIS Raster
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. PostGIS Cookbook
      1. Table of Contents
      2. PostGIS Cookbook
      3. Credits
      4. About the Authors
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Moving Data In and Out of PostGIS
        1. Introduction
        2. Importing nonspatial tabular data (CSV) using PostGIS functions
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Importing nonspatial tabular data (CSV) using GDAL
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Importing shapefiles with shp2pgsql
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Importing and exporting data with the ogr2ogr GDAL command
          1. How to do it...
          2. How it works...
          3. See also
        6. Handling batch importing and exporting of datasets
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Exporting data to the shapefile with the pgsql2shp PostGIS command
          1. How to do it...
          2. How it works...
        8. Importing OpenStreetMap data with the osm2pgsql command
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Importing raster data with the raster2pgsql PostGIS command
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Importing multiple rasters at a time
          1. Getting ready
          2. How to do it...
          3. How it works...
        11. Exporting rasters with the gdal_translate and gdalwarp GDAL commands
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      9. 2. Structures that Work
        1. Introduction
        2. Using geospatial views
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Using triggers to populate a geometry column
          1. Getting ready
          2. How to do it...
          3. There's more...
            1. Extending further...
          4. See also
        4. Structuring spatial data with table inheritance
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Extending inheritance – table partitioning
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Normalizing imports
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Normalizing internal overlays
          1. Getting ready
          2. How to do it...
            1. Converting polygons to linestrings
            2. Converting linestrings back to polygons
            3. Finding center points of resultant polygons
            4. Using resultant points to query tabular relationships
          3. How it works...
          4. There's more...
        8. Using polygon overlays for proportional census estimates
          1. Getting ready
          2. How to do it...
          3. How it works...
      10. 3. Working with Vector Data – The Basics
        1. Introduction
        2. Working with GPS data
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Fixing invalid geometries
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. GIS analysis with spatial joins
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Simplifying geometries
          1. How to do it...
          2. How it works...
        6. Measuring distances
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Merging polygons using a common attribute
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Computing intersections
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Clipping geometries to deploy data
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Simplifying geometries with PostGIS topology
          1. Getting ready
          2. How to do it...
          3. How it works...
      11. 4. Working with Vector Data – Advanced Recipes
        1. Introduction
        2. Improving proximity filtering with KNN
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Improving proximity filtering with KNN – advanced
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Rotating geometries
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Improving ST_Polygonize
          1. Getting ready
          2. How to do it...
          3. See also
        6. Translating, scaling, and rotating geometries – advanced
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Generating detailed building footprints from LiDAR
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Using external scripts to embed new functionality in order to calculate a Voronoi diagram
          1. Getting ready
          2. How to do it...
          3. See also
        9. Using external scripts to embed other libraries in order to calculate a Voronoi diagram – advanced
          1. Getting ready
          2. How to do it...
          3. There's more...
            1. Step zero – preparing the test table
            2. Step one – preparing the input text
            3. Step two – returning results
            4. Step three – bundling as a function
            5. Step four – translating into geometry
      12. 5. Working with Raster Data
        1. Introduction
        2. Getting and loading rasters
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Working with basic raster information and analysis
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Performing simple map-algebra operations
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Combining geometries with rasters for analysis
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Converting between rasters and geometries
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Processing and loading rasters with GDAL VRT
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Warping and resampling rasters
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Performing advanced map-algebra operations
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Executing DEM operations
          1. Getting ready
          2. How to do it...
          3. How it works...
        11. Sharing and visualizing rasters through SQL
          1. Getting ready
          2. How to do it...
          3. How it works...
      13. 6. Working with pgRouting
        1. Introduction
        2. Startup – Dijkstra routing
          1. Getting ready
          2. How to do it...
        3. Loading data from OpenStreetMap and finding the shortest path using A*
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Driving distance/service area calculation
          1. Getting ready
          2. How to do it...
          3. See also
        5. Calculating demographics using driving distance
          1. Getting ready
          2. How to do it...
        6. Extracting the centerlines of polygons
          1. Getting ready
          2. How to do it...
          3. There's more...
      14. 7. Into the Nth Dimension
        1. Introduction
        2. Importing LiDAR data
          1. Getting ready
          2. How to do it...
          3. See also
        3. Performing 3D queries on a LiDAR point cloud
          1. How to do it...
        4. Constructing and serving buildings 2.5 D
          1. Getting ready
          2. How to do it...
        5. Using ST_Extrude to extrude building footprints
        6. Creating arbitrary 3D objects for PostGIS
          1. Getting ready
          2. How to do it...
        7. Exporting models as X3D for the Web
          1. Getting ready
          2. How to do it...
          3. There's more...
        8. Reconstructing Unmanned Aerial Vehicle (UAV) image footprints with PostGIS 3D
          1. Getting ready
          2. How to do it...
        9. UAV photogrammetry in PostGIS – point cloud
          1. Getting ready
          2. How to do it...
        10. UAV photogrammetry in PostGIS – orthorectification
          1. Getting ready
          2. How to do it...
            1. Converting the point cloud to Voronoi polygons
            2. Attributing polygons with the color
            3. Rendering polygons to raster
        11. UAV photogrammetry in PostGIS – DSM creation
          1. Getting ready
          2. How it works...
      15. 8. PostGIS Programming
        1. Introduction
        2. Writing PostGIS vector data with Psycopg
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Writing PostGIS vector data with OGR Python bindings
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Writing PostGIS functions with PL/Python
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Geocoding and reverse-geocoding using the GeoNames datasets
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Geocoding using the OSM datasets with trigrams
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Geocoding with geopy and PL/Python
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Importing netCDF datasets with Python and GDAL
          1. Getting ready
          2. How to do it...
          3. How it works...
      16. 9. PostGIS and the Web
        1. Introduction
        2. Creating WMS and WFS services with MapServer
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Creating WMS and WFS services with GeoServer
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Creating a WMS Time with MapServer
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Consuming WMS services with OpenLayers
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Consuming WMS services with Leaflet
          1. How to do it...
          2. How it works...
        7. Consuming WFS-T services with OpenLayers
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Developing web applications with GeoDjango – part 1
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Developing web applications with GeoDjango – part 2
          1. Getting ready
          2. How to do it...
          3. How it works...
      17. 10. Maintenance, Optimization, and Performance Tuning
        1. Introduction
        2. Organizing the database
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Setting up the correct data privilege mechanism
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Backing up the database
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Using indexes
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Clustering for efficiency
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Optimizing SQL queries
          1. Getting ready
          2. How to do it...
          3. How it works...
        8. Migrating a PostGIS database to a different server
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Replicating a PostGIS database with streaming replication
          1. Getting ready
          2. How to do it...
          3. How it works...
      18. 11. Using Desktop Clients
        1. Introduction
        2. Adding PostGIS layers – QGIS
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Using the Database Manager plugin – QGIS
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Adding PostGIS layers – OpenJUMP GIS
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Running database queries – OpenJUMP GIS
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Adding PostGIS layers – gvSIG
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Adding PostGIS layers – uDig
          1. How to do it...
          2. How it works...
      19. Index