How to do it...

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

  1. First, perform a self-spatial join between your MultiLineString dataset and the PostGIS ST_Intersects function and find intersections in the join context with the ST_Intersection PostGIS function. The following is the basic query, resulting in 1,448 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 
      FROM chp03.rivers r1 
      JOIN chp03.rivers r2 
      ON ST_Intersects(r1.the_geom, r2.the_geom) 
      WHERE r1.gid != r2.gid; 
  1. You may hastily assume that all of the intersections are single points, but this is not the case; if you check the geometry type of the geometric intersections ...

Get PostGIS Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.