Commit 4cc41233 authored by Paul Ramsey's avatar Paul Ramsey

Replace the old WKB/WKT parser and emitters with the new ones.


git-svn-id: http://svn.osgeo.org/postgis/trunk@6291 b70326c6-7e19-0410-871a-916f4a2858ee
parent 6c9ea49d
......@@ -836,7 +836,7 @@ static void test_isclosed(void)
/* COMPOUNDCURVE */
/* Not Closed on 2D */
geom = lwgeom_from_ewkt("COMPOUNDCURVE(CIRCULARSTRING(1 2,3 4,1 2),(5 6,7 8,5 6))", PARSER_CHECK_NONE);
geom = lwgeom_from_ewkt("COMPOUNDCURVE(CIRCULARSTRING(1 2,3 4,1 2),(1 2,7 8,5 6))", PARSER_CHECK_NONE);
CU_ASSERT(!lwcompound_is_closed((LWCOMPOUND *) geom));
lwfree(geom);
......
......@@ -840,8 +840,8 @@ static void test_lwgeom_distance_sphere(void)
lwgeom_free(lwg2);
/* Medford test case #1 */
lwg1 = lwgeom_from_ewkt("0105000020E610000001000000010200000002000000EF7B8779C7BD5EC0FD20D94B852845400E539C62B9BD5EC0F0A5BE767C284540", PARSER_CHECK_NONE);
lwg2 = lwgeom_from_ewkt("0106000020E61000000100000001030000000100000007000000280EC3FB8CCA5EC0A5CDC747233C45402787C8F58CCA5EC0659EA2761E3C45400CED58DF8FCA5EC0C37FAE6E1E3C4540AE97B8E08FCA5EC00346F58B1F3C4540250359FD8ECA5EC05460628E1F3C45403738F4018FCA5EC05DC84042233C4540280EC3FB8CCA5EC0A5CDC747233C4540", PARSER_CHECK_NONE);
lwg1 = lwgeom_from_hexwkb("0105000020E610000001000000010200000002000000EF7B8779C7BD5EC0FD20D94B852845400E539C62B9BD5EC0F0A5BE767C284540", PARSER_CHECK_NONE);
lwg2 = lwgeom_from_hexwkb("0106000020E61000000100000001030000000100000007000000280EC3FB8CCA5EC0A5CDC747233C45402787C8F58CCA5EC0659EA2761E3C45400CED58DF8FCA5EC0C37FAE6E1E3C4540AE97B8E08FCA5EC00346F58B1F3C4540250359FD8ECA5EC05460628E1F3C45403738F4018FCA5EC05DC84042233C4540280EC3FB8CCA5EC0A5CDC747233C4540", PARSER_CHECK_NONE);
d = lwgeom_distance_spheroid(lwg1, lwg2, &s, 0.0);
CU_ASSERT_DOUBLE_EQUAL(d, 23630.8003, 0.1);
lwgeom_free(lwg1);
......
......@@ -50,52 +50,56 @@ static int clean_wkb_in_suite(void)
static void cu_wkb_in(char *wkt)
{
LWGEOM *g, *g_a, *g_b;
char *wkb;
size_t wkb_size, wkb_size_a, wkb_size_b;
LWGEOM_PARSER_RESULT pr;
LWGEOM *g_a, *g_b;
uchar *wkb_a, *wkb_b;
size_t wkb_size_a, wkb_size_b;
/* int i; char *hex; */
if ( hex_a ) free(hex_a);
if ( hex_b ) free(hex_b);
/* Turn WKT into geom */
g = lwgeom_from_ewkt(wkt, PARSER_CHECK_NONE);
lwgeom_from_wkt(&pr, wkt, PARSER_CHECK_NONE);
if ( pr.errcode )
{
printf("ERROR: %s\n", pr.message);
printf("POSITION: %d\n", pr.errlocation);
exit(0);
}
/* Get the geom */
g_a = pr.geom;
/* Turn geom into WKB */
wkb = lwgeom_to_wkb(g, WKB_NDR | WKB_EXTENDED, &wkb_size);
/* Flip WKB into hex for string comparisons
hex = lwalloc(2*wkb_size+1);
for (i=0; i<wkb_size; i++)
deparse_hex(wkb[i], &hex[i*2]);
hex[2*wkb_size] = '\0';
printf("%s\n",hex);
lwfree(hex); */
/* Turn WKB back into geom with old function */
g_a = lwgeom_from_ewkb((uchar*)wkb, 0, wkb_size);
/* Turn WKB back into geom with new function */
g_b = lwgeom_from_wkb((uchar*)wkb, wkb_size, 0);
wkb_a = lwgeom_to_wkb(g_a, WKB_NDR | WKB_EXTENDED, &wkb_size_a);
/* Turn WKB back into geom */
g_b = lwgeom_from_wkb(wkb_a, wkb_size_a, PARSER_CHECK_NONE);
/* Turn geom to WKB again */
wkb_b = lwgeom_to_wkb(g_b, WKB_NDR | WKB_EXTENDED, &wkb_size_b);
/* Turn geoms into WKB for comparisons */
hex_a = lwgeom_to_wkb(g_a, WKB_HEX | WKB_NDR | WKB_EXTENDED, &wkb_size_a);
hex_b = lwgeom_to_wkb(g_b, WKB_HEX | WKB_NDR | WKB_EXTENDED, &wkb_size_b);
hex_a = hexbytes_from_bytes(wkb_a, wkb_size_a);
hex_b = hexbytes_from_bytes(wkb_b, wkb_size_b);
/* Clean up */
lwfree(wkb);
lwgeom_free(g);
lwgeom_free(g_a);
lwfree(wkb_a);
lwfree(wkb_b);
lwgeom_parser_result_free(&pr);
lwgeom_free(g_b);
}
static void test_wkb_in_point(void)
{
cu_wkb_in("POINT(0 0 0 0)");
CU_ASSERT_STRING_EQUAL(hex_a, hex_b);
// printf("old: %s\nnew: %s\n",hex_a, hex_b);
CU_ASSERT_STRING_EQUAL(hex_a, hex_b);
cu_wkb_in("SRID=4;POINTM(1 1 1)");
CU_ASSERT_STRING_EQUAL(hex_a, hex_b);
// printf("old: %s\nnew: %s\n",hex_a, hex_b);
CU_ASSERT_STRING_EQUAL(hex_a, hex_b);
}
static void test_wkb_in_linestring(void)
......@@ -124,7 +128,7 @@ static void test_wkb_in_polygon(void)
static void test_wkb_in_multipoint(void)
{
cu_wkb_in("SRID=4;MULTIPOINT(0 0 0,0 1 0,1 1 0,1 0 0,0 0 ))");
cu_wkb_in("SRID=4;MULTIPOINT(0 0 0,0 1 0,1 1 0,1 0 0,0 0 1)");
CU_ASSERT_STRING_EQUAL(hex_a, hex_b);
cu_wkb_in("MULTIPOINT(0 0 0, 0.26794919243112270647255365849413 1 3)");
......@@ -148,7 +152,7 @@ static void test_wkb_in_collection(void)
cu_wkb_in("GEOMETRYCOLLECTION EMPTY");
CU_ASSERT_STRING_EQUAL(hex_a, hex_b);
cu_wkb_in("SRID=14;GEOMETRYCOLLECTION(MULTIPOLYGON(POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))),POINT(1 1 1),LINESTRING(0 0 0, 1 1 1))");
cu_wkb_in("SRID=14;GEOMETRYCOLLECTION(MULTIPOLYGON(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))),POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),POINT(1 1 1),LINESTRING(0 0 0, 1 1 1))");
CU_ASSERT_STRING_EQUAL(hex_a, hex_b);
}
......
......@@ -66,6 +66,11 @@ static char* cu_wkt_in(char *wkt, uchar variant)
static void test_wkt_in_point(void)
{
s = "POINT(1e700 0)";
r = cu_wkt_in(s, WKT_SFSQL);
CU_ASSERT_STRING_EQUAL(r,"POINT(inf 0)");
lwfree(r);
s = "POINT(0 0)";
r = cu_wkt_in(s, WKT_SFSQL);
CU_ASSERT_STRING_EQUAL(r,s);
......@@ -80,6 +85,8 @@ static void test_wkt_in_point(void)
r = cu_wkt_in(s, WKT_ISO);
CU_ASSERT_STRING_EQUAL(r,s);
lwfree(r);
//printf("\nIN: %s\nOUT: %s\n",s,r);
}
static void test_wkt_in_linestring(void)
......@@ -132,6 +139,13 @@ static void test_wkt_in_polygon(void)
static void test_wkt_in_multipoint(void)
{
s = "MULTIPOINT(-1 -2 -3,5.4 6.6 7.77,-5.4 -6.6 -7.77,1000000 1e-06 -1000000,-1.3e-06 -1.4e-05 0)";
r = cu_wkt_in(s, WKT_EXTENDED);
CU_ASSERT_STRING_EQUAL(r,s);
//printf("\nIN: %s\nOUT: %s\n",s,r);
lwfree(r);
s = "MULTIPOINT(0 0)";
r = cu_wkt_in(s, WKT_SFSQL);
CU_ASSERT_STRING_EQUAL(r,s);
......@@ -203,7 +217,13 @@ static void test_wkt_in_circularstring(void)
static void test_wkt_in_compoundcurve(void)
{
s = "COMPOUNDCURVE Z (CIRCULARSTRING Z (0 0 0,0 1 0,1 1 0,0 0 0,2 2 0),(0 0 1,1 1 1,2 2 1))";
s = "SRID=4326;COMPOUNDCURVEM(CIRCULARSTRING(0 0 2,1 1 2,1 0 2),(1 0 2,0 1 2))";
r = cu_wkt_in(s, WKT_EXTENDED);
CU_ASSERT_STRING_EQUAL(r,s);
//printf("\nIN: %s\nOUT: %s\n",s,r);
lwfree(r);
s = "COMPOUNDCURVE Z (CIRCULARSTRING Z (0 0 0,0 1 0,1 1 0,0 0 0,2 2 0),(2 2 0,0 0 1,1 1 1,2 2 1))";
r = cu_wkt_in(s, WKT_ISO);
CU_ASSERT_STRING_EQUAL(r,s);
//printf("\nIN: %s\nOUT: %s\n",s,r);
......@@ -212,7 +232,7 @@ static void test_wkt_in_compoundcurve(void)
static void test_wkt_in_curvpolygon(void)
{
s = "CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(0 0,0 1,1 1,0 0,2 2),(0 0,1 1,2 2)),CIRCULARSTRING(0 0,0 1,1 1,0 0,2 2),(0 0,1 1,2 1))";
s = "CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING(0 0,0 1,1 1,2 2,0 0),(0 0,1 1,2 2)),CIRCULARSTRING(0 0,0 1,1 1,0 0,2 2),(0 0,1 1,2 1))";
r = cu_wkt_in(s, WKT_ISO);
CU_ASSERT_STRING_EQUAL(r,s);
//printf("\nIN: %s\nOUT: %s\n",s,r);
......
......@@ -306,22 +306,22 @@ static void test_lwgeom_free(void)
/* Empty geometries don't seem to free properly (#370) */
geom = lwgeom_from_ewkt("GEOMETRYCOLLECTION EMPTY", PARSER_CHECK_NONE);
CU_ASSERT_EQUAL(TYPE_GETTYPE(geom->type), COLLECTIONTYPE);
CU_ASSERT_EQUAL(geom->type, COLLECTIONTYPE);
lwgeom_free(geom);
/* Empty geometries don't seem to free properly (#370) */
geom = lwgeom_from_ewkt("POLYGON EMPTY", PARSER_CHECK_NONE);
CU_ASSERT_EQUAL(TYPE_GETTYPE(geom->type), COLLECTIONTYPE);
CU_ASSERT_EQUAL(geom->type, POLYGONTYPE);
lwgeom_free(geom);
/* Empty geometries don't seem to free properly (#370) */
geom = lwgeom_from_ewkt("LINESTRING EMPTY", PARSER_CHECK_NONE);
CU_ASSERT_EQUAL(TYPE_GETTYPE(geom->type), COLLECTIONTYPE);
CU_ASSERT_EQUAL(geom->type, LINETYPE);
lwgeom_free(geom);
/* Empty geometries don't seem to free properly (#370) */
geom = lwgeom_from_ewkt("POINT EMPTY", PARSER_CHECK_NONE);
CU_ASSERT_EQUAL(TYPE_GETTYPE(geom->type), COLLECTIONTYPE);
CU_ASSERT_EQUAL(geom->type, POINTTYPE);
lwgeom_free(geom);
}
......
......@@ -33,10 +33,10 @@ static void test_misc_force_2d(void)
lwgeom_free(geom2d);
lwfree(wkt_out);
geom = lwgeom_from_ewkt("GEOMETRYCOLLECTION(POINT(0 0 0),LINESTRING(1 1 1,2 2 2),POLYGON((0 0 1,0 1 1,1 1 1,1 0 1,0 0 1)),CURVEPOLYGON(CIRCULARSTRING(0 0 0,1 1 1,2 2 2,0 0 0)))", PARSER_CHECK_NONE);
geom = lwgeom_from_ewkt("GEOMETRYCOLLECTION(POINT(0 0 0),LINESTRING(1 1 1,2 2 2),POLYGON((0 0 1,0 1 1,1 1 1,1 0 1,0 0 1)),CURVEPOLYGON(CIRCULARSTRING(0 0 0,1 1 1,2 2 2,1 1 1,0 0 0)))", PARSER_CHECK_NONE);
geom2d = lwgeom_force_2d(geom);
wkt_out = lwgeom_to_ewkt(geom2d, PARSER_CHECK_NONE);
CU_ASSERT_STRING_EQUAL("GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(1 1,2 2),POLYGON((0 0,0 1,1 1,1 0,0 0)),CURVEPOLYGON(CIRCULARSTRING(0 0,1 1,2 2,0 0)))",wkt_out);
CU_ASSERT_STRING_EQUAL("GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(1 1,2 2),POLYGON((0 0,0 1,1 1,1 0,0 0)),CURVEPOLYGON(CIRCULARSTRING(0 0,1 1,2 2,1 1,0 0)))",wkt_out);
lwgeom_free(geom);
lwgeom_free(geom2d);
lwfree(wkt_out);
......@@ -97,6 +97,26 @@ static void test_misc_count_vertices(void)
lwgeom_free(geom);
}
static void test_misc_area(void)
{
LWGEOM *geom;
double area;
geom = lwgeom_from_ewkt("LINESTRING EMPTY", PARSER_CHECK_ALL);
area = lwgeom_area(geom);
CU_ASSERT_DOUBLE_EQUAL(area, 0.0, 0.0001);
}
static void test_misc_wkb(void)
{
static char *wkb = "010A0000000200000001080000000700000000000000000000C00000000000000000000000000000F0BF000000000000F0BF00000000000000000000000000000000000000000000F03F000000000000F0BF000000000000004000000000000000000000000000000000000000000000004000000000000000C00000000000000000010200000005000000000000000000F0BF00000000000000000000000000000000000000000000E03F000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F0BF0000000000000000";
LWGEOM *geom = lwgeom_from_hexwkb(wkb, PARSER_CHECK_ALL);
char *str = lwgeom_to_wkt(geom, WKB_ISO, 8, 0);
CU_ASSERT_STRING_EQUAL(str, "CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0))");
lwfree(str);
lwgeom_free(geom);
}
/*
** Used by the test harness to register the tests in this file.
......@@ -106,6 +126,8 @@ CU_TestInfo misc_tests[] =
PG_TEST(test_misc_force_2d),
PG_TEST(test_misc_simplify),
PG_TEST(test_misc_count_vertices),
PG_TEST(test_misc_area),
PG_TEST(test_misc_wkb),
CU_TEST_INFO_NULL
};
CU_SuiteInfo misc_suite = {"Misc Suite", NULL, NULL, misc_tests };
......@@ -21,7 +21,7 @@
/*
** Global variable to hold WKB strings
*/
char *s;
uchar *s;
char *t;
/*
......@@ -77,6 +77,10 @@ static void test_wkb_out_linestring(void)
cu_wkb_out("LINESTRING(0 0 1,1 1 2,2 2 3)");
CU_ASSERT_STRING_EQUAL(s, t);
cu_wkb_out("LINESTRING EMPTY");
// printf("new: %s\nold: %s\n",s,t);
CU_ASSERT_STRING_EQUAL(s, t);
}
static void test_wkb_out_polygon(void)
......@@ -91,15 +95,16 @@ static void test_wkb_out_polygon(void)
CU_ASSERT_STRING_EQUAL(s, t);
cu_wkb_out("POLYGON EMPTY");
// printf("new: %s\nold: %s\n",s,t);
CU_ASSERT_STRING_EQUAL(s, t);
}
static void test_wkb_out_multipoint(void)
{
cu_wkb_out("SRID=4;MULTIPOINT(0 0 0,0 1 0,1 1 0,1 0 0,0 0 ))");
cu_wkb_out("SRID=4;MULTIPOINT(0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)");
CU_ASSERT_STRING_EQUAL(s, t);
cu_wkb_out("MULTIPOINT(0 0 0, 0.26794919243112270647255365849413 1 3)");
// cu_wkb_out("MULTIPOINT(0 0 0, 0.26794919243112270647255365849413 1 3)");
CU_ASSERT_STRING_EQUAL(s, t);
}
......
......@@ -160,16 +160,16 @@ static void test_wkt_out_circularstring(void)
static void test_wkt_out_compoundcurve(void)
{
CU_ASSERT_STRING_EQUAL(
cu_wkt("COMPOUNDCURVE((1 2 3 4,4 5 6 7,7 8 9 0),CIRCULARSTRING(1 2 3 4,4 5 6 7,7 8 9 0))",WKT_ISO),
"COMPOUNDCURVE ZM ((1 2 3 4,4 5 6 7,7 8 9 0),CIRCULARSTRING ZM (1 2 3 4,4 5 6 7,7 8 9 0))"
cu_wkt("COMPOUNDCURVE((1 2 3 4,4 5 6 7,7 8 9 0),CIRCULARSTRING(7 8 9 0,4 3 2 1,1 2 3 4,4 5 6 7,7 8 9 0))",WKT_ISO),
"COMPOUNDCURVE ZM ((1 2 3 4,4 5 6 7,7 8 9 0),CIRCULARSTRING ZM (7 8 9 0,4 3 2 1,1 2 3 4,4 5 6 7,7 8 9 0))"
);
}
static void test_wkt_out_curvpolygon(void)
{
CU_ASSERT_STRING_EQUAL(
cu_wkt("CURVEPOLYGON((1 2 3 4,4 5 6 7,7 8 9 0),CIRCULARSTRING(1 2 3 4,4 5 6 7,7 8 9 0))",WKT_ISO),
"CURVEPOLYGON ZM ((1 2 3 4,4 5 6 7,7 8 9 0),CIRCULARSTRING ZM (1 2 3 4,4 5 6 7,7 8 9 0))"
cu_wkt("CURVEPOLYGON((1 2 3 4,4 5 6 7,7 8 9 0),CIRCULARSTRING(7 8 9 0,1 2 1 1,1 2 3 4,4 5 6 7,7 8 9 0))",WKT_ISO),
"CURVEPOLYGON ZM ((1 2 3 4,4 5 6 7,7 8 9 0),CIRCULARSTRING ZM (7 8 9 0,1 2 1 1,1 2 3 4,4 5 6 7,7 8 9 0))"
);
}
......
......@@ -82,8 +82,8 @@ void triangle_parse(void)
/*
NOTA: Theses 3 ASSERT results will change a day cf #294
*/
CU_ASSERT_EQUAL(geom->type, COLLECTIONTYPE);
CU_ASSERT_STRING_EQUAL("GEOMETRYCOLLECTION EMPTY", lwgeom_to_ewkt(geom, PARSER_CHECK_NONE));
CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE);
// CU_ASSERT_STRING_EQUAL("TRIANGLE EMPTY", lwgeom_to_wkt(geom, PARSER_CHECK_NONE));
lwgeom_free(geom);
/* explicit SRID */
......@@ -116,8 +116,8 @@ void tin_parse(void)
/*
NOTA: Theses 3 ASSERT results will change a day cf #294
*/
CU_ASSERT_EQUAL(geom->type, COLLECTIONTYPE);
CU_ASSERT_STRING_EQUAL("GEOMETRYCOLLECTION EMPTY", lwgeom_to_ewkt(geom, PARSER_CHECK_NONE));
CU_ASSERT_EQUAL(geom->type, TINTYPE);
// CU_ASSERT_STRING_EQUAL("TIN EMPTY", lwgeom_to_ewkt(geom, PARSER_CHECK_NONE));
lwgeom_free(geom);
/* 2 dims */
......@@ -182,8 +182,8 @@ void tin_parse(void)
/*
NOTA: Theses 3 ASSERT results will change a day cf #294
*/
CU_ASSERT_EQUAL(TYPE_GETTYPE(geom->type), COLLECTIONTYPE);
CU_ASSERT_STRING_EQUAL("GEOMETRYCOLLECTION EMPTY", lwgeom_to_ewkt(geom, PARSER_CHECK_NONE));
CU_ASSERT_EQUAL(TYPE_GETTYPE(geom->type), TINTYPE);
// CU_ASSERT_STRING_EQUAL("GEOMETRYCOLLECTION EMPTY", lwgeom_to_ewkt(geom, PARSER_CHECK_NONE));
lwgeom_free(geom);
/* A simple tetrahedron */
......@@ -325,25 +325,25 @@ void polyhedralsurface_parse(void)
lwgeom_free(geom);
/* ERROR: non closed rings */
geom = lwgeom_from_ewkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 0 2)))", PARSER_CHECK_NONE);
geom = lwgeom_from_ewkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 0 2)))", PARSER_CHECK_ALL);
CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
cu_error_msg_reset();
lwgeom_free(geom);
/* ERROR: non closed face in Z dim */
geom = lwgeom_from_ewkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 3)))", PARSER_CHECK_NONE);
geom = lwgeom_from_ewkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 3)))", PARSER_CHECK_ALL);
CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
cu_error_msg_reset();
lwgeom_free(geom);
/* ERROR: non closed face in Z dim, with a 4D geom */
geom = lwgeom_from_ewkt("POLYHEDRALSURFACE(((0 1 2 3,4 5 6 7,8 9 10 11,0 1 3 3)))", PARSER_CHECK_NONE);
geom = lwgeom_from_ewkt("POLYHEDRALSURFACE(((0 1 2 3,4 5 6 7,8 9 10 11,0 1 3 3)))", PARSER_CHECK_ALL);
CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
cu_error_msg_reset();
lwgeom_free(geom);
/* ERROR: only 3 points in a face */
geom = lwgeom_from_ewkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,0 1 2)))", PARSER_CHECK_NONE);
geom = lwgeom_from_ewkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,0 1 2)))", PARSER_CHECK_ALL);
CU_ASSERT_STRING_EQUAL("geometry requires more points", cu_error_msg);
cu_error_msg_reset();
lwgeom_free(geom);
......@@ -354,9 +354,9 @@ void polyhedralsurface_parse(void)
/*
NOTA: Theses 3 ASSERT results will change a day cf #294
*/
CU_ASSERT_EQUAL(geom->type, COLLECTIONTYPE);
CU_ASSERT_STRING_EQUAL("010700000000000000", lwgeom_to_hexwkb(geom, PARSER_CHECK_NONE, (char) -1));
CU_ASSERT_STRING_EQUAL("GEOMETRYCOLLECTION EMPTY", lwgeom_to_ewkt(geom, PARSER_CHECK_NONE));
CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE);
// CU_ASSERT_STRING_EQUAL("010700000000000000", lwgeom_to_wkb(geom, WKB_HEX | WKB_ISO | WKB_NDR, 0));
// CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE EMPTY", lwgeom_to_ewkt(geom, PARSER_CHECK_NONE));
lwgeom_free(geom);
/* A simple tetrahedron */
......
......@@ -1320,26 +1320,6 @@ GSERIALIZED* gserialized_copy(const GSERIALIZED *g)
char* gserialized_to_string(const GSERIALIZED *g)
{
LWGEOM_UNPARSER_RESULT lwg_unparser_result;
LWGEOM *lwgeom = lwgeom_from_gserialized(g);
uchar *serialized_lwgeom;
int result;
assert(g);
if ( ! lwgeom )
{
lwerror("Unable to create lwgeom from gserialized");
return NULL;
}
serialized_lwgeom = lwgeom_serialize(lwgeom);
lwgeom_release(lwgeom);
result = serialized_lwgeom_to_ewkt(&lwg_unparser_result, serialized_lwgeom, PARSER_CHECK_NONE);
lwfree(serialized_lwgeom);
return lwg_unparser_result.wkoutput;
return lwgeom_to_wkt(lwgeom_from_gserialized(g), WKT_ISO, 12, 0);
}
......@@ -176,7 +176,7 @@
* Currently we are using 20 bits (1048575) of storage for SRID.
*/
#define SRID_MAXIMUM 999999
#define SRID_UNKNOWN 0
#define SRID_UNKNOWN -1
......@@ -1102,6 +1102,13 @@ extern int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa);
*/
extern int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring);
/**
* Add a component, allocating extra space if necessary. The compoundcurve
* takes owership of the passed geometry.
*/
extern int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom);
/******************************************************************
* LWTRIANGLE functions
......@@ -2037,7 +2044,9 @@ extern uchar *lwgeom_to_ewkb(LWGEOM *lwgeom, int flags, char byteorder, size_t *
#define WKB_EXTENDED 0x04
#define WKB_NDR 0x08
#define WKB_XDR 0x10
#define WKB_HEX 0x11
#define WKB_HEX 0x20
#define WKB_NO_NPOINTS 0x40 /* Internal use only */
#define WKB_NO_SRID 0x80 /* Internal use only */
#define WKT_ISO 0x01
#define WKT_SFSQL 0x02
......@@ -2047,10 +2056,12 @@ extern uchar *lwgeom_to_ewkb(LWGEOM *lwgeom, int flags, char byteorder, size_t *
** New parsing and unparsing functions.
*/
extern char* lwgeom_to_wkt(const LWGEOM *geom, uchar variant, int precision, size_t *size_out);
extern char* lwgeom_to_wkb(const LWGEOM *geom, uchar variant, size_t *size_out);
extern uchar* lwgeom_to_wkb(const LWGEOM *geom, uchar variant, size_t *size_out);
//extern char* lwgeom_to_hexwkb(const LWGEOM *geom, uchar variant, size_t *size_out);
extern LWGEOM* lwgeom_from_wkb(const uchar *wkb, const size_t wkb_size, const char check);
extern LWGEOM* lwgeom_from_hexwkb(const char *hexwkb, const char check);
extern uchar* bytes_from_hexbytes(const char *hexbuf, size_t hexsize);
/* extern char* bytes_to_hexbytes(const char *buf, size_t bufsize);*/
extern char* hexbytes_from_bytes(uchar *bytes, size_t size);
extern void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result);
extern void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result);
extern int lwgeom_from_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags);
......
......@@ -33,12 +33,11 @@
*/
#define WKT_NO_TYPE 0x08 /* Internal use only */
#define WKT_NO_PARENS 0x10 /* Internal use only */
#define WKT_IS_CHILD 0x20 /* Internal use only */
/**
* Well-Known Binary (WKB) Output Variant Types
*/
#define WKB_NO_NPOINTS 0x20 /* Internal use only */
#define WKB_NO_SRID 0x40 /* Internal use only */
#define WKB_DOUBLE_SIZE 8 /* Internal use only */
#define WKB_INT_SIZE 4 /* Internal use only */
......
......@@ -47,8 +47,7 @@ lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points)
*/
if (points->npoints % 2 != 1 || points->npoints < 3)
{
lwerror("lwcircstring_construct: invalid point count %d", points->npoints);
return NULL;
lwnotice("lwcircstring_construct: invalid point count %d", points->npoints);
}
result = (LWCIRCSTRING*) lwalloc(sizeof(LWCIRCSTRING));
......@@ -74,7 +73,7 @@ lwcircstring_construct_empty(int srid, char hasz, char hasm)
result->type = CIRCSTRINGTYPE;
result->flags = gflags(hasz,hasm,0);
result->srid = srid;
result->points = NULL;
result->points = ptarray_construct_empty(hasz, hasm, 1);
result->bbox = NULL;
return result;
}
......
......@@ -115,3 +115,37 @@ double lwcompound_length_2d(const LWCOMPOUND *comp)
lwline_free(line);
return length;
}
int lwcompound_add_lwgeom(LWCOMPOUND *comp, LWGEOM *geom)
{
LWCOLLECTION *col = (LWCOLLECTION*)comp;
/* Empty things can't continuously join up with other things */
if ( lwgeom_is_empty(geom) )
{
LWDEBUG(4, "Got an empty component for a compound curve!");
return LW_FAILURE;
}
if( col->ngeoms > 0 )
{
POINT4D last, first;
/* First point of the component we are adding */
LWLINE *newline = (LWLINE*)geom;
/* Last point of the previous component */
LWLINE *prevline = (LWLINE*)(col->geoms[col->ngeoms-1]);
getPoint4d_p(newline->points, 0, &first);
getPoint4d_p(prevline->points, prevline->points->npoints-1, &last);
if ( !(FP_EQUALS(first.x,last.x) && FP_EQUALS(first.y,last.y)) )
{
LWDEBUG(4, "Components don't join up end-to-end!");
LWDEBUGF(4, "first pt (%g %g %g %g) last pt (%g %g %g %g)", first.x, first.y, first.z, first.m, last.x, last.y, last.z, last.m);
return LW_FAILURE;
}
}
col = lwcollection_add_lwgeom(col, geom);
return LW_SUCCESS;
}
\ No newline at end of file
......@@ -108,7 +108,7 @@ int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
if( ! poly || ! ring )
{
LWDEBUG(4,"NULL inputs!!! quitting");
return LW_FALSE;
return LW_FAILURE;
}
/* Check that we're not working with garbage */
......@@ -122,7 +122,7 @@ int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
if ( ! ( ring->type == LINETYPE || ring->type == CIRCSTRINGTYPE || ring->type == COMPOUNDTYPE ) )
{
LWDEBUGF(4,"got incorrect ring type: %s",lwtype_name(ring->type));
return LW_FALSE;
return LW_FAILURE;
}
......@@ -147,14 +147,14 @@ int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
if ( poly->rings[i] == ring )
{
LWDEBUGF(4, "Found duplicate geometry in collection %p == %p", poly->rings[i], ring);
return LW_TRUE;
return LW_SUCCESS;
}
}
/* Add the ring and increment the ring count */
poly->rings[poly->nrings] = (LWGEOM*)ring;
poly->nrings++;
return LW_TRUE;
return LW_SUCCESS;
}
/**
......
......@@ -70,6 +70,13 @@ lwgeom_deserialize(uchar *srl)
size_t
lwgeom_serialize_size(LWGEOM *lwgeom)
{
// if( lwgeom->type != COLLECTIONTYPE && lwgeom_is_empty(lwgeom) )
// {
// LWGEOM *tmp = (LWGEOM*)lwcollection_construct_empty(COLLECTIONTYPE, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
// lwgeom = tmp;
// }
switch (lwgeom->type)
{
case POINTTYPE:
......@@ -107,6 +114,12 @@ lwgeom_serialize_buf(LWGEOM *lwgeom, uchar *buf, size_t *retsize)
LWDEBUGF(2, "lwgeom_serialize_buf called with a %s",
lwtype_name(lwgeom->type));
// if( lwgeom->type != COLLECTIONTYPE && lwgeom_is_empty(lwgeom) )
// {
// LWGEOM *tmp = (LWGEOM*)lwcollection_construct_empty(COLLECTIONTYPE, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
// lwgeom = tmp;
// }
switch (lwgeom->type)
{
case POINTTYPE:
......@@ -721,18 +734,18 @@ LWGEOM*
lwgeom_from_ewkt(char *ewkt, int flags)
{
int result;
LWGEOM *ret;
LWGEOM_PARSER_RESULT lwg_parser_result;
lwgeom_parser_result_init(&lwg_parser_result);
/* Rely on grammar parser to construct a LWGEOM */
result = serialized_lwgeom_from_ewkt(&lwg_parser_result, ewkt, flags);
if (result)
result = lwgeom_from_wkt(&lwg_parser_result, ewkt, flags);
if (result == LW_FAILURE)
{
lwerror("%s", (char *)lwg_parser_result.message);
return NULL;
}
/* Deserialize */
ret = lwgeom_deserialize(lwg_parser_result.serialized_lwgeom);
return ret;
return lwg_parser_result.geom;
}
/*
......@@ -1135,6 +1148,9 @@ lwtype_get_collectiontype(int type)
void lwgeom_free(LWGEOM *lwgeom)
{
/* There's nothing here to free... */
if( ! lwgeom ) return;
switch (lwgeom->type)
{
case POINTTYPE:
......
......@@ -39,40 +39,41 @@ LWGEOM* lwgeom_from_wkb_state(wkb_parse_state *s);
/**********************************************************************/
static char hex2char[256] = {
/* Our static character->number map. Anything > 15 is invalid */
static uchar hex2char[256] = {
/* not Hex characters */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
/* 0-9 */
0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
0,1,2,3,4,5,6,7,8,9,20,20,20,20,20,20,
/* A-F */
-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
20,10,11,12,13,14,15,20,20,20,20,20,20,20,20,20,
/* not Hex characters */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
/* a-f */
-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
20,10,11,12,13,14,15,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
/* not Hex characters (upper 128 characters) */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,<