Skip to content
 

Check for Validity

SELECT 
  name, state_name, fips, 
  st_summary(the_geom), 
  st_isvalidreason(the_geom) 
FROM usa_counties 
  WHERE not st_isvalid(the_geom);
NOTICE:  Ring Self-intersection at or near point -70.82466 42.26050
-[ RECORD 1 ]----+-------------------------------------------------
name             | Plymouth
state_name       | Massachusetts
fips             | 25023
st_summary       | MultiPolygon[B] with 1 elements
                 |   Polygon[] with 1 rings
                 |    ring 0 has 31 points
st_isvalidreason | Ring Self-intersection[-70.8246609058028 42.2605069326982]

Time: 268.654 ms
UPDATE usa_counties 
  set the_geom = ST_MakeValid(the_geom) where name='Plymouth' and fips = '25023'; 

SELECT 
  name, state_name, fips, 
  st_summary(the_geom), st_isvalidreason(the_geom) 
FROM usa_counties where not st_isvalid(the_geom); 

 name | state_name | fips | st_summary | st_isvalidreason
------+------------+------+------------+------------------ 
(0 rows) 


select postgis_version();
            postgis_version            
---------------------------------------
 2.0 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)


  examples of invalid multipolygon