PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
cu_out_x3d.c
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 * Copyright 2011-2016 Regina Obe
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_x3d3_test(char * in, char * out, char * srs, int precision, int option)
21{
22 LWGEOM *g;
23 char * h;
24
26 h = lwgeom_to_x3d3(g, srs, precision, option, "");
27
28 if (strcmp(h, out))
29 fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
30
31 CU_ASSERT_STRING_EQUAL(h, out);
32
33 lwgeom_free(g);
34 lwfree(h);
35}
36
37
38static void do_x3d3_unsupported(char * in, char * out)
39{
40 LWGEOM *g;
41 char *h;
42
44 h = lwgeom_to_x3d3(g, NULL, 0, 0, "");
45
46 if (strcmp(cu_error_msg, out))
47 fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n",
48 in, cu_error_msg, out);
49
50 CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
52
53 lwfree(h);
54 lwgeom_free(g);
55}
56
57
58static void out_x3d3_test_precision(void)
59{
60 /* 0 precision, i.e a round */
62 "POINT(1.1111111111111 1.1111111111111 2.11111111111111)",
63 "1 1 2",
64 NULL, 0, 0);
65
66 /* 3 digits precision */
68 "POINT(1.1111111111111 1.1111111111111 2.11111111111111)",
69 "1.111 1.111 2.111",
70 NULL, 3, 0);
71
72 /* 9 digits precision */
74 "POINT(1.2345678901234 1.2345678901234 4.123456789001)",
75 "1.23456789 1.23456789 4.123456789",
76 NULL, 9, 0);
77
78 /* huge data */
80 "POINT(1E300 -105E-153 4E300)", "1e+300 0 4e+300", NULL, 0, 0);
81}
82
83
84static void out_x3d3_test_geoms(void)
85{
86 /* Linestring */
88 "LINESTRING(0 1 5,2 3 6,4 5 7)",
89 "<LineSet vertexCount='3'><Coordinate point='0 1 5 2 3 6 4 5 7' /></LineSet>",
90 NULL, 0, 0);
91
92 /* Polygon **/
94 "POLYGON((15 10 3,13.536 6.464 3,10 5 3,6.464 6.464 3,5 10 3,6.464 13.536 3,10 15 3,13.536 13.536 3,15 10 3))",
95 "<IndexedFaceSet convex='false' coordIndex='0 1 2 3 4 5 6 7'><Coordinate point='15 10 3 13.536 6.464 3 10 5 3 6.464 6.464 3 5 10 3 6.464 13.536 3 10 15 3 13.536 13.536 3 ' /></IndexedFaceSet>",
96 NULL, 3, 0);
97
98 /* TODO: Polygon - with internal ring - the answer is clearly wrong */
104 /* 2D MultiPoint */
106 "MULTIPOINT(0 1,2 3,4 5)",
107 "<Polypoint2D point='0 1 2 3 4 5 ' />",
108 NULL, 0, 0);
109
110 /* 3D MultiPoint */
112 "MULTIPOINT Z(0 1 1,2 3 4,4 5 5)",
113 "<PointSet ><Coordinate point='0 1 1 2 3 4 4 5 5 ' /></PointSet>",
114 NULL, 0, 0);
115 /* 3D Multiline */
117 "MULTILINESTRING Z((0 1 1,2 3 4,4 5 5),(6 7 5,8 9 8,10 11 5))",
118 "<IndexedLineSet coordIndex='0 1 2 -1 3 4 5'><Coordinate point='0 1 1 2 3 4 4 5 5 6 7 5 8 9 8 10 11 5 ' /></IndexedLineSet>",
119 NULL, 0, 0);
120
121 /* MultiPolygon */
123 "MULTIPOLYGON(((0 1 1,2 3 1,4 5 1,0 1 1)),((6 7 1,8 9 1,10 11 1,6 7 1)))",
124 "<IndexedFaceSet convex='false' coordIndex='0 1 2 -1 3 4 5'><Coordinate point='0 1 1 2 3 1 4 5 1 6 7 1 8 9 1 10 11 1 ' /></IndexedFaceSet>",
125 NULL, 0, 0);
126
127 /* PolyhedralSurface */
129 "POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)), ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), ((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)), ((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )",
130 "<IndexedFaceSet convex='false' coordIndex='0 1 2 3 -1 4 5 6 7 -1 8 9 10 11 -1 12 13 14 15 -1 16 17 18 19 -1 20 21 22 23'><Coordinate point='0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 1 1 1 0 1 1 1 1 0 1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 0 1 1 1 1 0 1 1' /></IndexedFaceSet>",
131 NULL, 0, 0);
132
133 /* TODO: returns garbage at moment correctly implement GeometryCollection -- */
139 /* TODO: Implement Empty GeometryCollection correctly or throw a not-implemented */
145 /* CircularString */
147 "CIRCULARSTRING(-2 0 1,0 2 1,2 0 1,0 2 1,2 4 1)",
148 "lwgeom_to_x3d3: 'CircularString' geometry type not supported");
149
150 /* CompoundCurve */
152 "COMPOUNDCURVE(CIRCULARSTRING(0 0 1,1 1 1,1 0 1),(1 0 1,0 1 1))",
153 "lwgeom_to_x3d3: 'CompoundCurve' geometry type not supported");
154
155}
156
157static void out_x3d3_test_option(void)
158{
159 /* 0 precision, flip coordinates*/
161 "POINT(3.1111111111111 1.1111111111111 2.11111111111111)",
162 "1 3 2",
163 NULL, 0, 1);
164
165 /* geocoordinate long,lat*/
167 "SRID=4326;POLYGON((15 10 3,13.536 6.464 3,10 5 3,6.464 6.464 3,5 10 3,6.464 13.536 3,10 15 3,13.536 13.536 3,15 10 3))",
168 "<IndexedFaceSet convex='false' coordIndex='0 1 2 3 4 5 6 7'><GeoCoordinate geoSystem='\"GD\" \"WE\" \"longitude_first\"' point='15 10 3 13.536 6.464 3 10 5 3 6.464 6.464 3 5 10 3 6.464 13.536 3 10 15 3 13.536 13.536 3 ' /></IndexedFaceSet>",
169 NULL, 3, 2);
170
171 /* geocoordinate lat long*/
173 "SRID=4326;POLYGON((15 10 3,13.536 6.464 3,10 5 3,6.464 6.464 3,5 10 3,6.464 13.536 3,10 15 3,13.536 13.536 3,15 10 3))",
174 "<IndexedFaceSet convex='false' coordIndex='0 1 2 3 4 5 6 7'><GeoCoordinate geoSystem='\"GD\" \"WE\" \"latitude_first\"' point='10 15 3 6.464 13.536 3 5 10 3 6.464 6.464 3 10 5 3 13.536 6.464 3 15 10 3 13.536 13.536 3 ' /></IndexedFaceSet>",
175 NULL, 3, 3);
176}
177
178
179/*
180** Used by test harness to register the tests in this file.
181*/
182void out_x3d_suite_setup(void);
184{
185 CU_pSuite suite = CU_add_suite("x3d_output", NULL, NULL);
189}
static uint8_t precision
Definition cu_in_twkb.c:25
void out_x3d_suite_setup(void)
Definition cu_out_x3d.c:183
static void do_x3d3_unsupported(char *in, char *out)
Definition cu_out_x3d.c:38
static void out_x3d3_test_precision(void)
Definition cu_out_x3d.c:58
static void out_x3d3_test_option(void)
Definition cu_out_x3d.c:157
static void out_x3d3_test_geoms(void)
Definition cu_out_x3d.c:84
static void do_x3d3_test(char *in, char *out, char *srs, int precision, int option)
Definition cu_out_x3d.c:20
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
#define PG_ADD_TEST(suite, testfunc)
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
Definition lwout_x3d.c:36
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2060
void lwfree(void *mem)
Definition lwutil.c:242
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:905