From: Regina Obe Date: Sat, 4 May 2013 13:18:40 +0000 (+0000) Subject: #2295 Nathan Wagner patch to support for dumping circular strings in dump points X-Git-Tag: 2.1.0beta2~65 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4364f7ad7c013276c00bcf26355ea5c8f8f90ee2;p=postgis #2295 Nathan Wagner patch to support for dumping circular strings in dump points git-svn-id: http://svn.osgeo.org/postgis/trunk@11349 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 32065ba43..fb20b5f8d 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -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); diff --git a/liblwgeom/lwcircstring.c b/liblwgeom/lwcircstring.c index d5aff562a..247439b39 100644 --- a/liblwgeom/lwcircstring.c +++ b/liblwgeom/lwcircstring.c @@ -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; +} diff --git a/postgis/lwgeom_dumppoints.c b/postgis/lwgeom_dumppoints.c index 9559cb100..17fb2c601 100644 --- a/postgis/lwgeom_dumppoints.c +++ b/postgis/lwgeom_dumppoints.c @@ -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 diff --git a/regress/dumppoints_expected b/regress/dumppoints_expected index a2b384fa9..a1e9fc2a8 100644 --- a/regress/dumppoints_expected +++ b/regress/dumppoints_expected @@ -82,5 +82,21 @@ {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)