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