File: cu_out_encoded_polyline.c

package info (click to toggle)
postgis 2.3.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 58,660 kB
  • ctags: 10,181
  • sloc: ansic: 132,858; sql: 131,148; xml: 46,460; sh: 4,832; perl: 4,476; makefile: 2,749; python: 1,198; yacc: 442; lex: 131
file content (97 lines) | stat: -rw-r--r-- 2,395 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**********************************************************************
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.net
*
* Copyright 2014 Kashif Rasul <kashif.rasul@gmail.com> and
*                Shoaib Burq <saburq@gmail.com>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU General Public Licence. See the COPYING file.
*
**********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "CUnit/Basic.h"

#include "liblwgeom_internal.h"
#include "cu_tester.h"

static void do_encoded_polyline_test(char * in, int precision, char * out)
{
	LWGEOM *g;
	char * h;

	g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
	h = lwgeom_to_encoded_polyline(g, precision);

	if (strcmp(h, out))
		fprintf(stderr, "\nIn:   %s\nOut:  %s\nTheo: %s\n", in, h, out);

	CU_ASSERT_STRING_EQUAL(h, out);

	lwgeom_free(g);
	lwfree(h);
}


static void out_encoded_polyline_test_geoms(void)
{
	/* Linestring */
	do_encoded_polyline_test(
	    "LINESTRING(-120.2 38.5,-120.95 40.7,-126.453 43.252)",
	    5,
	    "_p~iF~ps|U_ulLnnqC_mqNvxq`@");

	/* MultiPoint */
	do_encoded_polyline_test(
	    "MULTIPOINT(-120.2 38.5,-120.95 40.7)",
	    5,
	    "_p~iF~ps|U_ulLnnqC");
}

static void out_encoded_polyline_test_srid(void)
{

	/* SRID - with PointArray */
	do_encoded_polyline_test(
	    "SRID=4326;LINESTRING(0 1,2 3)",
	    5,
	    "_ibE?_seK_seK");

	/* wrong SRID */
	do_encoded_polyline_test(
	    "SRID=4327;LINESTRING(0 1,2 3)",
	    5,
	    "_ibE?_seK_seK");
}

static void out_encoded_polyline_test_precision(void)
{

	/* Linestring */
	do_encoded_polyline_test(
	    "LINESTRING(-0.250691 49.283048,-0.250633 49.283376,-0.250502 49.283972,-0.251245 49.284028,-0.251938 49.284232,-0.251938 49.2842)",
	    6,
	    "o}~~|AdshNoSsBgd@eGoBlm@wKhj@~@?");

	/* MultiPoint */
	do_encoded_polyline_test(
	    "MULTIPOINT(-120.2 38.5,-120.95 40.7)",
	    3,
	    "gejAnwiFohCzm@");
}

/*
** Used by test harness to register the tests in this file.
*/
void out_encoded_polyline_suite_setup(void);
void out_encoded_polyline_suite_setup(void)
{
	CU_pSuite suite = CU_add_suite("encoded_polyline_output", NULL, NULL);
	PG_ADD_TEST(suite, out_encoded_polyline_test_geoms);
	PG_ADD_TEST(suite, out_encoded_polyline_test_srid);
	PG_ADD_TEST(suite, out_encoded_polyline_test_precision);
}