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