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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.