PostGIS  2.4.9dev-r@@SVN_REVISION@@
cu_out_encoded_polyline.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright 2014 Kashif Rasul <kashif.rasul@gmail.com> and
7  * Shoaib Burq <saburq@gmail.com>
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 
22 static void
23 do_encoded_polyline_test(char* in, int precision, char* out)
24 {
25  LWGEOM* g;
26  char* h;
27 
29  h = lwgeom_to_encoded_polyline(g, precision);
30 
31  if (strcmp(h, out))
32  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
33 
34  CU_ASSERT_STRING_EQUAL(h, out);
35 
36  lwgeom_free(g);
37  lwfree(h);
38 }
39 
40 static void
42 {
43  /* Magic Linestring */
45  "SRID=4326;LINESTRING(33.6729 38.7071,33.6692 38.701,"
46  "33.6673 38.6972,33.6626 38.6871)",
47  5,
48  "k~fkFsvolEbe@bVvVzJb~@j\\");
49 
50  /* Linestring */
52  "LINESTRING(-120.2 38.5,-120.95 40.7,-126.453 43.252)",
53  5,
54  "_p~iF~ps|U_ulLnnqC_mqNvxq`@");
55  do_encoded_polyline_test("LINESTRING EMPTY", 5, "");
56 
57  /* MultiPoint */
59  "MULTIPOINT(-120.2 38.5,-120.95 40.7)", 5, "_p~iF~ps|U_ulLnnqC");
60  do_encoded_polyline_test("MULTIPOINT EMPTY", 5, "");
61 }
62 
63 static void
65 {
66 
67  /* SRID - with PointArray */
69  "SRID=4326;LINESTRING(0 1,2 3)", 5, "_ibE?_seK_seK");
70 
71  /* wrong SRID */
73  "SRID=4327;LINESTRING(0 1,2 3)", 5, "_ibE?_seK_seK");
74 }
75 
76 static void
78 {
79 
80  /* Linestring */
82  "LINESTRING(-0.250691 49.283048, -0.250633 49.283376,"
83  "-0.250502 49.283972, -0.251245 49.284028, -0.251938 "
84  "49.284232, -0.251938 49.2842)",
85  6,
86  "o}~~|AdshNoSsBgd@eGoBlm@wKhj@~@?");
87 
88  /* MultiPoint */
90  "MULTIPOINT(-120.2 38.5,-120.95 40.7)", 3, "gejAnwiFohCzm@");
91 }
92 
93 /*
94 ** Used by test harness to register the tests in this file.
95 */
97 void
99 {
100  CU_pSuite suite = CU_add_suite("encoded_polyline_output", NULL, NULL);
104 }
void lwfree(void *mem)
Definition: lwutil.c:244
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
char * lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision)
static void out_encoded_polyline_test_precision(void)
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
void out_encoded_polyline_suite_setup(void)
static void out_encoded_polyline_test_srid(void)
#define PG_ADD_TEST(suite, testfunc)
uint8_t precision
Definition: cu_in_twkb.c:25
static void out_encoded_polyline_test_geoms(void)
static void do_encoded_polyline_test(char *in, int precision, char *out)