[postgis-users] Fixing invalid polygons created from polygonizing rasters

Martin Davis mbdavis at refractions.net
Wed Jan 14 11:04:36 PST 2009


You can try using buffer(0) on the geometry - this often fixes this kind 
of problem.

William Temperley wrote:
> Hi all,
>
> We have some polygonized rasters that create invalid GEOS geometries.
> Take polygon A I've attempted to illustrate below. It is one ring,
> which touches itself at a single point. In line with the OGC spec it
> is invalid. If it becomes two polygons, it is valid (See B I've
> illustrated below).
>
> It would be great if anyone knew of an algorithm to make A into B.
>
> Thanks
>
> Will
>
>
> ==============
> A
> ____
> |   __|___
> |   |__|    |
> |_______|
>
> MAP=# select isvalid(geomfromtext('MULTIPOLYGON(((0 0, 0 3, 2 3, 2 2,
> 1 2, 1 1, 2 1, 2 2, 3 2, 3 0, 0 0)))')
> );
> NOTICE:  Ring Self-intersection
>  isvalid
> ---------
>  f
>
> ===============
> B
> ____
> |  1__|___
> |__|__|    |
> |______2|
>
>
> MAP=# select isvalid(geomfromtext('MULTIPOLYGON(((0 0, 0 1, 2 1, 2 2,
> 3 2, 3 0, 0 0)),((0 1, 0 3, 2 3, 2 2, 1 2, 0 1)))')
> );
>  isvalid
> ---------
>  t
> (1 row)
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>   

-- 
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022




More information about the postgis-users mailing list