PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
cu_out_wkb.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 hex WKB strings
22*/
23static char *s;
24
25/*
26** The suite initialization function.
27** Create any reused objects.
28*/
29static int init_wkb_out_suite(void)
30{
31 s = NULL;
32 return 0;
33}
34
35/*
36** The suite cleanup function.
37** Frees any global objects.
38*/
39static int clean_wkb_out_suite(void)
40{
41 if (s) free(s);
42 s = NULL;
43 return 0;
44}
45
46/*
47** Creating an input from a hexwkb
48*/
49static void cu_wkb_from_hexwkb(char *hexwkb)
50{
52 if ( s ) free(s);
54 lwgeom_free(g);
55}
56
57/*
58** Creating an input WKB from a wkb string
59*/
60static void cu_wkb(char *wkt)
61{
63 if ( s ) free(s);
65 lwgeom_free(g);
66}
67
68static void cu_wkb_empty_point_check(char *hex)
69{
70 LWGEOM *g;
72 CU_ASSERT(g != NULL);
73 CU_ASSERT(lwgeom_is_empty(g));
74 CU_ASSERT(g->type == POINTTYPE);
75 lwgeom_free(g);
76}
77
78static void test_wkb_out_point(void)
79{
80 cu_wkb("POINT(0 0 0 0)");
81 ASSERT_STRING_EQUAL(s,"00C00000010000000000000000000000000000000000000000000000000000000000000000");
82
83 cu_wkb("SRID=4;POINTM(1 1 1)");
84 ASSERT_STRING_EQUAL(s,"0060000001000000043FF00000000000003FF00000000000003FF0000000000000");
85
86 cu_wkb("POINT EMPTY");
88
89 cu_wkb("SRID=4326;POINT EMPTY");
91
92 cu_wkb("POINT Z EMPTY");
94
95 cu_wkb("POINT M EMPTY");
97
98 cu_wkb("POINT ZM EMPTY");
100}
101
102static void test_wkb_out_linestring(void)
103{
104 cu_wkb("LINESTRING(0 0,1 1)");
105 ASSERT_STRING_EQUAL(s,"000000000200000002000000000000000000000000000000003FF00000000000003FF0000000000000");
106
107 cu_wkb("LINESTRING(0 0 1,1 1 2,2 2 3)");
108 ASSERT_STRING_EQUAL(s,"008000000200000003000000000000000000000000000000003FF00000000000003FF00000000000003FF00000000000004000000000000000400000000000000040000000000000004008000000000000");
109
110 cu_wkb("LINESTRING EMPTY");
111 ASSERT_STRING_EQUAL(s,"000000000200000000");
112}
113
114static void test_wkb_out_polygon(void)
115{
116 cu_wkb("SRID=4;POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))");
117 ASSERT_STRING_EQUAL(s,"00A000000300000004000000010000000500000000000000000000000000000000000000000000000000000000000000003FF000000000000000000000000000003FF00000000000003FF000000000000000000000000000003FF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
118
119 cu_wkb("SRID=14;POLYGON((0 0 0 1,0 1 0 2,1 1 0 3,1 0 0 4,0 0 0 5))");
120 ASSERT_STRING_EQUAL(s,"00E00000030000000E00000001000000050000000000000000000000000000000000000000000000003FF000000000000000000000000000003FF0000000000000000000000000000040000000000000003FF00000000000003FF0000000000000000000000000000040080000000000003FF00000000000000000000000000000000000000000000040100000000000000000000000000000000000000000000000000000000000004014000000000000");
121
122 cu_wkb("SRID=4;POLYGON((0 0 0 1,0 1 0 2,1 1 0 3,1 0 0 4,0 0 0 5))");
123 ASSERT_STRING_EQUAL(s,"00E00000030000000400000001000000050000000000000000000000000000000000000000000000003FF000000000000000000000000000003FF0000000000000000000000000000040000000000000003FF00000000000003FF0000000000000000000000000000040080000000000003FF00000000000000000000000000000000000000000000040100000000000000000000000000000000000000000000000000000000000004014000000000000");
124
125 cu_wkb("POLYGON EMPTY");
126 ASSERT_STRING_EQUAL(s,"000000000300000000");
127
128 /*
129 * POLYGON with EMPTY shell
130 * See http://http://trac.osgeo.org/postgis/ticket/937
131 */
132 cu_wkb_from_hexwkb("01030000000100000000000000");
133 ASSERT_STRING_EQUAL(s,"000000000300000000");
134}
135
136static void test_wkb_out_multipoint(void)
137{
138 cu_wkb("SRID=4;MULTIPOINT(0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)");
139 ASSERT_STRING_EQUAL(s,"00A000000400000004000000050080000001000000000000000000000000000000000000000000000000008000000100000000000000003FF0000000000000000000000000000000800000013FF00000000000003FF0000000000000000000000000000000800000013FF0000000000000000000000000000000000000000000000080000001000000000000000000000000000000000000000000000000");
140
141 cu_wkb("MULTIPOINT(0 0 0, 0.26794919243112270647255365849413 1 3)");
142 ASSERT_STRING_EQUAL(s,"008000000400000002008000000100000000000000000000000000000000000000000000000000800000013FD126145E9ECD563FF00000000000004008000000000000");
143
144 cu_wkb("MULTIPOINT EMPTY");
145 ASSERT_STRING_EQUAL(s,"000000000400000000");
146}
147
149
151{
152 cu_wkb("SRID=14;MULTIPOLYGON(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((-1 -1 0,-1 2 0,2 2 0,2 -1 0,-1 -1 0),(0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)))");
153 ASSERT_STRING_EQUAL(s,"00A00000060000000E000000020080000003000000010000000500000000000000000000000000000000000000000000000000000000000000003FF000000000000000000000000000003FF00000000000003FF000000000000000000000000000003FF00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000030000000200000005BFF0000000000000BFF00000000000000000000000000000BFF0000000000000400000000000000000000000000000004000000000000000400000000000000000000000000000004000000000000000BFF00000000000000000000000000000BFF0000000000000BFF000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000003FF000000000000000000000000000003FF00000000000003FF000000000000000000000000000003FF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
154
155 cu_wkb("MULTIPOLYGON EMPTY");
156 ASSERT_STRING_EQUAL(s,"000000000600000000");
157}
158
159static void test_wkb_out_collection(void)
160{
161 cu_wkb("SRID=14;GEOMETRYCOLLECTION(POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),POINT(1 1 1))");
162 ASSERT_STRING_EQUAL(s,"00A00000070000000E000000020080000003000000010000000500000000000000000000000000000000000000000000000000000000000000003FF000000000000000000000000000003FF00000000000003FF000000000000000000000000000003FF00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000013FF00000000000003FF00000000000003FF0000000000000");
163
164 cu_wkb("GEOMETRYCOLLECTION EMPTY");
165 ASSERT_STRING_EQUAL(s,"000000000700000000");
166
167 cu_wkb("GEOMETRYCOLLECTION(LINESTRING EMPTY)");
168 ASSERT_STRING_EQUAL(s,"000000000700000001000000000200000000");
169
170 cu_wkb("GEOMETRYCOLLECTION(LINESTRING EMPTY, MULTILINESTRING(EMPTY,EMPTY))");
171 // printf("%s\n",s );
172 ASSERT_STRING_EQUAL(s,"000000000700000002000000000200000000000000000500000002000000000200000000000000000200000000");
173}
174
176{
177 cu_wkb("CIRCULARSTRING(0 -2,-2 0,0 2,2 0,0 -2)");
178 ASSERT_STRING_EQUAL(s,"0000000008000000050000000000000000C000000000000000C000000000000000000000000000000000000000000000004000000000000000400000000000000000000000000000000000000000000000C000000000000000");
179
180 cu_wkb("CIRCULARSTRING(-5 0 0 4, 0 5 1 3, 5 0 2 2, 10 -5 3 1, 15 0 4 0)");
181 ASSERT_STRING_EQUAL(s,"00C000000800000005C014000000000000000000000000000000000000000000004010000000000000000000000000000040140000000000003FF0000000000000400800000000000040140000000000000000000000000000400000000000000040000000000000004024000000000000C01400000000000040080000000000003FF0000000000000402E000000000000000000000000000040100000000000000000000000000000");
182
183 cu_wkb("SRID=43;CIRCULARSTRING(-5 0 0 4, 0 5 1 3, 5 0 2 2, 10 -5 3 1, 15 0 4 0)");
184 ASSERT_STRING_EQUAL(s,"00E00000080000002B00000005C014000000000000000000000000000000000000000000004010000000000000000000000000000040140000000000003FF0000000000000400800000000000040140000000000000000000000000000400000000000000040000000000000004024000000000000C01400000000000040080000000000003FF0000000000000402E000000000000000000000000000040100000000000000000000000000000");
185}
186
188{
189 cu_wkb("COMPOUNDCURVE(CIRCULARSTRING(0 0 0, 0.26794919243112270647255365849413 1 3, 0.5857864376269049511983112757903 1.4142135623730950488016887242097 1),(0.5857864376269049511983112757903 1.4142135623730950488016887242097 1,2 0 0,0 0 0))");
190 ASSERT_STRING_EQUAL(s,"0080000009000000020080000008000000030000000000000000000000000000000000000000000000003FD126145E9ECD563FF000000000000040080000000000003FE2BEC3330188673FF6A09E667F3BCD3FF00000000000000080000002000000033FE2BEC3330188673FF6A09E667F3BCD3FF0000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
191}
192
194{
195 cu_wkb("CURVEPOLYGON(CIRCULARSTRING(-2 0 0 0,-1 -1 1 2,0 0 2 4,1 -1 3 6,2 0 4 8,0 2 2 4,-2 0 0 0),(-1 0 1 2,0 0.5 2 4,1 0 3 6,0 1 3 4,-1 0 1 2))");
196 ASSERT_STRING_EQUAL(s,"00C000000A0000000200C000000800000007C000000000000000000000000000000000000000000000000000000000000000BFF0000000000000BFF00000000000003FF0000000000000400000000000000000000000000000000000000000000000400000000000000040100000000000003FF0000000000000BFF00000000000004008000000000000401800000000000040000000000000000000000000000000401000000000000040200000000000000000000000000000400000000000000040000000000000004010000000000000C00000000000000000000000000000000000000000000000000000000000000000C000000200000005BFF000000000000000000000000000003FF0000000000000400000000000000000000000000000003FE0000000000000400000000000000040100000000000003FF000000000000000000000000000004008000000000000401800000000000000000000000000003FF000000000000040080000000000004010000000000000BFF000000000000000000000000000003FF00000000000004000000000000000");
197}
198
199static void test_wkb_out_multicurve(void) {}
200
201static void test_wkb_out_multisurface(void) {}
202
204{
205// cu_wkb("POLYHEDRALSURFACE(((0 0 0 0,0 0 1 0,0 1 0 2,0 0 0 0)),((0 0 0 0,0 1 0 0,1 0 0 4,0 0 0 0)),((0 0 0 0,1 0 0 0,0 0 1 6,0 0 0 0)),((1 0 0 0,0 1 0 0,0 0 1 0,1 0 0 0)))");
206// ASSERT_STRING_EQUAL(s, t);
207// printf("\nnew: %s\nold: %s\n",s,t);
208}
209
210/*
211** Used by test harness to register the tests in this file.
212*/
213void wkb_out_suite_setup(void);
static void test_wkb_out_multicurve(void)
Definition cu_out_wkb.c:199
static void test_wkb_out_collection(void)
Definition cu_out_wkb.c:159
static void cu_wkb(char *wkt)
Definition cu_out_wkb.c:60
static void test_wkb_out_compoundcurve(void)
Definition cu_out_wkb.c:187
static void test_wkb_out_linestring(void)
Definition cu_out_wkb.c:102
static void cu_wkb_empty_point_check(char *hex)
Definition cu_out_wkb.c:68
static void test_wkb_out_curvpolygon(void)
Definition cu_out_wkb.c:193
static int clean_wkb_out_suite(void)
Definition cu_out_wkb.c:39
static void test_wkb_out_multipoint(void)
Definition cu_out_wkb.c:136
static void test_wkb_out_multilinestring(void)
Definition cu_out_wkb.c:148
static void cu_wkb_from_hexwkb(char *hexwkb)
Definition cu_out_wkb.c:49
static void test_wkb_out_multisurface(void)
Definition cu_out_wkb.c:201
static int init_wkb_out_suite(void)
Definition cu_out_wkb.c:29
static void test_wkb_out_polyhedralsurface(void)
Definition cu_out_wkb.c:203
static void test_wkb_out_multipolygon(void)
Definition cu_out_wkb.c:150
void wkb_out_suite_setup(void)
Definition cu_out_wkb.c:214
static char * s
Definition cu_out_wkb.c:23
static void test_wkb_out_polygon(void)
Definition cu_out_wkb.c:114
static void test_wkb_out_point(void)
Definition cu_out_wkb.c:78
static void test_wkb_out_circularstring(void)
Definition cu_out_wkb.c:175
#define PG_ADD_TEST(suite, testfunc)
#define ASSERT_STRING_EQUAL(o, e)
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2149
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:102
#define WKB_HEX
Definition liblwgeom.h:2215
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition lwin_wkb.c:866
#define WKB_EXTENDED
Definition liblwgeom.h:2212
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:940
#define WKB_XDR
Definition liblwgeom.h:2214
uint8_t * lwgeom_to_wkb_buffer(const LWGEOM *geom, uint8_t variant)
Definition lwout_wkb.c:815
void free(void *)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199
uint8_t type
Definition liblwgeom.h:462