[postgis-devel] [PostGIS] #1855: 'SQL/MM Spatial exception - curve not simple' exception at adding two polygons

PostGIS trac at osgeo.org
Thu Jun 7 07:04:03 PDT 2012


#1855: 'SQL/MM Spatial exception - curve not simple' exception at adding two
polygons
----------------------+-----------------------------------------------------
 Reporter:  wimned    |       Owner:  strk         
     Type:  defect    |      Status:  new          
 Priority:  medium    |   Milestone:  PostGIS 2.0.1
Component:  topology  |     Version:  2.0.x        
 Keywords:            |  
----------------------+-----------------------------------------------------
 The code:
 {{{
 CREATE OR REPLACE FUNCTION testerror0()
  returns void AS
 $$
     declare geom0 geometry;
     declare geom1 geometry;
 BEGIN
     perform CreateTopology('wimpy', 4326, 0.00001);

     geom0 = ST_GeometryFromText(
         'POLYGON((76.26727 9.85751,76.29001 9.90026,
                 76.29942 9.86257,76.26727 9.85751))' , 4326);
     geom1 = ST_GeometryFromText(
         'POLYGON((76.31988 9.89696,76.30482 9.88391,
                 76.2941 9.88391,76.29409 9.88391,76.29409 9.88392,
                 76.29001 9.90026,76.31988 9.89696))' , 4326);
     perform topogeo_AddPolygon('wimpy', geom0);
     perform topogeo_AddPolygon('wimpy', geom1);
 END
 $$
 LANGUAGE plpgsql;
 }}}
 Raises the exception mentioned in the title.

 The curve is:
 {{{
 LINESTRING(76.2940920774741 9.88391,76.29409 9.88391,76.2940920774741
 9.88391)
 }}}

 Probable cause is a small triangular shaped overlap of the two polygons,
 about the size of the tolerance.
 Snapping leads to an edge of 3 points, begin and end point being the same.

 I'm using a nightly build from launchpad on my ubuntu box:

 deb http://ppa.launchpad.net/sharpie/postgis-nightly/ubuntu precise main

 I managed to edit a workaround in
 /usr/share/postgresql/9.1/contrib/postgis-2.1/topology.sql:

 In function ST_AddEdgeModFace() at the test of the curve being simple
 {{{
   IF NOT ST_IsSimple(acurve) THEN
     IF ST_NPoints(acurve) = 3 AND
 ST_Equals(ST_PointN(acurve,1),ST_PointN(acurve,1))
     THEN
         return 0; -- skip spike
     END IF;
     RAISE EXCEPTION 'SQL/MM Spatial exception - curve not simple %',
 ST_AsText(acurve);
   END IF;
 }}}

 Inspecting the code calling ST_AddEdgeModFace the return value must be
 checked, e.g. in TopoGeo_addLineString():

 {{{
     IF id IS NULL THEN
       id := topology.ST_AddEdgeModFace(atopology,start_node, end_node,
                                        snapped);
     ELSE
     END IF;

     if id != 0
     then
         RETURN NEXT id; --value 0 means invalid curve to be skipped
     end if;
 }}}

 These code changes result in the polygons to be entered into the topology
 properly. (though there is a small face between the two polygons).

 The change doesn't break much, the conversion would have been stopped
 anyhow by the exception

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/1855>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-devel mailing list