]> granicus.if.org Git - postgis/commitdiff
Require at least 8 edges to define a full circle (#2420)
authorSandro Santilli <strk@keybit.net>
Sun, 11 Aug 2013 15:55:50 +0000 (15:55 +0000)
committerSandro Santilli <strk@keybit.net>
Sun, 11 Aug 2013 15:55:50 +0000 (15:55 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@11769 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwsegmentize.c
regress/tickets.sql
regress/tickets_expected

index 4fa9671b96404f565f6bf871cbb339bab4326042..b7858f4e414b9fdb860eedb3c81dd1a02ac837fe 100644 (file)
@@ -16,6 +16,9 @@
 #include <string.h>
 
 #include "liblwgeom_internal.h"
+
+//#define POSTGIS_DEBUG_LEVEL 4
+
 #include "lwgeom_log.h"
 
 
@@ -551,9 +554,11 @@ pta_desegmentize(POINTARRAY *points, int type, int srid)
        int found_arc = LW_FALSE;
        int current_arc = 1;
        int num_edges;
-       int edge_type = -1;
+       int edge_type; /* non-zero if edge is part of an arc */
        int start, end;
        LWCOLLECTION *outcol;
+       /* Minimum number of edges, per quadrant, required to define an arc */
+       const unsigned int min_quad_edges = 2;
 
        /* Die on null input */
        if ( ! points )
@@ -608,6 +613,24 @@ pta_desegmentize(POINTARRAY *points, int type, int srid)
                /* Jump past all the edges that were added to the arc */
                if ( found_arc )
                {
+                       /* Check if an arc was composed by enough edges to be
+                        * really considered an arc
+                        * See http://trac.osgeo.org/postgis/ticket/2420
+                        */
+                       unsigned int arc_edges = j - 1 - i;
+                       unsigned int num_quadrants = 1; /* silly guess, TODO: compute */
+                       LWDEBUGF(4, "arc defined by %d edges found", arc_edges);
+                       if ( a1.x == b.x && a1.y == b.y ) {
+                               LWDEBUG(4, "arc is a circle");
+                               num_quadrants = 4;
+                       }
+                       /* a1 is first point, b is last point */
+                       if ( arc_edges < min_quad_edges * num_quadrants ) {
+                               LWDEBUGF(4, "Not enough edges for a %d quadrants arc", num_quadrants);
+                               for ( k = j-1; k >= i; k-- )
+                                       edges_in_arcs[k] = 0;
+                       }
+
                        i = j-1;
                }
                else
index d58ee794c6a7f8941c18edb85b7c2b117884ffda..c516b6d3a5fffade1c2d22dfb5183ee6aebc6111 100644 (file)
@@ -831,5 +831,7 @@ SELECT '#2415.2', ST_AsText(ST_Multi(
 
 SELECT '#2412', ST_AsText(ST_LineToCurve('LINESTRING(0 0,10 0,20 0)'));
 
+SELECT '#2430', ST_AsText(ST_LineToCurve('LINESTRING(0 0,10 0,10 10,0 10,0 0)'));
+
 -- Clean up
 DELETE FROM spatial_ref_sys;
index 1084bae7c6a8a310e7fbb57af2fbf6a4e36abca2..82130cf805dbfacd790ad675b67877feb29394ba 100644 (file)
@@ -247,3 +247,4 @@ ERROR:  invalid GML representation
 #2415.1|MULTICURVE(COMPOUNDCURVE((0 0,10 0),CIRCULARSTRING(10 0,15 1,20 10)))
 #2415.2|MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(10 0,15 1,20 0,18 5,20 10,10 10,10 0)))
 #2412|LINESTRING(0 0,10 0,20 0)
+#2430|LINESTRING(0 0,10 0,10 10,0 10,0 0)