/* +-----+-----+ | | | +-----+-----+ */ static void buildarea2(void) { LWGEOM *gin, *gout, *gexp; /* because i don't trust that much prior tests... ;) */ cu_error_msg_reset(); gin = lwgeom_from_wkt( "MULTILINESTRING((0 0, 10 0, 10 10, 0 10, 0 0),(10 10, 20 10, 20 0, 10 0, 10 10))", LW_PARSER_CHECK_NONE); CU_ASSERT(gin != NULL); gexp = lwgeom_from_wkt( "POLYGON((0 0,0 10,10 10,20 10,20 0,10 0,0 0))", LW_PARSER_CHECK_NONE); CU_ASSERT(gexp != NULL); gout = lwgeom_buildarea(gin); CU_ASSERT(gout != NULL); check_geom_equal(gout, gexp); lwgeom_free(gout); lwgeom_free(gexp); lwgeom_free(gin); }
/* +--------------------+ +-------+ | +-----+ +----+ | | +---+ | | | +-+ | | | | | | | | | | | | | +----+ | | +---+ | | | +-+ | | | | | | | | | | | | | | | | | | +-+ | | | | | | | +-----+ +----+ | | | +--------------------+ +-------+ */ static void buildarea7(void) { LWGEOM *gin, *gout, *gexp; cu_error_msg_reset(); gin = lwgeom_from_wkt( "MULTILINESTRING( (0 0, 70 0, 70 70, 0 70, 0 0), (10 10, 10 60, 40 60, 40 10, 10 10), (20 20, 20 30, 30 30, 30 20, 20 20), (20 30, 30 30, 30 50, 20 50, 20 30), (50 20, 60 20, 60 40, 50 40, 50 20), (50 40, 60 40, 60 60, 50 60, 50 40), (80 0, 110 0, 110 70, 80 70, 80 0), (90 60, 100 60, 100 50, 90 50, 90 60))", LW_PARSER_CHECK_NONE); CU_ASSERT(gin != NULL); gexp = lwgeom_from_wkt( "MULTIPOLYGON(((80 0,80 70,110 70,110 0,80 0),(90 60,90 50,100 50,100 60,90 60)),((20 20,20 30,20 50,30 50,30 30,30 20,20 20)),((0 0,0 70,70 70,70 0,0 0),(10 10,40 10,40 60,10 60,10 10),(50 20,60 20,60 40,60 60,50 60,50 40,50 20)))", LW_PARSER_CHECK_NONE); CU_ASSERT(gexp != NULL); gout = lwgeom_buildarea(gin); CU_ASSERT(gout != NULL); check_geom_equal(gout, gexp); lwgeom_free(gout); lwgeom_free(gexp); lwgeom_free(gin); }
/* +-----+ | | +-----+-----+ | | +-----+ */ static void buildarea1(void) { LWGEOM *gin, *gout, *gexp; cu_error_msg_reset(); gin = lwgeom_from_wkt( "MULTILINESTRING((0 0, 10 0, 10 10, 0 10, 0 0),(10 10, 20 10, 20 20, 10 20, 10 10))", LW_PARSER_CHECK_NONE); CU_ASSERT( gin != NULL ); gexp = lwgeom_from_wkt( "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((10 10,10 20,20 20,20 10,10 10)))", LW_PARSER_CHECK_NONE); CU_ASSERT( gexp != NULL ); gout = lwgeom_buildarea(gin); CU_ASSERT(gout != NULL); check_geom_equal(gout, gexp); lwgeom_free(gout); lwgeom_free(gexp); lwgeom_free(gin); }
static void test_lwgeom_delaunay_triangulation(void) { #if POSTGIS_GEOS_VERSION >= 34 LWGEOM *in, *tmp, *out; char *wkt, *exp_wkt; /* Because i don't trust that much prior tests... ;) */ cu_error_msg_reset(); in = lwgeom_from_wkt("MULTIPOINT(10 0, 20 0, 5 5)", LW_PARSER_CHECK_NONE); tmp = lwgeom_delaunay_triangulation(in, 0, 0); lwgeom_free(in); out = lwgeom_normalize(tmp); lwgeom_free(tmp); wkt = lwgeom_to_ewkt(out); lwgeom_free(out); exp_wkt = "GEOMETRYCOLLECTION(POLYGON((5 5,20 0,10 0,5 5)))"; if ( strcmp(wkt, exp_wkt) ) { fprintf(stderr, "\nExp: %s\nObt: %s\n", exp_wkt, wkt); } CU_ASSERT_STRING_EQUAL(wkt, exp_wkt); lwfree(wkt); #endif /* POSTGIS_GEOS_VERSION >= 33 */ }
/* +---------------+ | +---------+ | | | +--+--+ | | | | | | | | | | | +--+--+ | | | +---------+ | +---------------+ */ static void buildarea5(void) { LWGEOM *gin, *gout, *gexp; cu_error_msg_reset(); gin = lwgeom_from_wkt( "MULTILINESTRING((0 0, 20 0, 20 20, 0 20, 0 0),(2 2, 18 2, 18 18, 2 18, 2 2),(8 8, 8 12, 12 12, 12 8, 8 8),(10 8, 10 12))", LW_PARSER_CHECK_NONE); CU_ASSERT(gin != NULL); gexp = lwgeom_from_wkt( "MULTIPOLYGON(((0 0,0 20,20 20,20 0,0 0),(2 2,18 2,18 18,2 18,2 2)),((8 8,8 12,12 12,12 8,8 8)))", LW_PARSER_CHECK_NONE); CU_ASSERT(gexp != NULL); gout = lwgeom_buildarea(gin); CU_ASSERT(gout != NULL); check_geom_equal(gout, gexp); lwgeom_free(gout); lwgeom_free(gexp); lwgeom_free(gin); }
static void do_gml2_unsupported(char * in, char * out) { LWGEOM *g; char *h; g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE); h = lwgeom_to_gml2(g, NULL, 0, ""); if (strcmp(cu_error_msg, out)) fprintf(stderr, "\nGML 2 - In: %s\nOut: %s\nTheo: %s\n", in, cu_error_msg, out); CU_ASSERT_STRING_EQUAL(out, cu_error_msg); cu_error_msg_reset(); lwfree(h); lwgeom_free(g); }
static void test_schema_is_valid() { static PCSCHEMA *myschema = NULL; char *xmlstr; int rv; // See https://github.com/pgpointcloud/pointcloud/issues/28 xmlstr = "<pc:PointCloudSchema xmlns:pc='x'><pc:dimension>1</pc:dimension></pc:PointCloudSchema>"; rv = pc_schema_from_xml(xmlstr, &myschema); CU_ASSERT_EQUAL(rv, PC_SUCCESS); cu_error_msg_reset(); rv = pc_schema_is_valid(myschema); CU_ASSERT_EQUAL(rv, PC_FAILURE); pc_schema_free(myschema); }
static void do_gml3_extent_test(char * in, char * out, char * srs, double precision, int opts, char* prefix) { LWGEOM *g; char *h; g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE); h = lwgeom_extent_to_gml3(g, srs, precision, opts, prefix); if ( ! h ) h = strdup(cu_error_msg); if (strcmp(h, out)) fprintf(stderr, "\nEXT GML 3 - In: %s\nObt: %s\nExp: %s\n", in, h, out); CU_ASSERT_STRING_EQUAL(out, h); cu_error_msg_reset(); lwfree(h); lwgeom_free(g); }
static void test_lwgeom_node(void) { #if POSTGIS_GEOS_VERSION >= 33 LWGEOM *in, *out; const char *wkt; char *tmp; /* Because i don't trust that much prior tests... ;) */ cu_error_msg_reset(); wkt = "LINESTRING(0 0,5 5, 10 0)"; in = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE); out = lwgeom_node(in); /* printf("%s\n", lwgeom_to_ewkt(out)); */ CU_ASSERT(lwgeom_same(in, out)); lwgeom_free(out); lwgeom_free(in); wkt = "MULTILINESTRING((0 0,0 5),(10 0, -10 5))"; in = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE); out = lwgeom_node(in); tmp = lwgeom_to_ewkt(out); CU_ASSERT_STRING_EQUAL("MULTILINESTRING((0 2.5,-10 5),(0 0,0 2.5),(0 2.5,0 5),(10 0,0 2.5))", tmp) lwfree(tmp); lwgeom_free(out); lwgeom_free(in); wkt = "MULTILINESTRING((0 0,5 5,10 0, 11 0, 20 0),(10 0, 12 0, 22 0))"; in = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE); out = lwgeom_node(in); tmp = lwgeom_to_ewkt(out); printf("%s\n", tmp); CU_ASSERT_STRING_EQUAL("MULTILINESTRING((0 0,5 5,10 0),(10 0,11 0,12 0,20 0),(20 0,22 0))", tmp); lwfree(tmp); lwgeom_free(out); lwgeom_free(in); wkt = "MULTILINESTRING((0 0,5 5,10 0, 11 0, 20 0),(22 0, 12 0, 10 0),(0 5, 5 0))"; in = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE); out = lwgeom_node(in); tmp = lwgeom_to_ewkt(out); printf("%s\n", tmp); CU_ASSERT_STRING_EQUAL( "MULTILINESTRING((0 0,2.5 2.5),(0 5,2.5 2.5),(22 0,20 0),(20 0,12 0,11 0,10 0),(10 0,5 5,2.5 2.5),(2.5 2.5,5 0))", tmp); lwfree(tmp); lwgeom_free(out); lwgeom_free(in); #endif /* POSTGIS_GEOS_VERSION >= 33 */ }
static void test_ptarrayarc_contains_point() { /* int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt) */ LWLINE *lwline; POINTARRAY *pa; POINT2D pt; int rv; /*** Collection of semi-circles surrounding unit square ***/ lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 -1, -2 0, -1 1, 0 2, 1 1, 2 0, 1 -1, 0 -2, -1 -1)")); pa = lwline->points; /* Point in middle of square */ pt.x = 0; pt.y = 0; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point in left lobe */ pt.x = -1.1; pt.y = 0.1; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point on boundary of left lobe */ pt.x = -1; pt.y = 0; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point on boundary vertex */ pt.x = -1; pt.y = 1; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /* Point outside */ pt.x = -1.5; pt.y = 1.5; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /*** Two-edge ring made up of semi-circles (really, a circle) ***/ lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0, 0 -1, -1 0)")); pa = lwline->points; /* Point outside */ pt.x = -1.5; pt.y = 1.5; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /* Point more outside */ pt.x = 2.5; pt.y = 1.5; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /* Point more outside */ pt.x = 2.5; pt.y = 2.5; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /* Point inside at middle */ pt.x = 0; pt.y = 0; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point inside offset from middle */ pt.x = 0.01; pt.y = 0.01; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point on edge vertex */ pt.x = 0; pt.y = 1; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /*** Two-edge ring, closed ***/ lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(1 6, 6 1, 9 7, 6 10, 1 6)")); pa = lwline->points; /* Point to left of ring */ pt.x = 20; pt.y = 4; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /*** One-edge ring, closed circle ***/ lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0, -1 0)")); pa = lwline->points; /* Point inside */ pt.x = 0; pt.y = 0; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point outside */ pt.x = 0; pt.y = 2; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /* Point on boundary */ pt.x = 0; pt.y = 1; rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /*** Overshort ring ***/ lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0)")); pa = lwline->points; cu_error_msg_reset(); rv = ptarrayarc_contains_point(pa, &pt); //printf("%s\n", cu_error_msg); CU_ASSERT_STRING_EQUAL("ptarrayarc_contains_point called with even number of points", cu_error_msg); /*** Unclosed ring ***/ lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0, 2 0)")); pa = lwline->points; cu_error_msg_reset(); rv = ptarrayarc_contains_point(pa, &pt); CU_ASSERT_STRING_EQUAL("ptarrayarc_contains_point called on unclosed ring", cu_error_msg); lwline_free(lwline); }
static void test_lwgeom_make_valid(void) { #if POSTGIS_GEOS_VERSION >= 33 LWGEOM *gin, *gout, *gexp; char *ewkt; /* Because i don't trust that much prior tests... ;) */ cu_error_msg_reset(); gin = lwgeom_from_wkt( "MULTIPOLYGON(((1725063 4819121, 1725104 4819067, 1725060 4819087, 1725064.14183882 4819094.70208557,1725064.13656044 4819094.70235069,1725064.14210359 4819094.70227252,1725064.14210362 4819094.70227252,1725064.13656043 4819094.70235069,1725055. 4819094, 1725055 4819094, 1725055 4819094, 1725063 4819121)))", LW_PARSER_CHECK_NONE); CU_ASSERT(gin != NULL); gout = lwgeom_make_valid(gin); /* We're really only interested in avoiding a crash in here. * See http://trac.osgeo.org/postgis/ticket/1738 * TODO: enhance the test if we find a workaround * to the excepion: * See http://trac.osgeo.org/postgis/ticket/1735 */ lwgeom_free(gout); lwgeom_free(gin); /* Test for http://trac.osgeo.org/postgis/ticket/2307 */ gin = lwgeom_from_hexwkb("0106000020E6100000010000000103000000010000000A0000004B7DA956B99844C0DB0790FE8B4D1DC010BA74A9AF9444C049AFFC5B8C4D1DC03FC6CC690D9844C0DD67E5628C4D1DC07117B56B0D9844C0C80ABA67C45E1DC0839166ABAF9444C0387D4568C45E1DC010BA74A9AF9444C049AFFC5B8C4D1DC040C3CD74169444C0362EC0608C4D1DC07C1A3B77169444C0DC3ADB40B2641DC03AAE5F68B99844C0242948DEB1641DC04B7DA956B99844C0DB0790FE8B4D1DC0", LW_PARSER_CHECK_NONE); CU_ASSERT(gin != NULL); gout = lwgeom_make_valid(gin); CU_ASSERT(gout != NULL); lwgeom_free(gin); /* We're really only interested in avoiding memory problems. * Convertion to ewkt ensures full scan of coordinates thus * triggering the error, if any */ ewkt = lwgeom_to_ewkt(gout); lwgeom_free(gout); lwfree(ewkt); /* Test collection */ gin = lwgeom_from_wkt( "GEOMETRYCOLLECTION(LINESTRING(0 0, 0 0), POLYGON((0 0, 10 10, 10 0, 0 10, 0 0)), LINESTRING(10 0, 10 10))", LW_PARSER_CHECK_NONE); CU_ASSERT(gin != NULL); gout = lwgeom_make_valid(gin); CU_ASSERT(gout != NULL); ewkt = lwgeom_to_ewkt(gout); /* printf("c = %s\n", ewkt); */ /* TODO: This doesn't work on windows returns in different order. strk figure out why. For now will replace with normalized version */ /* CU_ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(0 0),MULTIPOLYGON(((5 5,0 0,0 10,5 5)),((5 5,10 10,10 0,5 5))),LINESTRING(10 0,10 10))");*/ gexp = lwgeom_from_wkt( "GEOMETRYCOLLECTION(POINT(0 0),MULTIPOLYGON(((5 5,0 0,0 10,5 5)),((5 5,10 10,10 0,5 5))),LINESTRING(10 0,10 10))", LW_PARSER_CHECK_NONE); check_geom_equal(gout, gexp); lwfree(ewkt); lwgeom_free(gout); lwgeom_free(gin); lwgeom_free(gexp); /* Test multipoint */ gin = lwgeom_from_wkt( "MULTIPOINT(0 0,1 1,2 2)", LW_PARSER_CHECK_NONE); CU_ASSERT(gin != NULL); gout = lwgeom_make_valid(gin); CU_ASSERT(gout != NULL); ewkt = lwgeom_to_ewkt(gout); /* printf("c = %s\n", ewkt); */ CU_ASSERT_STRING_EQUAL(ewkt, "MULTIPOINT(0 0,1 1,2 2)"); lwfree(ewkt); lwgeom_free(gout); lwgeom_free(gin); #endif /* POSTGIS_GEOS_VERSION >= 33 */ }
static void test_lwline_split_by_point_to(void) { #if POSTGIS_GEOS_VERSION >= 33 LWLINE *line; LWPOINT *point; LWMLINE *coll; int ret; /* Because i don't trust that much prior tests... ;) */ cu_error_msg_reset(); coll = lwmline_construct_empty(SRID_UNKNOWN, 0, 0); CU_ASSERT_EQUAL(coll->ngeoms, 0); line = lwgeom_as_lwline(lwgeom_from_wkt("LINESTRING(0 0,5 5, 10 0)", LW_PARSER_CHECK_NONE)); CU_ASSERT(line != NULL); point = lwgeom_as_lwpoint(lwgeom_from_wkt( "POINT(0 0)", LW_PARSER_CHECK_NONE)); ret = lwline_split_by_point_to(line, point, coll); CU_ASSERT_EQUAL(ret, 1); CU_ASSERT_EQUAL(coll->ngeoms, 0); lwpoint_free(point); point = lwgeom_as_lwpoint(lwgeom_from_wkt( "POINT(10 0)", LW_PARSER_CHECK_NONE)); ret = lwline_split_by_point_to(line, point, coll); CU_ASSERT_EQUAL(ret, 1); CU_ASSERT_EQUAL(coll->ngeoms, 0); lwpoint_free(point); point = lwgeom_as_lwpoint(lwgeom_from_wkt( "POINT(5 0)", LW_PARSER_CHECK_NONE)); ret = lwline_split_by_point_to(line, point, coll); CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(coll->ngeoms, 0); lwpoint_free(point); point = lwgeom_as_lwpoint(lwgeom_from_wkt( "POINT(5 5)", LW_PARSER_CHECK_NONE)); ret = lwline_split_by_point_to(line, point, coll); CU_ASSERT_EQUAL(ret, 2); CU_ASSERT_EQUAL(coll->ngeoms, 2); lwpoint_free(point); point = lwgeom_as_lwpoint(lwgeom_from_wkt( "POINT(2 2)", LW_PARSER_CHECK_NONE)); ret = lwline_split_by_point_to(line, point, coll); CU_ASSERT_EQUAL(ret, 2); CU_ASSERT_EQUAL(coll->ngeoms, 4); lwpoint_free(point); lwcollection_free((LWCOLLECTION*)coll); lwline_free(line); #endif /* POSTGIS_GEOS_VERSION >= 33 */ }
void polyhedralsurface_parse(void) { LWGEOM *geom; GSERIALIZED *g; char *tmp; cu_error_msg_reset(); /* Because i don't trust that much prior tests... ;) */ /* 2 dims */ geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE); tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0); CU_ASSERT_STRING_EQUAL("010F00000001000000010300000001000000040000000000000000000000000000000000F03F00000000000000400000000000000840000000000000104000000000000014400000000000000000000000000000F03F", tmp); lwfree(tmp); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1)))", tmp); lwfree(tmp); lwgeom_free(geom); /* 3DM */ geom = lwgeom_from_wkt("POLYHEDRALSURFACEM(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACEM(((0 1 2,3 4 5,6 7 8,0 1 2)))", tmp); lwfree(tmp); tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0); CU_ASSERT_STRING_EQUAL("010F00004001000000010300004001000000040000000000000000000000000000000000F03F000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001C4000000000000020400000000000000000000000000000F03F0000000000000040", tmp); lwfree(tmp); lwgeom_free(geom); /* ERROR: a missing Z values */ geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7,0 1 2)))", LW_PARSER_CHECK_NONE); CU_ASSERT_STRING_EQUAL("can not mix dimensionality in a geometry", cu_error_msg); cu_error_msg_reset(); lwgeom_free(geom); /* 1 face with 1 interior ring */ geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 2),(9 10 11,12 13 14,15 16 17,9 10 11)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 2),(9 10 11,12 13 14,15 16 17,9 10 11)))", tmp); lwfree(tmp); tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0); CU_ASSERT_STRING_EQUAL("010F00008001000000010300008002000000040000000000000000000000000000000000F03F000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001C4000000000000020400000000000000000000000000000F03F00000000000000400400000000000000000022400000000000002440000000000000264000000000000028400000000000002A400000000000002C400000000000002E4000000000000030400000000000003140000000000000224000000000000024400000000000002640", tmp); lwfree(tmp); lwgeom_free(geom); /* ERROR: non closed rings */ geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 0 2)))", LW_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_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 3)))", LW_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_wkt("POLYHEDRALSURFACE(((0 1 2 3,4 5 6 7,8 9 10 11,0 1 3 3)))", LW_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_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,0 1 2)))", LW_PARSER_CHECK_ALL); CU_ASSERT_STRING_EQUAL("geometry requires more points", cu_error_msg); cu_error_msg_reset(); lwgeom_free(geom); /* EMPTY face */ geom = lwgeom_from_wkt("POLYHEDRALSURFACE EMPTY", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE); tmp = (char *)lwgeom_to_wkb(geom, WKB_HEX | WKB_ISO | WKB_NDR, 0); CU_ASSERT_STRING_EQUAL("010F00000000000000", tmp); lwfree(tmp); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE EMPTY", tmp); lwfree(tmp); lwgeom_free(geom); /* A simple tetrahedron */ geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE); CU_ASSERT_EQUAL(geom->srid, SRID_UNKNOWN); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", tmp); lwfree(tmp); tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0); CU_ASSERT_STRING_EQUAL("010F000080040000000103000080010000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000010300008001000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000000001030000800100000004000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000000001030000800100000004000000000000000000F03F000000000000000000000000000000000000000000000000000000000000F03F000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000", tmp); lwfree(tmp); lwgeom_free(geom); /* A 4D tetrahedron */ geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 0 0 0,0 0 1 0,0 1 0 2,0 0 0 0)),((0 0 0 0,0 1 0 0,1 0 0 4,0 0 0 0)),((0 0 0 0,1 0 0 0,0 0 1 6,0 0 0 0)),((1 0 0 0,0 1 0 0,0 0 1 0,1 0 0 0)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE); CU_ASSERT_EQUAL(FLAGS_GET_M(geom->flags), 1); CU_ASSERT_EQUAL(geom->srid, SRID_UNKNOWN); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE(((0 0 0 0,0 0 1 0,0 1 0 2,0 0 0 0)),((0 0 0 0,0 1 0 0,1 0 0 4,0 0 0 0)),((0 0 0 0,1 0 0 0,0 0 1 6,0 0 0 0)),((1 0 0 0,0 1 0 0,0 0 1 0,1 0 0 0)))", tmp); lwfree(tmp); tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0); CU_ASSERT_STRING_EQUAL("010F0000C00400000001030000C00100000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F00000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000001030000C0010000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F000000000000000000000000000000000000000000001040000000000000000000000000000000000000000000000000000000000000000001030000C001000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000001840000000000000000000000000000000000000000000000000000000000000000001030000C00100000004000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000000000000000000000000000000000000000", tmp); lwfree(tmp); lwgeom_free(geom); /* explicit SRID */ geom = lwgeom_from_wkt("SRID=4326;POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE); CU_ASSERT_EQUAL(geom->srid, 4326); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("SRID=4326;POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", tmp); lwfree(tmp); tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0); CU_ASSERT_STRING_EQUAL("010F0000A0E6100000040000000103000080010000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000010300008001000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000000001030000800100000004000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000000001030000800100000004000000000000000000F03F000000000000000000000000000000000000000000000000000000000000F03F000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000", tmp); lwfree(tmp); lwgeom_free(geom); /* geography support */ geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE); g = gserialized_from_lwgeom(geom, 1, 0); CU_ASSERT_EQUAL(gserialized_get_type(g), POLYHEDRALSURFACETYPE); lwgeom_free(geom); lwfree(g); }
void triangle_parse(void) { LWGEOM *geom; GSERIALIZED *g; char *tmp; cu_error_msg_reset(); /* Because i don't trust that much prior tests... ;) */ /* 2 dims */ geom = lwgeom_from_wkt("TRIANGLE((0 1,2 3,4 5,0 1))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("TRIANGLE((0 1,2 3,4 5,0 1))", tmp); lwfree(tmp); lwgeom_free(geom); /* 3DM */ geom = lwgeom_from_wkt("TRIANGLEM((0 1 2,3 4 5,6 7 8,0 1 2))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("TRIANGLEM((0 1 2,3 4 5,6 7 8,0 1 2))", tmp); lwfree(tmp); lwgeom_free(geom); /* ERROR: a missing Z values */ geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7,0 1 2))", LW_PARSER_CHECK_NONE); CU_ASSERT_STRING_EQUAL("can not mix dimensionality in a geometry", cu_error_msg); cu_error_msg_reset(); lwgeom_free(geom); /* ERROR: non closed rings */ geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 0 2))", LW_PARSER_CHECK_NONE); 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_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 3))", LW_PARSER_CHECK_NONE); 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_wkt("TRIANGLE((0 1 2 3,4 5 6 7,8 9 10 11,0 1 3 3))", LW_PARSER_CHECK_NONE); 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_wkt("TRIANGLE((0 1 2,3 4 5,0 1 2))", LW_PARSER_CHECK_NONE); CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg); cu_error_msg_reset(); lwgeom_free(geom); /* ERROR: more than 4 points in a face */ geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,9 10 11,0 1 2))", LW_PARSER_CHECK_NONE); CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg); cu_error_msg_reset(); lwgeom_free(geom); /* ERROR: no interior rings allowed */ geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2),(9 10 11,12 13 14,15 16 17,9 10 11)", LW_PARSER_CHECK_NONE); CU_ASSERT_STRING_EQUAL("parse error - invalid geometry", cu_error_msg); cu_error_msg_reset(); lwgeom_free(geom); /* EMPTY face */ geom = lwgeom_from_wkt("TRIANGLE EMPTY", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE); tmp = lwgeom_to_wkt(geom, LW_PARSER_CHECK_NONE, 0, 0); CU_ASSERT_STRING_EQUAL("TRIANGLE EMPTY", tmp); lwfree(tmp); lwgeom_free(geom); /* explicit SRID */ geom = lwgeom_from_wkt("SRID=4326;TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE); CU_ASSERT_EQUAL(geom->srid, 4326); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("SRID=4326;TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2))", tmp); lwfree(tmp); lwgeom_free(geom); /* geography support */ geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2))", LW_PARSER_CHECK_NONE); g = gserialized_from_lwgeom(geom, 1, 0); CU_ASSERT_EQUAL(gserialized_get_type(g), TRIANGLETYPE); lwgeom_free(geom); lwfree(g); }
void tin_parse(void) { LWGEOM *geom; GSERIALIZED *g; char *tmp; cu_error_msg_reset(); /* Because i don't trust that much prior tests... ;) */ /* empty */ geom = lwgeom_from_wkt("TIN EMPTY", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TINTYPE); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("TIN EMPTY", tmp); lwfree(tmp); lwgeom_free(geom); /* 2 dims */ geom = lwgeom_from_wkt("TIN(((0 1,2 3,4 5,0 1)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TINTYPE); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("TIN(((0 1,2 3,4 5,0 1)))", tmp); lwfree(tmp); lwgeom_free(geom); /* 3DM */ geom = lwgeom_from_wkt("TINM(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TINTYPE); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("TINM(((0 1 2,3 4 5,6 7 8,0 1 2)))", tmp); lwfree(tmp); lwgeom_free(geom); /* ERROR: a missing Z values */ geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7,0 1 2)))", LW_PARSER_CHECK_NONE); CU_ASSERT_STRING_EQUAL("can not mix dimensionality in a geometry", cu_error_msg); cu_error_msg_reset(); lwgeom_free(geom); /* ERROR: non closed rings */ geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 0 2)))", LW_PARSER_CHECK_NONE); 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_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 1 3)))", LW_PARSER_CHECK_NONE); 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_wkt("TIN(((0 1 2 3,4 5 6 7,8 9 10 11,0 1 3 3)))", LW_PARSER_CHECK_NONE); 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_wkt("TIN(((0 1 2,3 4 5,0 1 2)))", LW_PARSER_CHECK_NONE); CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg); cu_error_msg_reset(); lwgeom_free(geom); /* ERROR: more than 3 points in a face */ geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,9 10 11,0 1 2)))", LW_PARSER_CHECK_NONE); CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg); cu_error_msg_reset(); lwgeom_free(geom); /* ERROR: use ring for triangle */ geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 1 2),(9 10 11,12 13 14,15 16 17,9 10 11)))", LW_PARSER_CHECK_NONE); CU_ASSERT_STRING_EQUAL("parse error - invalid geometry", cu_error_msg); cu_error_msg_reset(); lwgeom_free(geom); /* EMPTY face */ geom = lwgeom_from_wkt("TIN EMPTY", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TINTYPE); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("TIN EMPTY", tmp); lwfree(tmp); lwgeom_free(geom); /* A simple tetrahedron */ geom = lwgeom_from_wkt("TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TINTYPE); CU_ASSERT_EQUAL(geom->srid, SRID_UNKNOWN); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", tmp); lwfree(tmp); lwgeom_free(geom); /* A 4D tetrahedron */ geom = lwgeom_from_wkt("TIN(((0 0 0 0,0 0 1 0,0 1 0 2,0 0 0 0)),((0 0 0 0,0 1 0 0,1 0 0 4,0 0 0 0)),((0 0 0 0,1 0 0 0,0 0 1 6,0 0 0 0)),((1 0 0 0,0 1 0 0,0 0 1 0,1 0 0 0)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TINTYPE); CU_ASSERT_EQUAL(FLAGS_GET_M(geom->flags), 1); CU_ASSERT_EQUAL(geom->srid, SRID_UNKNOWN); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("TIN(((0 0 0 0,0 0 1 0,0 1 0 2,0 0 0 0)),((0 0 0 0,0 1 0 0,1 0 0 4,0 0 0 0)),((0 0 0 0,1 0 0 0,0 0 1 6,0 0 0 0)),((1 0 0 0,0 1 0 0,0 0 1 0,1 0 0 0)))", tmp); lwfree(tmp); lwgeom_free(geom); /* explicit SRID */ geom = lwgeom_from_wkt("SRID=4326;TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", LW_PARSER_CHECK_NONE); CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); CU_ASSERT_EQUAL(geom->type, TINTYPE); CU_ASSERT_EQUAL(geom->srid, 4326); tmp = lwgeom_to_ewkt(geom); CU_ASSERT_STRING_EQUAL("SRID=4326;TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", tmp); lwfree(tmp); lwgeom_free(geom); /* geography support */ geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE); g = gserialized_from_lwgeom(geom, 1, 0); CU_ASSERT_EQUAL(gserialized_get_type(g), TINTYPE); lwgeom_free(geom); lwfree(g); }