Automatically fixing ring self-intersections in shp2pgsql

lambshaanxy picture lambshaanxy · Aug 10, 2012 · Viewed 9.9k times · Source

We're importing a whole bunch of ArcGIS shapefiles into PostGIS, converted on the fly with shp2pgsql. Problem is, if the shapefiles have any ring self-intersections, the import chokes:

NOTICE:  Ring Self-intersection at or near point -80.1338 25.8102
ERROR:  new row for relation "place_shapes" violates
  check constraint "shape_is_valid"

How can we fix this?

Answer

Marcelo picture Marcelo · Aug 11, 2012

This query often fixes it for me:

UPDATE place_shapes
  SET geometry=ST_Buffer(geometry, 0.0);