[postgis-users] what to do about TopologyExceptions
David Kaplan
david.kaplan at ird.fr
Thu Dec 23 04:26:13 PST 2010
Hi,
I thought I had everything figured out with respect to my problems
unioning and differencing polygons, but I am running into more
TopologyExceptions that have me confused.
After looking at Paul Ramsey's FOSS4G presentation, I realized that what
I really wanted to do was an "ArcGIS Union Operation" - i.e. reducing a
set of overlapping polygons into all possible combinations of overlaps.
My table consists of a set of MULTIPOLYGONs that sometimes overlap. I
used ST_Buffer(0) to force them to be valid polygons (and checked this
worked correctly). Then I did the following to reduce every polygon to
just the LINESTRINGs that define them:
SELECT ST_ExteriorRing((ST_DumpRings((ST_Dump(wkb_geometry)).geom)).geom) AS geom
INTO TEMP TABLE ht1 FROM my_geo_table;
Note that I added ST_ExteriorRing to ST_DumpRings to reduce polygons to
linestrings. Is this correct?
Then I wanted to union these linestrings to assure that they have all
the nodes at overlaps, but I keep getting a TopologyException:
SELECT ST_Union(geom) AS geom INTO TEMP TABLE ht2 FROM ht1;
NOTICE: TopologyException: found non-noded intersection between LINESTRING (-165.443 23.1836, -165.443 23.1836) and LINESTRING (-165.443 23.1836, -165.464 23.2079) at -165.443 23.1836
ERROR: GEOS union() threw an error!
Presuming the coordinates given are actual geographic coordinates, it
appears that this problem occurs at a location that two different
linestrings just barely overlap (see attached image). Is this a
postgis / GEOS problem or is there something that I am doing that is
conceptually wrong? In either case, is there a way to move forward?
The next steps in the process would be to use ST_Polygonize to get back
a bunch of polygons, ST_PointOnSurface to find interior points and
ST_Intersects to find the original polygons these points belonged to.
Thanks again for the help.
Cheers,
David
On Mon, 2010-12-20 at 17:49 +0100, Peter Hopfgartner wrote:
> AFAIK there are slightly different definitions of valid polygon between shape files and PostGIS/Simple Features.
> Paul Ramsey had a talk on a number of tricks to correct those problems (and some more):
> http://2010.foss4g.org/presentations_show.php?id=3369.
>
> Peter Hopfgartner
>
> R3 GIS Srl - GmbH
> http://www.r3-gis.com
>
>
> --------David Kaplan <david.kaplan at ird.fr> wrote--------
> Subject: [postgis-users] what to do about TopologyExceptions
> Date: 20.12.2010 09:54
>
> >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).
> >
> >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?
> >
> >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.
> >
> >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?
> >
> >Thanks for the help.
> >
> >Cheers,
> >David
> >
> >--
> >**********************************
> >David M. Kaplan
> >Charge de Recherche 1
> >
> >Institut de Recherche pour le Developpement
> >Centre de Recherche Halieutique Mediterraneenne et Tropicale
> >av. Jean Monnet
> >B.P. 171
> >34203 Sete cedex
> >France
> >
> >Phone: +33 (0)4 99 57 32 27
> >Fax: +33 (0)4 99 57 32 95
> >
> >http://www.ur097.ird.fr/team/dkaplan/index.html
> >http://www.amped.ird.fr/
> >**********************************
> >
> >
> >_______________________________________________
> >postgis-users mailing list
> >postgis-users at postgis.refractions.net
> >http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
>
--
**********************************
David M. Kaplan
Charge de Recherche 1
Institut de Recherche pour le Developpement
Centre de Recherche Halieutique Mediterraneenne et Tropicale
av. Jean Monnet
B.P. 171
34203 Sete cedex
France
Phone: +33 (0)4 99 57 32 27
Fax: +33 (0)4 99 57 32 95
http://www.ur097.ird.fr/team/dkaplan/index.html
http://www.amped.ird.fr/
**********************************
-------------- next part --------------
A non-text attachment was scrubbed...
Name: linestring.union.prob.png
Type: image/png
Size: 14379 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20101223/0300f061/attachment.png>
More information about the postgis-users
mailing list