Book Image

PostGIS Cookbook

Book Image

PostGIS Cookbook

Overview of this book

Table of Contents (18 chapters)
PostGIS Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Computing intersections


One typical GIS geoprocessing workflow is to compute intersections generated by intersecting linear geometries.

PostGIS offers a rich set of functions for solving this particular type of problem and you will have a look at them in this recipe.

Getting ready

Download the rivers dataset from the following naturalearthdata.com website (or use the ZIP file included in the code bundle provided with this book):

http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/10m-rivers-lake-centerlines.zip

Extract the shapefile to your working directory, chp03/working. Import the shapefile in PostGIS using shp2pgsql as follows:

$ shp2pgsql -I -W LATIN1 -s 4326 -g the_geom ne_10m_rivers_lake_centerlines.shp chp03.rivers > rivers.sql
$ psql -U me -d postgis_cookbook -f rivers.sql

How to do it...

The steps you need to perform to complete this recipe are as follows:

  1. First, perform a self-spatial join with your MultiLineString dataset with the PostGIS ST_Intersects...