PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_lwgeom_make_valid ( void  )
static

Definition at line 42 of file cu_clean.c.

References check_geom_equal, cu_error_msg_reset(), LW_PARSER_CHECK_NONE, lwfree(), lwgeom_free(), lwgeom_from_hexwkb(), lwgeom_from_wkt(), lwgeom_make_valid(), and lwgeom_to_ewkt().

Referenced by clean_suite_setup().

43 {
44 #if POSTGIS_GEOS_VERSION >= 33
45  LWGEOM *gin, *gout, *gexp;
46  char *ewkt;
47 
48  /* Because i don't trust that much prior tests... ;) */
50 
51  gin = lwgeom_from_wkt(
52 "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)))",
54  CU_ASSERT(gin != NULL);
55 
56  gout = lwgeom_make_valid(gin);
57 
58  /* We're really only interested in avoiding a crash in here.
59  * See http://trac.osgeo.org/postgis/ticket/1738
60  * TODO: enhance the test if we find a workaround
61  * to the excepion:
62  * See http://trac.osgeo.org/postgis/ticket/1735
63  */
64 
65  lwgeom_free(gout);
66  lwgeom_free(gin);
67 
68  /* Test for http://trac.osgeo.org/postgis/ticket/2307 */
69 
70  gin = lwgeom_from_hexwkb("0106000020E6100000010000000103000000010000000A0000004B7DA956B99844C0DB0790FE8B4D1DC010BA74A9AF9444C049AFFC5B8C4D1DC03FC6CC690D9844C0DD67E5628C4D1DC07117B56B0D9844C0C80ABA67C45E1DC0839166ABAF9444C0387D4568C45E1DC010BA74A9AF9444C049AFFC5B8C4D1DC040C3CD74169444C0362EC0608C4D1DC07C1A3B77169444C0DC3ADB40B2641DC03AAE5F68B99844C0242948DEB1641DC04B7DA956B99844C0DB0790FE8B4D1DC0", LW_PARSER_CHECK_NONE);
71  CU_ASSERT(gin != NULL);
72 
73  gout = lwgeom_make_valid(gin);
74  CU_ASSERT(gout != NULL);
75  lwgeom_free(gin);
76 
77  /* We're really only interested in avoiding memory problems.
78  * Convertion to ewkt ensures full scan of coordinates thus
79  * triggering the error, if any
80  */
81  ewkt = lwgeom_to_ewkt(gout);
82  lwgeom_free(gout);
83  lwfree(ewkt);
84 
85 
86  /* Test collection */
87 
88  gin = lwgeom_from_wkt(
89 "GEOMETRYCOLLECTION(LINESTRING(0 0, 0 0), POLYGON((0 0, 10 10, 10 0, 0 10, 0 0)), LINESTRING(10 0, 10 10))",
91  CU_ASSERT(gin != NULL);
92 
93  gout = lwgeom_make_valid(gin);
94  CU_ASSERT(gout != NULL);
95 
96  ewkt = lwgeom_to_ewkt(gout);
97  /* printf("c = %s\n", ewkt); */
98  /*
99  TODO: This doesn't work on windows returns in different order.
100  strk figure out why. For now will replace with normalized version
101  */
102 /* CU_ASSERT_STRING_EQUAL(ewkt,
103 "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))");*/
104  gexp = lwgeom_from_wkt(
105 "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))",
107  check_geom_equal(gout, gexp);
108  lwfree(ewkt);
109 
110  lwgeom_free(gout);
111  lwgeom_free(gin);
112  lwgeom_free(gexp);
113 
114  /* Test multipoint */
115 
116  gin = lwgeom_from_wkt(
117 "MULTIPOINT(0 0,1 1,2 2)",
119  CU_ASSERT(gin != NULL);
120 
121  gout = lwgeom_make_valid(gin);
122  CU_ASSERT(gout != NULL);
123 
124  ewkt = lwgeom_to_ewkt(gout);
125  /* printf("c = %s\n", ewkt); */
126  CU_ASSERT_STRING_EQUAL(ewkt,
127 "MULTIPOINT(0 0,1 1,2 2)");
128  lwfree(ewkt);
129 
130  lwgeom_free(gout);
131  lwgeom_free(gin);
132 
133 #endif /* POSTGIS_GEOS_VERSION >= 33 */
134 }
void lwfree(void *mem)
Definition: lwutil.c:190
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:425
#define check_geom_equal(gobt, gexp)
Definition: cu_clean.c:22
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
LWGEOM * lwgeom_make_valid(LWGEOM *geom)
Attempts to make an invalid geometries valid w/out losing points.
void cu_error_msg_reset()
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:753

Here is the call graph for this function:

Here is the caller graph for this function: