[postgis-users] what to do about TopologyExceptions

strk strk at keybit.net
Mon Dec 20 02:54:06 PST 2010


On Mon, Dec 20, 2010 at 09:53:53AM +0100, David Kaplan wrote:
> Hi,
> 
> I am working with a GIS table that is derived from importing a fairly
> complex shapefile.  I want to do a number of union and difference
> operations, but I am encountering TopologyException problems and am
> wondering how much attention I need to pay to these exceptions and what
> is the best way to deal with these problems.
> 
> For example, upon doing a simple union operation, I have:
> 
> CREATE TABLE by_country_iucn AS
> SELECT min(ogc_fid) AS ogc_fid, country, iucn_cat, 
>        ST_Multi( ST_Union( wkb_geometry ) ) AS wkb_geometry
> FROM pol_2010
> GROUP BY country, iucn_cat
> ORDER BY country, iucn_cat;
> 
> I get the following exception at the end:
> 
> NOTICE:  TopologyException: side location conflict at 29.1972 0.251105
> 
> However, I am not sure what to do with this for two reasons:
> 
> 1) The point indicated in the exception (presuming this is a 2D point
> location) is located in the middle of nowhere and none of my polygons
> come anywhere near it (the nearest is >1000 km away).

I can see this is annoying. In fact that point only exists in a version
of the geometries which are internally translated closest to the origin
to increase precision. In turn this "precision imrovement" was triggered
by _another_ topology exception, which isn't printed unless whatever
is attempted later fails.

> 2) Looking at the result of the union, I don't see any obvious problems.
> Do these exceptions mean I am missing some part of the desired union?

It means the operation with the original geometries failed and was instead
conducted on a sligtly modified versions of them.

> For the union, this returns a result no problem, but for the difference
> operations that follow it, the query fails with no result after a
> similar exception.

That might mean nothing worked (precision reduction, snapping etc..)

> I saw in a previous thread that I should use ST_IsValid to test for
> problems.  I applied this to my shapefile and it found lots of results.
> Looking at the "bad" polygons, many look fine to the naked eye, but some
> do have strange things like internal lines.  Is there a good way to fix
> these?  ST_SimplifyPreserveTopology?  Will doing this help the other
> union and difference manipulations?

Often ST_Buffer(0) fixes it. Try it. If it doesn't, considere ST_MakeValid
(requires PostGIS svn).

--strk;

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html



More information about the postgis-users mailing list