PostGIS  2.3.8dev-r@@SVN_REVISION@@
cu_clip_by_rect.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright (C) 2014 Sandro Santilli <strk@kbt.io>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU General Public Licence. See the COPYING file.
10  *
11  **********************************************************************/
12 
13 #include "CUnit/Basic.h"
14 #include "cu_tester.h"
15 
16 #include "liblwgeom.h"
17 #include "liblwgeom_internal.h"
18 
19 static void test_lwgeom_clip_by_rect(void)
20 {
21 #if POSTGIS_GEOS_VERSION >= 35
22  LWGEOM *in, *out;
23  const char *wkt;
24  char *tmp;
25 
26  /* Because i don't trust that much prior tests... ;) */
28 
29  wkt = "LINESTRING(0 0, 5 5, 10 0)";
31  out = lwgeom_clip_by_rect(in, 5, 0, 10, 10);
32  tmp = lwgeom_to_ewkt(out);
33  /* printf("%s\n", tmp); */
34  CU_ASSERT_STRING_EQUAL("LINESTRING(5 5,10 0)", tmp)
35  lwfree(tmp); lwgeom_free(out); lwgeom_free(in);
36 
37  wkt = "LINESTRING EMPTY";
39  out = lwgeom_clip_by_rect(in, 5, 0, 10, 10);
40  tmp = lwgeom_to_ewkt(out);
41  /* printf("%s\n", tmp); */
42  CU_ASSERT_STRING_EQUAL(wkt, tmp)
43  lwfree(tmp); lwgeom_free(out); lwgeom_free(in);
44 
45  wkt = "MULTIPOINT EMPTY";
47  out = lwgeom_clip_by_rect(in, 5, 0, 10, 10);
48  tmp = lwgeom_to_ewkt(out);
49  /* printf("%s\n", tmp); */
50  CU_ASSERT_STRING_EQUAL(wkt, tmp)
51  lwfree(tmp); lwgeom_free(out); lwgeom_free(in);
52 
53  wkt = "MULTIPOINT(0 0, 6 6, 7 5)";
55  out = lwgeom_clip_by_rect(in, 5, 0, 10, 10);
56  tmp = lwgeom_to_ewkt(out);
57  /* printf("%s\n", tmp); */
58  CU_ASSERT_STRING_EQUAL("MULTIPOINT(6 6,7 5)", tmp)
59  lwfree(tmp); lwgeom_free(out); lwgeom_free(in);
60 
61  /* Disjoint polygon */
62  wkt = "POLYGON((311017 4773762,311016 4773749,311006 4773744,310990 4773748,310980 4773758,310985 4773771,311003 4773776,311017 4773762))";
64  out = lwgeom_clip_by_rect(in, -80, -80, 80, 80);
65  //tmp = lwgeom_to_ewkt(out); printf("%s\n", tmp); lwfree(tmp);
66  CU_ASSERT(lwgeom_is_empty(out));
67  lwgeom_free(out); lwgeom_free(in);
68 
69 #endif /* POSTGIS_GEOS_VERSION >= 35 */
70 }
71 
72 /*
73 ** Used by test harness to register the tests in this file.
74 */
75 void clip_by_rect_suite_setup(void);
77 {
78  CU_pSuite suite = CU_add_suite("clip_by_rectangle", NULL, NULL);
80 }
static void test_lwgeom_clip_by_rect(void)
void lwfree(void *mem)
Definition: lwutil.c:242
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:482
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
void clip_by_rect_suite_setup(void)
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1985
void cu_error_msg_reset()
#define PG_ADD_TEST(suite, testfunc)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1310
This library is the generic geometry handling section of PostGIS.