PostGIS  2.4.9dev-r@@SVN_REVISION@@
cu_out_wkt.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  * Copyright 2010 Paul Ramsey <pramsey@cleverelephant.ca>
6  *
7  * This is free software; you can redistribute and/or modify it under
8  * the terms of the GNU General Public Licence. See the COPYING file.
9  *
10  **********************************************************************/
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include "CUnit/Basic.h"
16 
17 #include "liblwgeom_internal.h"
18 #include "cu_tester.h"
19 
20 /*
21 ** Global variable to hold WKT strings
22 */
23 char *s = NULL;
24 
25 /*
26 ** The suite initialization function.
27 ** Create any re-used objects.
28 */
29 static int init_wkt_out_suite(void)
30 {
31  s = NULL;
32  return 0;
33 }
34 
35 /*
36 ** The suite cleanup function.
37 ** Frees any global objects.
38 */
39 static int clean_wkt_out_suite(void)
40 {
41  if ( s ) free(s);
42  s = NULL;
43  return 0;
44 }
45 
46 static char* cu_wkt(char *wkt, uint8_t variant)
47 {
49  if ( s ) free(s);
50  if ( ! g )
51  {
52  printf("error converting '%s' to lwgeom\n", wkt);
53  exit(0);
54  }
55  s = lwgeom_to_wkt(g, variant, 8, NULL);
56  lwgeom_free(g);
57  return s;
58 }
59 
60 static void test_wkt_out_point(void)
61 {
62  CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(0.1111 0.1111 0.1111 0)",WKT_ISO), "POINT ZM (0.1111 0.1111 0.1111 0)");
63  CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(0 0 0 0)",WKT_EXTENDED), "POINT(0 0 0 0)");
64  CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(0 0 0 0)",WKT_SFSQL), "POINT(0 0)");
65 
66  CU_ASSERT_STRING_EQUAL(cu_wkt("POINTM(0 0 0)",WKT_ISO), "POINT M (0 0 0)");
67  CU_ASSERT_STRING_EQUAL(cu_wkt("POINTM(0 0 0)",WKT_EXTENDED), "POINTM(0 0 0)");
68  CU_ASSERT_STRING_EQUAL(cu_wkt("POINTM(0 0 0)",WKT_SFSQL), "POINT(0 0)");
69 
70  CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100 100)",WKT_ISO), "POINT(100 100)");
71  CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100 100)",WKT_EXTENDED), "POINT(100 100)");
72  CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100 100)",WKT_SFSQL), "POINT(100 100)");
73 
74  CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100.1 100 12 12)",WKT_ISO), "POINT ZM (100.1 100 12 12)");
75  CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100.1 100 12 12)",WKT_EXTENDED), "POINT(100.1 100 12 12)");
76  CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100.1 100 12 12)",WKT_SFSQL), "POINT(100.1 100)");
77 
78  CU_ASSERT_STRING_EQUAL(cu_wkt("SRID=100;POINT(100.1 100 12 12)",WKT_SFSQL), "POINT(100.1 100)");
79  CU_ASSERT_STRING_EQUAL(cu_wkt("SRID=100;POINT(100.1 100 12 12)",WKT_EXTENDED), "SRID=100;POINT(100.1 100 12 12)");
80 // printf("%s\n",cu_wkt("SRID=100;POINT(100.1 100 12 12)",WKT_EXTENDED));
81 
82 }
83 
84 static void test_wkt_out_linestring(void)
85 {
86  CU_ASSERT_STRING_EQUAL(cu_wkt("LINESTRING(1 2 3 4,5 6 7 8)",WKT_ISO), "LINESTRING ZM (1 2 3 4,5 6 7 8)");
87  CU_ASSERT_STRING_EQUAL(cu_wkt("LINESTRING(1 2 3,5 6 7)",WKT_ISO), "LINESTRING Z (1 2 3,5 6 7)");
88  CU_ASSERT_STRING_EQUAL(cu_wkt("LINESTRINGM(1 2 3,5 6 7)",WKT_ISO), "LINESTRING M (1 2 3,5 6 7)");
89 }
90 
91 static void test_wkt_out_polygon(void)
92 {
93  CU_ASSERT_STRING_EQUAL(
94  cu_wkt("POLYGON((100 100 2, 100 200 2, 200 200 2, 200 100 2, 100 100 2))",WKT_ISO),
95  "POLYGON Z ((100 100 2,100 200 2,200 200 2,200 100 2,100 100 2))"
96  );
97  CU_ASSERT_STRING_EQUAL(
98  cu_wkt("POLYGON((100 100 2, 100 200 2, 200 200 2, 200 100 2, 100 100 2))",WKT_EXTENDED),
99  "POLYGON((100 100 2,100 200 2,200 200 2,200 100 2,100 100 2))"
100  );
101 }
102 static void test_wkt_out_multipoint(void)
103 {
104  CU_ASSERT_STRING_EQUAL(cu_wkt("MULTIPOINT(1 2 3 4,5 6 7 8)",WKT_ISO), "MULTIPOINT ZM (1 2 3 4,5 6 7 8)");
105  CU_ASSERT_STRING_EQUAL(cu_wkt("MULTIPOINT(1 2 3,5 6 7)",WKT_ISO), "MULTIPOINT Z (1 2 3,5 6 7)");
106  CU_ASSERT_STRING_EQUAL(cu_wkt("MULTIPOINTM(1 2 3,5 6 7)",WKT_ISO), "MULTIPOINT M (1 2 3,5 6 7)");
107 
108 }
109 
111 {
112  CU_ASSERT_STRING_EQUAL(
113  cu_wkt("MULTILINESTRING((1 2 3 4,5 6 7 8))",WKT_ISO),
114  "MULTILINESTRING ZM ((1 2 3 4,5 6 7 8))"
115  );
116  CU_ASSERT_STRING_EQUAL(
117  cu_wkt("MULTILINESTRING((1 2 3,5 6 7))",WKT_ISO),
118  "MULTILINESTRING Z ((1 2 3,5 6 7))"
119  );
120  CU_ASSERT_STRING_EQUAL(
121  cu_wkt("MULTILINESTRINGM((1 2 3,5 6 7))",WKT_ISO),
122  "MULTILINESTRING M ((1 2 3,5 6 7))"
123  );
124 }
125 
126 static void test_wkt_out_multipolygon(void)
127 {
128  CU_ASSERT_STRING_EQUAL(
129  cu_wkt("MULTIPOLYGON(((100 100 2, 100 200 2, 200 200 2, 200 100 2, 100 100 2)))",WKT_ISO),
130  "MULTIPOLYGON Z (((100 100 2,100 200 2,200 200 2,200 100 2,100 100 2)))"
131  );
132  CU_ASSERT_STRING_EQUAL(
133  cu_wkt("MULTIPOLYGON(((100 100 2, 100 200 2, 200 200 2, 200 100 2, 100 100 2)))",WKT_EXTENDED),
134  "MULTIPOLYGON(((100 100 2,100 200 2,200 200 2,200 100 2,100 100 2)))"
135  );
136 }
137 
138 static void test_wkt_out_collection(void)
139 {
140  //printf("%s\n",cu_wkt("GEOMETRYCOLLECTION(MULTIPOLYGON(((100 100 2, 100 200 2, 200 200 2, 200 100 2, 100 100 2))),MULTIPOINT(.5 .5 .5,1 1 1),CURVEPOLYGON((.8 .8 .8,.8 .8 .8,.8 .8 .8)))",WKT_ISO));
141  CU_ASSERT_STRING_EQUAL(
142  cu_wkt("GEOMETRYCOLLECTION(POLYGON((100 100 2, 100 200 2, 200 200 2, 200 100 2, 100 100 2)),POINT(.5 .5 .5),CIRCULARSTRING(.8 .8 .8,.8 .8 .8,.8 .8 .8))",WKT_ISO),
143  "GEOMETRYCOLLECTION Z (POLYGON Z ((100 100 2,100 200 2,200 200 2,200 100 2,100 100 2)),POINT Z (0.5 0.5 0.5),CIRCULARSTRING Z (0.8 0.8 0.8,0.8 0.8 0.8,0.8 0.8 0.8))"
144  );
145  CU_ASSERT_STRING_EQUAL(
146  cu_wkt("GEOMETRYCOLLECTION(MULTIPOLYGON(((100 100 2, 100 200 2, 200 200 2, 200 100 2, 100 100 2))),MULTIPOINT(.5 .5 .5,1 1 1),CURVEPOLYGON((.8 .8 .8,.8 .8 .8,.8 .8 .8)))",WKT_ISO),
147  "GEOMETRYCOLLECTION Z (MULTIPOLYGON Z (((100 100 2,100 200 2,200 200 2,200 100 2,100 100 2))),MULTIPOINT Z (0.5 0.5 0.5,1 1 1),CURVEPOLYGON Z ((0.8 0.8 0.8,0.8 0.8 0.8,0.8 0.8 0.8)))"
148  );
149 
150  /* See http://trac.osgeo.org/postgis/ticket/724 */
151  CU_ASSERT_STRING_EQUAL(
152  cu_wkt("GEOMETRYCOLLECTIONM(MULTIPOINTM(0 0 0), POINTM(1 1 1))", WKT_EXTENDED),
153  "GEOMETRYCOLLECTIONM(MULTIPOINTM(0 0 0),POINTM(1 1 1))"
154  );
155 }
156 
158 {
159  CU_ASSERT_STRING_EQUAL(
160  cu_wkt("CIRCULARSTRING(1 2 3 4,4 5 6 7,7 8 9 0)",WKT_ISO),
161  "CIRCULARSTRING ZM (1 2 3 4,4 5 6 7,7 8 9 0)"
162  );
163  CU_ASSERT_STRING_EQUAL(
164  cu_wkt("CIRCULARSTRING(1 2 3 4,4 5 6 7,7 8 9 0)",WKT_EXTENDED),
165  "CIRCULARSTRING(1 2 3 4,4 5 6 7,7 8 9 0)"
166  );
167  //printf("%s\n",cu_wkt("GEOMETRYCOLLECTION(MULTIPOLYGON(((100 100 2, 100 200 2, 200 200 2, 200 100 2, 100 100 2))),MULTIPOINT(.5 .5 .5,1 1 1),CURVEPOLYGON((.8 .8 .8,.8 .8 .8,.8 .8 .8)))",WKT_ISO));
168 }
169 
170 static void test_wkt_out_compoundcurve(void)
171 {
172  CU_ASSERT_STRING_EQUAL(
173  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),
174  "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))"
175  );
176 }
177 
178 static void test_wkt_out_curvpolygon(void)
179 {
180  CU_ASSERT_STRING_EQUAL(
181  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),
182  "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))"
183  );
184 }
185 
186 static void test_wkt_out_multicurve(void)
187 {
188  CU_ASSERT_STRING_EQUAL(
189  cu_wkt("MULTICURVE((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),
190  "MULTICURVE 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))"
191  );
192  CU_ASSERT_STRING_EQUAL(
193  cu_wkt("MULTICURVE(COMPOUNDCURVE((1 2 3 4,4 5 6 7,7 8 9 0),CIRCULARSTRING(7 8 9 0,8 9 0 0,1 2 3 4,4 5 6 7,7 8 9 0)),(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),
194  "MULTICURVE ZM (COMPOUNDCURVE ZM ((1 2 3 4,4 5 6 7,7 8 9 0),CIRCULARSTRING ZM (7 8 9 0,8 9 0 0,1 2 3 4,4 5 6 7,7 8 9 0)),(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))"
195  );
196 }
197 
198 static void test_wkt_out_multisurface(void)
199 {
200  CU_ASSERT_STRING_EQUAL(
201  cu_wkt("MULTISURFACE(((1 2 3 4,4 5 6 7,7 8 9 0)),CURVEPOLYGON((1 2 3 4,4 5 6 7,7 8 9 0)))",WKT_ISO),
202  "MULTISURFACE ZM (((1 2 3 4,4 5 6 7,7 8 9 0)),CURVEPOLYGON ZM ((1 2 3 4,4 5 6 7,7 8 9 0)))"
203  );
204 
205 }
206 
207 /*
208 ** Used by test harness to register the tests in this file.
209 */
210 void wkt_out_suite_setup(void);
212 {
213  CU_pSuite suite = CU_add_suite("wkt_output", init_wkt_out_suite, clean_wkt_out_suite);
226 }
uint8_t variant
Definition: cu_in_twkb.c:26
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:669
static void test_wkt_out_multipolygon(void)
Definition: cu_out_wkt.c:126
void wkt_out_suite_setup(void)
Definition: cu_out_wkt.c:211
static void test_wkt_out_multisurface(void)
Definition: cu_out_wkt.c:198
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
static void test_wkt_out_polygon(void)
Definition: cu_out_wkt.c:91
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
#define WKT_ISO
Definition: liblwgeom.h:2083
static char * cu_wkt(char *wkt, uint8_t variant)
Definition: cu_out_wkt.c:46
#define PG_ADD_TEST(suite, testfunc)
static void test_wkt_out_point(void)
Definition: cu_out_wkt.c:60
static void test_wkt_out_multicurve(void)
Definition: cu_out_wkt.c:186
static void test_wkt_out_multilinestring(void)
Definition: cu_out_wkt.c:110
static void test_wkt_out_circularstring(void)
Definition: cu_out_wkt.c:157
char * s
Definition: cu_out_wkt.c:23
#define WKT_EXTENDED
Definition: liblwgeom.h:2085
static int clean_wkt_out_suite(void)
Definition: cu_out_wkt.c:39
static void test_wkt_out_collection(void)
Definition: cu_out_wkt.c:138
static void test_wkt_out_curvpolygon(void)
Definition: cu_out_wkt.c:178
#define WKT_SFSQL
Definition: liblwgeom.h:2084
static int init_wkt_out_suite(void)
Definition: cu_out_wkt.c:29
void free(void *)
static void test_wkt_out_multipoint(void)
Definition: cu_out_wkt.c:102
unsigned char uint8_t
Definition: uthash.h:79
static void test_wkt_out_compoundcurve(void)
Definition: cu_out_wkt.c:170
static void test_wkt_out_linestring(void)
Definition: cu_out_wkt.c:84