PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_lwgeom_make_valid()

static void test_lwgeom_make_valid ( void  )
static

Definition at line 42 of file cu_clean.c.

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

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().

Here is the call graph for this function:
Here is the caller graph for this function: