Database Reference
In-Depth Information
Computing intersections
OnetypicalGISgeoprocessingworkflowistocomputeintersectionsgeneratedbyin-
tersecting 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
Downloadthe rivers datasetfromthefollowing naturalearthdata.com website
(or use the ZIP file included in the code bundle provided with this topic):
http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/
physical/10m-rivers-lake-centerlines.zip
Extracttheshapefiletoyourworkingdirectory, chp03/working .Importtheshapefile
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 toperform to complete this recipe are as follows:
1. First, perform a self-spatial join with your MultiLineString dataset with
thePostGIS ST_Intersects functionandfindintersectionsinthejoincon-
textwiththe ST_Intersection PostGISfunction.Thefollowingisthebasic
query, resulting in 1448 records being selected:
postgis_cookbook=# SELECT r1.gid AS gid1,
r2.gid AS
gid2,ST_AsText(ST_Intersection(r1.the_geom,
r2.the_geom)) AS the_geom
Search WWH ::




Custom Search