[postgis-users] Invalid Geometries from shapefiles

Paul Ramsey pramsey at refractions.net
Wed Feb 7 09:52:42 PST 2007


If someone wants to fun CleanGeometry(), I am all ears :)  There is no 
magic bullet to make invalid geometries valid, but invalidities tend to 
fall in a few major categories, so a CleanGeometry() could be fairly 
effective.

In the meantime, do this, perhaps:

update yourtable set the_geom = buffer(the_geom,0.0) where not 
isvalid(the_geom);

If that doesn't work, try running a snaptogrid() inside the buffer with 
a very small tolerance.  Both buffer and snaptogrid tend to squash out 
invalidities, in many (but not all) cases.

Paul

Bruce Rindahl wrote:
> I have an application that stores floodplains in a PostGIS database for
> later display in a web mapping application.  The floodplains are derived
> from shapefiles and are converted using shp2pgsql.  The issue is some of the
> shapes are invalid when converted to the geometry format in PostGIS.  When
> these invalid geometries are manipulated by certain operators, the results
> are not as expected (for example intersection returns a geometry collection
> instead of a multipolygon).
> Are there some guidelines or things to look for in shapefiles to assure the
> geometry is valid?  Most of the problems occur when a polygon has an
> interior island.  All of the tools we are using accepts these shapefiles as
> valid but will cause problems when converted.
> Thanks


-- 

   Paul Ramsey
   Refractions Research
   http://www.refractions.net
   pramsey at refractions.net
   Phone: 250-383-3022
   Cell: 250-885-0632



More information about the postgis-users mailing list