]> granicus.if.org Git - postgis/commitdiff
#2295 Nathan Wagner patch to support for dumping circular strings in dump points
authorRegina Obe <lr@pcorp.us>
Sat, 4 May 2013 13:18:40 +0000 (13:18 +0000)
committerRegina Obe <lr@pcorp.us>
Sat, 4 May 2013 13:18:40 +0000 (13:18 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@11349 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom.h.in
liblwgeom/lwcircstring.c
postgis/lwgeom_dumppoints.c
regress/dumppoints_expected

index 32065ba43659936eff145d5bc2aa92b427db6416..fb20b5f8dde7b9a4f79e837aad5ccb09df72e04e 100644 (file)
@@ -1065,6 +1065,7 @@ extern void lwgeom_affine(LWGEOM *geom, const AFFINE *affine);
 extern int lwgeom_dimension(const LWGEOM *geom);
 
 extern LWPOINT* lwline_get_lwpoint(LWLINE *line, int where);
+extern LWPOINT* lwcircstring_get_lwpoint(LWCIRCSTRING *circ, int where);
 
 extern double ptarray_length_2d(const POINTARRAY *pts);
 extern double ptarray_length(const POINTARRAY *pts);
index d5aff562ae65b6a5f0279a96eb37b6aa80540e3b..247439b396a8d35f0b55416075a57697d8b60254 100644 (file)
@@ -290,3 +290,22 @@ double lwcircstring_length_2d(const LWCIRCSTRING *circ)
        lwline_free(line);
        return length;
 }
+
+/*
+ * Returns freshly allocated #LWPOINT that corresponds to the index where.
+ * Returns NULL if the geometry is empty or the index invalid.
+ */
+LWPOINT* lwcircstring_get_lwpoint(LWCIRCSTRING *circ, int where) {
+       POINT4D pt;
+       LWPOINT *lwpoint;
+       POINTARRAY *pa;
+
+       if ( lwcircstring_is_empty(circ) || where < 0 || where >= circ->points->npoints )
+               return NULL;
+
+       pa = ptarray_construct_empty(FLAGS_GET_Z(circ->flags), FLAGS_GET_M(circ->flags), 1);
+       pt = getPoint4d(circ->points, where);
+       ptarray_append_point(pa, &pt, LW_TRUE);
+       lwpoint = lwpoint_construct(circ->srid, NULL, pa);
+       return lwpoint;
+}
index 9559cb100a94e9e93d8a44198ec978d56159d7d5..17fb2c601e23e73817825ecee6e58ee1ba5a86b8 100644 (file)
@@ -130,6 +130,7 @@ Datum LWGEOM_dumppoints(PG_FUNCTION_ARGS) {
                         * probably not worth the bother
                         */
                        LWLINE  *line;
+                       LWCIRCSTRING *circ;
                        LWPOLY  *poly;
                        LWTRIANGLE      *tri;
                        LWPOINT *lwpoint = NULL;
@@ -198,11 +199,14 @@ Datum LWGEOM_dumppoints(PG_FUNCTION_ARGS) {
                                        }
                                        break;
                                case CIRCSTRINGTYPE:
-                                       ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
-                                               errmsg("Invalid Geometry type circstring passed to ST_DumpPoints()")));
+                                       circ = lwgeom_as_lwcircstring(lwgeom);
+                                       if (circ->points && state->pt <= circ->points->npoints) {
+                                               lwpoint = lwcircstring_get_lwpoint((LWCIRCSTRING*)lwgeom, state->pt);
+                                       }
+                                       break;
                                default:
                                        ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
-                                               errmsg("Invalid Geometry type passed to ST_DumpPoints()")));
+                                               errmsg("Invalid Geometry type %d passed to ST_DumpPoints()", lwgeom->type)));
                        }
 
                        /*
@@ -276,5 +280,6 @@ Datum LWGEOM_dumppoints(PG_FUNCTION_ARGS) {
         case MULTISURFACETYPE:
         case POLYHEDRALSURFACETYPE:
         case TINTYPE:
+
 #endif
 
index a2b384fa9640dc07a29ae701c2a8dbd1a27a1e46..a1e9fc2a803b5c5b39c010ab8f0006847d5a645a 100644 (file)
 {5,1,2,2}|POINT(5 6)
 {5,1,2,3}|POINT(6 6)
 {5,1,2,4}|POINT(5 5)
-ERROR:  Invalid Geometry type circstring passed to ST_DumpPoints()
-ERROR:  Invalid Geometry type circstring passed to ST_DumpPoints()
+{1,1}|POINT(-71.0821 42.3036)
+{1,2}|POINT(-71.4821 42.3036)
+{1,3}|POINT(-71.7821 42.7036)
+{1,4}|POINT(-71.0821 42.7036)
+{1,5}|POINT(-71.0821 42.3036)
+{2,1}|POINT(-71.1821 42.4036)
+{2,2}|POINT(-71.3821 42.6036)
+{2,3}|POINT(-71.3821 42.4036)
+{2,4}|POINT(-71.1821 42.4036)
+{1,1}|POINT(0 0)
+{1,2}|POINT(4 0)
+{1,3}|POINT(4 4)
+{1,4}|POINT(0 4)
+{1,5}|POINT(0 0)
+{2,1}|POINT(1 1)
+{2,2}|POINT(3 3)
+{2,3}|POINT(3 1)
+{2,4}|POINT(1 1)