PostGIS  2.1.10dev-r@@SVN_REVISION@@
cu_force_sfs.c
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id:$
3  *
4  * PostGIS - Spatial Types for PostgreSQL
5  * http://postgis.net
6  * Copyright 2013 Olivier Courtin <olivier.courtin@oslandia.com>
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 static void do_geom_test(char * in, char * out)
22 {
23  LWGEOM *g, *h;
24  char *tmp;
25 
27  h = lwgeom_force_sfs(g, 110);
28  tmp = lwgeom_to_ewkt(h);
29  if (strcmp(tmp, out))
30  fprintf(stderr, "\nIn: %s\nOut: %s\nExp: %s\n",
31  in, tmp, out);
32  CU_ASSERT_STRING_EQUAL(tmp, out);
33  lwfree(tmp);
34  lwgeom_free(h);
35 }
36 
37 
38 static void do_type_test(char * in, int type)
39 {
40  LWGEOM *g, *h;
41 
43  h = lwgeom_force_sfs(g, 110);
44  if(h->type != type)
45  fprintf(stderr, "\nIn: %s\nOut: %s\nExp: %s\n",
46  in, lwtype_name(h->type), lwtype_name(type));
47  CU_ASSERT_EQUAL(h->type, type);
48  lwgeom_free(h);
49  lwgeom_free(g);
50 }
51 
52 
53 static void test_sqlmm(void)
54 {
55  do_type_test("CIRCULARSTRING(-1 0,0 1,0 -1)",
56  LINETYPE);
57 
58  do_type_test("COMPOUNDCURVE(CIRCULARSTRING(-1 0,0 1,0 -1),(0 -1,-1 -1))",
59  LINETYPE);
60 
61  do_type_test("COMPOUNDCURVE((-3 -3,-1 0),CIRCULARSTRING(-1 0,0 1,0 -1),(0 -1,0 -1.5,0 -2),CIRCULARSTRING(0 -2,-1 -3,1 -3),(1 -3,5 5))",
62  LINETYPE);
63 
64  do_type_test("COMPOUNDCURVE(CIRCULARSTRING(-1 0,0 1,0 -1),CIRCULARSTRING(0 -1,-1 -2,1 -2))",
65  LINETYPE);
66 
67  do_type_test("CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING (0 0 2,1 1 2,1 0 2),(1 0 2,0 1 2),(0 1 2, 0 0 2)))",
68  POLYGONTYPE);
69 
70  do_type_test("CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (0 0 2 5,1 1 2 6,1 0 2 5), (1 0 2 3,0 1 2 2), (0 1 2 2,30 1 2 2), CIRCULARSTRING (30 1 2 2,12 1 2 6,1 10 2 5, 1 10 3 5, 0 0 2 5)))",
71  POLYGONTYPE);
72 
73  do_type_test("MULTISURFACE (CURVEPOLYGON (CIRCULARSTRING (-2 0, -1 -1, 0 0, 1 -1, 2 0, 0 2, -2 0), (-1 0, 0 0.5, 1 0, 0 1, -1 0)), ((7 8, 10 10, 6 14, 4 11, 7 8)))",
75 
76 }
77 
78 static void test_sfs_12(void)
79 {
80  do_geom_test("TRIANGLE((1 2,3 4,5 6,1 2))",
81  "POLYGON((1 2,3 4,5 6,1 2))");
82 
83  do_geom_test("GEOMETRYCOLLECTION(TRIANGLE((1 2,3 4,5 6,1 2)))",
84  "GEOMETRYCOLLECTION(POLYGON((1 2,3 4,5 6,1 2)))");
85 
86  do_geom_test("GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(TRIANGLE((1 2,3 4,5 6,1 2))))",
87  "GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POLYGON((1 2,3 4,5 6,1 2))))");
88 
89 
90  do_geom_test("TIN(((1 2,3 4,5 6,1 2)),((7 8,9 10,11 12,7 8)))",
91  "GEOMETRYCOLLECTION(POLYGON((1 2,3 4,5 6,1 2)),POLYGON((7 8,9 10,11 12,7 8)))");
92 
93  do_geom_test("GEOMETRYCOLLECTION(TIN(((1 2,3 4,5 6,1 2)),((7 8,9 10,11 12,7 8))))",
94  "GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POLYGON((1 2,3 4,5 6,1 2)),POLYGON((7 8,9 10,11 12,7 8))))");
95 
96  do_geom_test("GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(TIN(((1 2,3 4,5 6,1 2)),((7 8,9 10,11 12,7 8)))))",
97  "GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POLYGON((1 2,3 4,5 6,1 2)),POLYGON((7 8,9 10,11 12,7 8)))))");
98 
99 
100  do_geom_test("POLYHEDRALSURFACE(((1 2,3 4,5 6,1 2)),((7 8,9 10,11 12,7 8)))",
101  "GEOMETRYCOLLECTION(POLYGON((1 2,3 4,5 6,1 2)),POLYGON((7 8,9 10,11 12,7 8)))");
102 
103  do_geom_test("GEOMETRYCOLLECTION(POLYHEDRALSURFACE(((1 2,3 4,5 6,1 2)),((7 8,9 10,11 12,7 8))))",
104  "GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POLYGON((1 2,3 4,5 6,1 2)),POLYGON((7 8,9 10,11 12,7 8))))");
105 
106  do_geom_test("GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POLYGON((1 2,3 4,5 6,1 2)),POLYGON((7 8,9 10,11 12,7 8)))))",
107  "GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POLYGON((1 2,3 4,5 6,1 2)),POLYGON((7 8,9 10,11 12,7 8)))))");
108 
109 }
110 
111 static void test_sfs_11(void)
112 {
113  do_geom_test("POINT(1 2)",
114  "POINT(1 2)");
115 
116  do_geom_test("LINESTRING(1 2,3 4)",
117  "LINESTRING(1 2,3 4)");
118 
119  do_geom_test("POLYGON((1 2,3 4,5 6,1 2))",
120  "POLYGON((1 2,3 4,5 6,1 2))");
121 
122  do_geom_test("POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8))",
123  "POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8))");
124 
125  do_geom_test("MULTIPOINT(1 2,3 4)",
126  "MULTIPOINT(1 2,3 4)");
127 
128  do_geom_test("MULTILINESTRING((1 2,3 4),(5 6,7 8))",
129  "MULTILINESTRING((1 2,3 4),(5 6,7 8))");
130 
131  do_geom_test("MULTIPOLYGON(((1 2,3 4,5 6,1 2)),((7 8,9 10,11 12,7 8)))",
132  "MULTIPOLYGON(((1 2,3 4,5 6,1 2)),((7 8,9 10,11 12,7 8)))");
133 
134  do_geom_test("MULTIPOLYGON(((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8)),((13 14,15 16,17 18,13 14)))",
135  "MULTIPOLYGON(((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8)),((13 14,15 16,17 18,13 14)))");
136 
137  do_geom_test("GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(3 4,5 6))",
138  "GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(3 4,5 6))");
139 
140  do_geom_test("GEOMETRYCOLLECTION EMPTY",
141  "GEOMETRYCOLLECTION EMPTY");
142 
143  /* SRID */
144  do_geom_test("SRID=4326;GEOMETRYCOLLECTION EMPTY",
145  "SRID=4326;GEOMETRYCOLLECTION EMPTY");
146 
147  do_geom_test("SRID=4326;POINT(1 2)",
148  "SRID=4326;POINT(1 2)");
149 
150 
151  /* 3D and 4D */
152  /* SFS 1.2 is only 2D but we choose here to keep 3D and 4D,
153  and let the user use force_2d if he want/need it */
154  do_geom_test("POINT(1 2 3)",
155  "POINT(1 2 3)");
156 
157  do_geom_test("POINTM(1 2 3)",
158  "POINTM(1 2 3)");
159 
160  do_geom_test("POINT(1 2 3 4)",
161  "POINT(1 2 3 4)");
162 }
163 
164 /*
165 ** Used by test harness to register the tests in this file.
166 */
167 void force_sfs_suite_setup(void);
169 {
170  CU_pSuite suite = CU_add_suite("Force SFS", NULL, NULL);
171  PG_ADD_TEST(suite, test_sfs_11);
172  PG_ADD_TEST(suite, test_sfs_12);
173  PG_ADD_TEST(suite, test_sqlmm);
174 }
#define LINETYPE
Definition: liblwgeom.h:61
void lwfree(void *mem)
Definition: lwutil.c:190
#define POLYGONTYPE
Definition: liblwgeom.h:62
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:425
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
LWGEOM * lwgeom_force_sfs(LWGEOM *geom, int version)
Definition: lwgeom.c:700
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
static void test_sfs_11(void)
Definition: cu_force_sfs.c:111
#define PG_ADD_TEST(suite, testfunc)
static void test_sqlmm(void)
Definition: cu_force_sfs.c:53
static void do_type_test(char *in, int type)
Definition: cu_force_sfs.c:38
static void test_sfs_12(void)
Definition: cu_force_sfs.c:78
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:65
uint8_t type
Definition: liblwgeom.h:352
void force_sfs_suite_setup(void)
Definition: cu_force_sfs.c:168
static void do_geom_test(char *in, char *out)
Definition: cu_force_sfs.c:21