From 442a2c98e36abe9b660e56b2516afeb1afce51a4 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 12 Jan 2012 11:21:06 +0000 Subject: [PATCH] Fix bug in dimension computer for collection WKT. The parser got confused by inner M letters. This commit also improves speed early breaking the loop over WKT. git-svn-id: http://svn.osgeo.org/postgis/trunk@8788 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/cunit/cu_in_wkt.c | 19 +++++++++++++++++++ liblwgeom/lwin_wkt.c | 5 ++++- regress/wkb_expected | 12 ++++++------ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/liblwgeom/cunit/cu_in_wkt.c b/liblwgeom/cunit/cu_in_wkt.c index 17a9d5931..c992b8982 100644 --- a/liblwgeom/cunit/cu_in_wkt.c +++ b/liblwgeom/cunit/cu_in_wkt.c @@ -223,6 +223,25 @@ static void test_wkt_in_collection(void) //printf("\nIN: %s\nOUT: %s\n",s,r); CU_ASSERT_STRING_EQUAL(r,s); lwfree(r); + + s = "GEOMETRYCOLLECTION Z (POINT Z (0 0 0))"; + r = cu_wkt_in(s, WKT_ISO); + //printf("\nIN: %s\nOUT: %s\n",s,r); + CU_ASSERT_STRING_EQUAL(r,s); + lwfree(r); + + s = "GEOMETRYCOLLECTION M (MULTILINESTRING M ((0 0 5,2 0 5),(1 1 5,2 2 5)))"; + r = cu_wkt_in(s, WKT_ISO); + //printf("\nIN: %s\nOUT: %s\n",s,r); + CU_ASSERT_STRING_EQUAL(r,s); + lwfree(r); + + /* See http://trac.osgeo.org/postgis/ticket/1455#comment:3 */ + s = "GEOMETRYCOLLECTION Z (MULTILINESTRING Z ((0 0 5,2 0 5),(1 1 5,2 2 5)))"; + r = cu_wkt_in(s, WKT_ISO); + //printf("\nIN: %s\nOUT: %s\n",s,r); + CU_ASSERT_STRING_EQUAL(r,s); + lwfree(r); } static void test_wkt_in_circularstring(void) diff --git a/liblwgeom/lwin_wkt.c b/liblwgeom/lwin_wkt.c index 8f060c72d..0d14b81ab 100644 --- a/liblwgeom/lwin_wkt.c +++ b/liblwgeom/lwin_wkt.c @@ -10,6 +10,7 @@ **********************************************************************/ #include +#include /* for isspace */ #include "lwin_wkt.h" #include "lwin_wkt_parse.h" @@ -70,8 +71,10 @@ static uint8_t wkt_dimensionality(char *dimensionality) { if( (dimensionality[i] == 'Z') || (dimensionality[i] == 'z') ) FLAGS_SET_Z(flags,1); - if( (dimensionality[i] == 'M') || (dimensionality[i] == 'm') ) + else if( (dimensionality[i] == 'M') || (dimensionality[i] == 'm') ) FLAGS_SET_M(flags,1); + /* only a space is accepted in between */ + else if( ! isspace(dimensionality[i]) ) break; } return flags; } diff --git a/regress/wkb_expected b/regress/wkb_expected index 50bda618a..2943b4947 100644 --- a/regress/wkb_expected +++ b/regress/wkb_expected @@ -7,7 +7,7 @@ POINT Z (1 2 3)|01e9030000000000000000f03f00000000000000400000000000000840|t|000 POINT M (1 2 3)|01d1070000000000000000f03f00000000000000400000000000000840|t|00000007d13ff000000000000040000000000000004008000000000000 POINT ZM (1 2 3 4)|01b90b0000000000000000f03f000000000000004000000000000008400000000000001040|t|0000000bb93ff0000000000000400000000000000040080000000000004010000000000000 MULTIPOINT EMPTY|010400000000000000|t|000000000400000000 -MULTIPOINT Z EMPTY|01bc0b000000000000|t|0000000bbc00000000 +MULTIPOINT Z EMPTY|01ec03000000000000|t|00000003ec00000000 MULTIPOINT M EMPTY|01d407000000000000|t|00000007d400000000 MULTIPOINT ZM EMPTY|01bc0b000000000000|t|0000000bbc00000000 MULTIPOINT((0 0), (2 0))|010400000002000000010100000000000000000000000000000000000000010100000000000000000000400000000000000000|t|000000000400000002000000000100000000000000000000000000000000000000000140000000000000000000000000000000 @@ -15,7 +15,7 @@ MULTIPOINT Z ((0 0 0), (2 0 1))|01ec0300000200000001e903000000000000000000000000 MULTIPOINT M ((0 0 2), (2 0 1))|01d40700000200000001d107000000000000000000000000000000000000000000000000004001d107000000000000000000400000000000000000000000000000f03f|t|00000007d40000000200000007d100000000000000000000000000000000400000000000000000000007d1400000000000000000000000000000003ff0000000000000 MULTIPOINT ZM ((0 1 2 3), (3 2 1 0))|01bc0b00000200000001b90b00000000000000000000000000000000f03f0000000000000040000000000000084001b90b000000000000000008400000000000000040000000000000f03f0000000000000000|t|0000000bbc000000020000000bb900000000000000003ff0000000000000400000000000000040080000000000000000000bb9400800000000000040000000000000003ff00000000000000000000000000000 LINESTRING EMPTY|010200000000000000|t|000000000200000000 -LINESTRING Z EMPTY|01ba0b000000000000|t|0000000bba00000000 +LINESTRING Z EMPTY|01ea03000000000000|t|00000003ea00000000 LINESTRING M EMPTY|01d207000000000000|t|00000007d200000000 LINESTRING ZM EMPTY|01ba0b000000000000|t|0000000bba00000000 LINESTRING(0 0, 1 1)|01020000000200000000000000000000000000000000000000000000000000f03f000000000000f03f|t|000000000200000002000000000000000000000000000000003ff00000000000003ff0000000000000 @@ -23,7 +23,7 @@ LINESTRING Z (0 0 2, 1 1 3)|01ea030000020000000000000000000000000000000000000000 LINESTRING M (0 0 2, 1 1 3)|01d207000002000000000000000000000000000000000000000000000000000040000000000000f03f000000000000f03f0000000000000840|t|00000007d2000000020000000000000000000000000000000040000000000000003ff00000000000003ff00000000000004008000000000000 LINESTRING ZM (0 0 2 3, 1 1 4 5)|01ba0b0000020000000000000000000000000000000000000000000000000000400000000000000840000000000000f03f000000000000f03f00000000000010400000000000001440|t|0000000bba0000000200000000000000000000000000000000400000000000000040080000000000003ff00000000000003ff000000000000040100000000000004014000000000000 MULTILINESTRING EMPTY|010500000000000000|t|000000000500000000 -MULTILINESTRING Z EMPTY|01bd0b000000000000|t|0000000bbd00000000 +MULTILINESTRING Z EMPTY|01ed03000000000000|t|00000003ed00000000 MULTILINESTRING M EMPTY|01d507000000000000|t|00000007d500000000 MULTILINESTRING ZM EMPTY|01bd0b000000000000|t|0000000bbd00000000 MULTILINESTRING((0 0, 2 0))|0105000000010000000102000000020000000000000000000000000000000000000000000000000000400000000000000000|t|0000000005000000010000000002000000020000000000000000000000000000000040000000000000000000000000000000 @@ -32,7 +32,7 @@ MULTILINESTRING Z ((0 0 1, 2 0 2), (1 1 3, 2 2 4))|01ed0300000200000001ea0300000 MULTILINESTRING M ((0 0 1, 2 0 2), (1 1 3, 2 2 4))|01d50700000200000001d20700000200000000000000000000000000000000000000000000000000f03f00000000000000400000000000000000000000000000004001d207000002000000000000000000f03f000000000000f03f0000000000000840000000000000004000000000000000400000000000001040|t|00000007d50000000200000007d200000002000000000000000000000000000000003ff000000000000040000000000000000000000000000000400000000000000000000007d2000000023ff00000000000003ff00000000000004008000000000000400000000000000040000000000000004010000000000000 MULTILINESTRING ZM ((0 0 1 5, 2 0 2 4), (1 1 3 3, 2 2 4 2))|01bd0b00000200000001ba0b00000200000000000000000000000000000000000000000000000000f03f0000000000001440000000000000004000000000000000000000000000000040000000000000104001ba0b000002000000000000000000f03f000000000000f03f000000000000084000000000000008400000000000000040000000000000004000000000000010400000000000000040|t|0000000bbd000000020000000bba00000002000000000000000000000000000000003ff0000000000000401400000000000040000000000000000000000000000000400000000000000040100000000000000000000bba000000023ff00000000000003ff0000000000000400800000000000040080000000000004000000000000000400000000000000040100000000000004000000000000000 POLYGON EMPTY|010300000000000000|t|000000000300000000 -POLYGON Z EMPTY|01bb0b000000000000|t|0000000bbb00000000 +POLYGON Z EMPTY|01eb03000000000000|t|00000003eb00000000 POLYGON M EMPTY|01d307000000000000|t|00000007d300000000 POLYGON ZM EMPTY|01bb0b000000000000|t|0000000bbb00000000 POLYGON((0 0,1 0,1 1,0 1,0 0))|0103000000010000000500000000000000000000000000000000000000000000000000f03f0000000000000000000000000000f03f000000000000f03f0000000000000000000000000000f03f00000000000000000000000000000000|t|00000000030000000100000005000000000000000000000000000000003ff000000000000000000000000000003ff00000000000003ff000000000000000000000000000003ff000000000000000000000000000000000000000000000 @@ -41,7 +41,7 @@ POLYGON Z ((0 0 1,10 0 2 ,10 10 2,0 10 2,0 0 1),(2 2 5 ,2 5 4,5 5 3,5 2 3,2 2 5) POLYGON M ((0 0 1,10 0 2 ,10 10 2,0 10 2,0 0 1),(2 2 5 ,2 5 4,5 5 3,5 2 3,2 2 5))|01d3070000020000000500000000000000000000000000000000000000000000000000f03f00000000000024400000000000000000000000000000004000000000000024400000000000002440000000000000004000000000000000000000000000002440000000000000004000000000000000000000000000000000000000000000f03f05000000000000000000004000000000000000400000000000001440000000000000004000000000000014400000000000001040000000000000144000000000000014400000000000000840000000000000144000000000000000400000000000000840000000000000004000000000000000400000000000001440|t|00000007d30000000200000005000000000000000000000000000000003ff0000000000000402400000000000000000000000000004000000000000000402400000000000040240000000000004000000000000000000000000000000040240000000000004000000000000000000000000000000000000000000000003ff000000000000000000005400000000000000040000000000000004014000000000000400000000000000040140000000000004010000000000000401400000000000040140000000000004008000000000000401400000000000040000000000000004008000000000000400000000000000040000000000000004014000000000000 POLYGON ZM ((0 0 1 -1,10 0 2 -2,10 10 2 -2,0 10 2 -4,0 0 1 -1),(2 2 5 0,2 5 4 1,5 5 3 2,5 2 3 1,2 2 5 0))|01bb0b0000020000000500000000000000000000000000000000000000000000000000f03f000000000000f0bf00000000000024400000000000000000000000000000004000000000000000c000000000000024400000000000002440000000000000004000000000000000c000000000000000000000000000002440000000000000004000000000000010c000000000000000000000000000000000000000000000f03f000000000000f0bf050000000000000000000040000000000000004000000000000014400000000000000000000000000000004000000000000014400000000000001040000000000000f03f0000000000001440000000000000144000000000000008400000000000000040000000000000144000000000000000400000000000000840000000000000f03f0000000000000040000000000000004000000000000014400000000000000000|t|0000000bbb0000000200000005000000000000000000000000000000003ff0000000000000bff0000000000000402400000000000000000000000000004000000000000000c000000000000000402400000000000040240000000000004000000000000000c000000000000000000000000000000040240000000000004000000000000000c010000000000000000000000000000000000000000000003ff0000000000000bff00000000000000000000540000000000000004000000000000000401400000000000000000000000000004000000000000000401400000000000040100000000000003ff000000000000040140000000000004014000000000000400800000000000040000000000000004014000000000000400000000000000040080000000000003ff00000000000004000000000000000400000000000000040140000000000000000000000000000 MULTIPOLYGON EMPTY|010600000000000000|t|000000000600000000 -MULTIPOLYGON Z EMPTY|01be0b000000000000|t|0000000bbe00000000 +MULTIPOLYGON Z EMPTY|01ee03000000000000|t|00000003ee00000000 MULTIPOLYGON M EMPTY|01d607000000000000|t|00000007d600000000 MULTIPOLYGON ZM EMPTY|01be0b000000000000|t|0000000bbe00000000 MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(2 2,2 5,5 5,5 2,2 2)))|010600000001000000010300000002000000050000000000000000000000000000000000000000000000000024400000000000000000000000000000244000000000000024400000000000000000000000000000244000000000000000000000000000000000050000000000000000000040000000000000004000000000000000400000000000001440000000000000144000000000000014400000000000001440000000000000004000000000000000400000000000000040|t|000000000600000001000000000300000002000000050000000000000000000000000000000040240000000000000000000000000000402400000000000040240000000000000000000000000000402400000000000000000000000000000000000000000000000000054000000000000000400000000000000040000000000000004014000000000000401400000000000040140000000000004014000000000000400000000000000040000000000000004000000000000000 @@ -49,6 +49,6 @@ MULTIPOLYGON Z (((0 0 3,10 0 3,10 10 3,0 10 3,0 0 3),(2 2 3,2 5 3,5 5 3,5 2 3,2 MULTIPOLYGON M (((0 0 3,10 0 3,10 10 3,0 10 3,0 0 3),(2 2 3,2 5 3,5 5 3,5 2 3,2 2 3)))|01d60700000100000001d3070000020000000500000000000000000000000000000000000000000000000000084000000000000024400000000000000000000000000000084000000000000024400000000000002440000000000000084000000000000000000000000000002440000000000000084000000000000000000000000000000000000000000000084005000000000000000000004000000000000000400000000000000840000000000000004000000000000014400000000000000840000000000000144000000000000014400000000000000840000000000000144000000000000000400000000000000840000000000000004000000000000000400000000000000840|t|00000007d60000000100000007d3000000020000000500000000000000000000000000000000400800000000000040240000000000000000000000000000400800000000000040240000000000004024000000000000400800000000000000000000000000004024000000000000400800000000000000000000000000000000000000000000400800000000000000000005400000000000000040000000000000004008000000000000400000000000000040140000000000004008000000000000401400000000000040140000000000004008000000000000401400000000000040000000000000004008000000000000400000000000000040000000000000004008000000000000 MULTIPOLYGON ZM (((0 0 3 2,10 0 3 2,10 10 3 2,0 10 3 2,0 0 3 2),(2 2 3 2,2 5 3 2,5 5 3 2,5 2 3 2,2 2 3 2)))|01be0b00000100000001bb0b00000200000005000000000000000000000000000000000000000000000000000840000000000000004000000000000024400000000000000000000000000000084000000000000000400000000000002440000000000000244000000000000008400000000000000040000000000000000000000000000024400000000000000840000000000000004000000000000000000000000000000000000000000000084000000000000000400500000000000000000000400000000000000040000000000000084000000000000000400000000000000040000000000000144000000000000008400000000000000040000000000000144000000000000014400000000000000840000000000000004000000000000014400000000000000040000000000000084000000000000000400000000000000040000000000000004000000000000008400000000000000040|t|0000000bbe000000010000000bbb0000000200000005000000000000000000000000000000004008000000000000400000000000000040240000000000000000000000000000400800000000000040000000000000004024000000000000402400000000000040080000000000004000000000000000000000000000000040240000000000004008000000000000400000000000000000000000000000000000000000000000400800000000000040000000000000000000000540000000000000004000000000000000400800000000000040000000000000004000000000000000401400000000000040080000000000004000000000000000401400000000000040140000000000004008000000000000400000000000000040140000000000004000000000000000400800000000000040000000000000004000000000000000400000000000000040080000000000004000000000000000 GEOMETRYCOLLECTION EMPTY|010700000000000000|t|000000000700000000 -GEOMETRYCOLLECTION Z EMPTY|01bf0b000000000000|t|0000000bbf00000000 +GEOMETRYCOLLECTION Z EMPTY|01ef03000000000000|t|00000003ef00000000 GEOMETRYCOLLECTION M EMPTY|01d707000000000000|t|00000007d700000000 GEOMETRYCOLLECTION ZM EMPTY|01bf0b000000000000|t|0000000bbf00000000 -- 2.40.0