PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
cu_force_dims.c
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 *
6 * Copyright (C) 2008 Paul Ramsey
7 * Copyright (C) 2020 Kristian Thy <thy@42.dk>
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU General Public Licence. See the COPYING file.
11 *
12 **********************************************************************/
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17#include "CUnit/Basic.h"
18
19#include "liblwgeom_internal.h"
20#include "cu_tester.h"
21
22static void
24{
25 LWGEOM *geom;
26 LWGEOM *geom2d;
27 char *wkt_out;
28
29 geom = lwgeom_from_wkt("CIRCULARSTRINGM(-5 0 4,0 5 3,5 0 2,10 -5 1,15 0 0)", LW_PARSER_CHECK_NONE);
30 geom2d = lwgeom_force_2d(geom);
31 wkt_out = lwgeom_to_ewkt(geom2d);
32 ASSERT_STRING_EQUAL("CIRCULARSTRING(-5 0,0 5,5 0,10 -5,15 0)", wkt_out);
33 lwgeom_free(geom);
34 lwgeom_free(geom2d);
35 lwfree(wkt_out);
36
37 geom = lwgeom_from_wkt(
38 "GEOMETRYCOLLECTION(POINT(0 0 0),LINESTRING(1 1 1,2 2 2),POLYGON((0 0 1,0 1 1,1 1 1,1 0 1,0 0 1)),CURVEPOLYGON(CIRCULARSTRING(0 0 0,1 1 1,2 2 2,1 1 1,0 0 0)))",
40 geom2d = lwgeom_force_2d(geom);
41 wkt_out = lwgeom_to_ewkt(geom2d);
43 "GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(1 1,2 2),POLYGON((0 0,0 1,1 1,1 0,0 0)),CURVEPOLYGON(CIRCULARSTRING(0 0,1 1,2 2,1 1,0 0)))",
44 wkt_out);
45 lwgeom_free(geom);
46 lwgeom_free(geom2d);
47 lwfree(wkt_out);
48}
49
50static void
52{
53 LWGEOM *geom;
54 LWGEOM *geom3dm;
55 char *wkt_out;
56
57 geom = lwgeom_from_wkt("CIRCULARSTRING(-5 0 4,0 5 3,5 0 2,10 -5 1,15 0 0)", LW_PARSER_CHECK_NONE);
58 geom3dm = lwgeom_force_3dm(geom, 1);
59 wkt_out = lwgeom_to_ewkt(geom3dm);
60 ASSERT_STRING_EQUAL("CIRCULARSTRINGM(-5 0 1,0 5 1,5 0 1,10 -5 1,15 0 1)", wkt_out);
61 lwgeom_free(geom);
62 lwgeom_free(geom3dm);
63 lwfree(wkt_out);
64}
65
66static void
68{
69 LWGEOM *geom;
70 LWGEOM *geom3dz;
71 char *wkt_out;
72
73 geom = lwgeom_from_wkt("CIRCULARSTRING(-5 0,0 5,5 0,10 -5,15 0)", LW_PARSER_CHECK_NONE);
74 geom3dz = lwgeom_force_3dz(geom, -99);
75 wkt_out = lwgeom_to_ewkt(geom3dz);
76 ASSERT_STRING_EQUAL("CIRCULARSTRING(-5 0 -99,0 5 -99,5 0 -99,10 -5 -99,15 0 -99)", wkt_out);
77 lwgeom_free(geom);
78 lwgeom_free(geom3dz);
79 lwfree(wkt_out);
80
81 geom = lwgeom_from_wkt("CIRCULARSTRING(-5 0,0 5,5 0,10 -5,15 0)", LW_PARSER_CHECK_NONE);
82 geom3dz = lwgeom_force_3dz(geom, 0.0);
83 wkt_out = lwgeom_to_ewkt(geom3dz);
84 ASSERT_STRING_EQUAL("CIRCULARSTRING(-5 0 0,0 5 0,5 0 0,10 -5 0,15 0 0)", wkt_out);
85 lwgeom_free(geom);
86 lwgeom_free(geom3dz);
87 lwfree(wkt_out);
88}
89
90static void
92{
93 LWGEOM *geom;
94 LWGEOM *geom4d;
95 char *wkt_out;
96
97 geom = lwgeom_from_wkt("POINT(1 2)", LW_PARSER_CHECK_NONE);
98 geom4d = lwgeom_force_4d(geom, 3, 4);
99 wkt_out = lwgeom_to_ewkt(geom4d);
100 ASSERT_STRING_EQUAL("POINT(1 2 3 4)", wkt_out);
101 lwgeom_free(geom);
102 lwgeom_free(geom4d);
103 lwfree(wkt_out);
104}
105
106/*
107** Used by the test harness to register the tests in this file.
108*/
109void force_dims_suite_setup(void);
110void
112{
113 CU_pSuite suite = CU_add_suite("force_dims", NULL, NULL);
118}
static void test_force_3dm(void)
static void test_force_2d(void)
static void test_force_4d(void)
static void test_force_3dz(void)
void force_dims_suite_setup(void)
#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
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom, double zval)
Definition lwgeom.c:827
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition lwgeom.c:821
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an allocated string.
Definition lwgeom.c:593
void lwfree(void *mem)
Definition lwutil.c:248
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:940
LWGEOM * lwgeom_force_4d(const LWGEOM *geom, double zval, double mval)
Definition lwgeom.c:839
LWGEOM * lwgeom_force_3dm(const LWGEOM *geom, double mval)
Definition lwgeom.c:833