From: Sandro Santilli Date: Thu, 5 May 2011 21:12:43 +0000 (+0000) Subject: Allow dumping polygons with empty rings, fixing bug #937, add unit testing for that... X-Git-Tag: 2.0.0alpha1~1706 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0b984b0582dbcc680b215d6c86a5f0d2e547886e;p=postgis Allow dumping polygons with empty rings, fixing bug #937, add unit testing for that case. git-svn-id: http://svn.osgeo.org/postgis/trunk@7102 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_out_wkb.c b/liblwgeom/cunit/cu_out_wkb.c index d2768fa7a..3cc3c2b35 100644 --- a/liblwgeom/cunit/cu_out_wkb.c +++ b/liblwgeom/cunit/cu_out_wkb.c @@ -48,6 +48,16 @@ static int clean_wkb_out_suite(void) return 0; } +static void cu_wkb_out_from_hexwkb(char *hexwkb) +{ + LWGEOM *g = lwgeom_from_hexwkb(hexwkb, PARSER_CHECK_NONE); + if ( s ) free(s); + if ( t ) free(t); + s = lwgeom_to_wkb(g, WKB_HEX | WKB_XDR | WKB_EXTENDED, NULL); + t = lwgeom_to_hexwkb_old(g, PARSER_CHECK_NONE, XDR); + lwgeom_free(g); +} + static void cu_wkb_out(char *wkt) { LWGEOM *g = lwgeom_from_ewkt(wkt, PARSER_CHECK_NONE); @@ -97,6 +107,13 @@ static void test_wkb_out_polygon(void) cu_wkb_out("POLYGON EMPTY"); // printf("new: %s\nold: %s\n",s,t); CU_ASSERT_STRING_EQUAL(s, t); + + /* + * POLYGON with EMPTY shell + * See http://http://trac.osgeo.org/postgis/ticket/937 + */ + cu_wkb_out_from_hexwkb("01030000000100000000000000"); + CU_ASSERT_STRING_EQUAL(s, t); } static void test_wkb_out_multipoint(void) diff --git a/liblwgeom/lwout_wkb.c b/liblwgeom/lwout_wkb.c index 58b9948d8..25cf1296f 100644 --- a/liblwgeom/lwout_wkb.c +++ b/liblwgeom/lwout_wkb.c @@ -310,8 +310,12 @@ static size_t ptarray_to_wkb_size(const POINTARRAY *pa, uchar variant) { int dims = 2; size_t size = 0; +#if 0 +/* see http://trac.osgeo.org/postgis/ticket/937 */ if ( pa->npoints < 1 ) return 0; +#endif + if ( variant & (WKB_ISO | WKB_EXTENDED) ) dims = FLAGS_NDIMS(pa->flags); @@ -331,12 +335,15 @@ static uchar* ptarray_to_wkb_buf(const POINTARRAY *pa, uchar *buf, uchar variant int i, j; double *dbl_ptr; +#if 0 +/* see http://trac.osgeo.org/postgis/ticket/937 */ /* Nothing to do with a pointarray with no ordinates */ if ( pa->npoints < 1 ) { - lwerror("Point array has < 1 ordinates!"); + lwnotice("Point array has < 1 ordinates!"); return buf; } +#endif /* SFSQL is always 2-d. Extended and ISO use all available dimensions */ if ( (variant & WKB_ISO) || (variant & WKB_EXTENDED) )