How to do it...

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

  1. First, investigate whether or not any geometry is invalid in the imported table. As you can see in the following query, using the ST_IsValid and ST_IsValidReason functions, we find four invalid geometries that are all invalid for the same reason—ring self-intersection:
      postgis_cookbook=# SELECT gid, name, ST_IsValidReason(the_geom) 
        FROM chp03.countries 
        WHERE ST_IsValid(the_geom)=false;
      (4 rows) 
  1. Now concentrate on just one of the invalid geometries, for example, in the multipolygon geometry representing Russia. Create a table containing just the ring ...

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.