PostGIS  2.5.7dev-r@@SVN_REVISION@@
cu_filterm.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright 2018 Nicklas Avén <nicklas.aven@jordogskog.no>
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 <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include "CUnit/Basic.h"
17 
18 #include "liblwgeom_internal.h"
19 #include "cu_tester.h"
20 
21 static void do_test_filterm(char *geom_txt,char *expected, double min, double max)
22 {
23  LWGEOM *geom_in, *geom_out;
24  char *out_txt;
25  geom_in = lwgeom_from_wkt(geom_txt, LW_PARSER_CHECK_NONE);
26  geom_out = lwgeom_filter_m(geom_in,min, max, 1);
27  out_txt = lwgeom_to_wkt(geom_out, WKT_EXTENDED, 3, NULL);
28  if(strcmp(expected, out_txt))
29  printf("%s is not equal to %s\n", expected, out_txt);
30  CU_ASSERT_STRING_EQUAL(expected, out_txt)
31  lwfree(out_txt);
32  lwgeom_free(geom_in);
33  lwgeom_free(geom_out);
34  return;
35 }
36 
38 {
39  /*Point*/
40  do_test_filterm("POINT(0 0 0 0)","POINT(0 0 0 0)", 0, 11);
41  do_test_filterm("POINT(0 0 0 0)","POINT EMPTY", 1, 11);
42  /*Line*/
43  do_test_filterm("LINESTRING(0 0 0 0,1 1 0 2,2 2 0 5,3 1 0 3)","LINESTRING(1 1 0 2,3 1 0 3)",2,3);
44  do_test_filterm("LINESTRING(0 0 0 0,1 1 0 2,2 2 0 5,3 1 0 3)","LINESTRING EMPTY",10, 11);
45  /*Polygon*/
46  do_test_filterm("POLYGON((0 0 0 0,1 1 0 2,5 5 0 5,3 1 0 3,0 0 0 0))","POLYGON((0 0 0 0,1 1 0 2,3 1 0 3,0 0 0 0))",0,4);
47  do_test_filterm("POLYGON((0 0 0 0,1 1 0 2,5 5 0 5,3 1 0 3,0 0 0 0))","POLYGON EMPTY",10, 11);
48  return;
49 }
50 
51 static void do_test_filterm_collections(void)
52 {
53  do_test_filterm("GEOMETRYCOLLECTION(POINT(1 1 1 1), LINESTRING(1 1 1 1, 1 2 1 4, 2 2 1 3), POLYGON((0 0 0 4,1 1 0 2,5 5 0 5,3 1 0 3,0 0 0 4)))","GEOMETRYCOLLECTION(POINT(1 1 1 1),LINESTRING(1 1 1 1,1 2 1 4,2 2 1 3),POLYGON((0 0 0 4,1 1 0 2,3 1 0 3,0 0 0 4)))",0,4);
54  do_test_filterm("GEOMETRYCOLLECTION(POINT(1 1 1 1), LINESTRING(1 1 1 1, 1 2 1 4, 2 2 1 3), POLYGON((0 0 0 4,1 1 0 2,5 5 0 5,3 1 0 3,0 0 0 4)))","GEOMETRYCOLLECTION(LINESTRING(1 2 1 4,2 2 1 3),POLYGON((0 0 0 4,1 1 0 2,3 1 0 3,0 0 0 4)))",2,4);
55  return;
56 }
57 
58 void filterm_suite_setup(void);
60 {
61  CU_pSuite suite = CU_add_suite("filterm",NULL,NULL);
64 }
static void do_test_filterm(char *geom_txt, char *expected, double min, double max)
Definition: cu_filterm.c:21
static void do_test_filterm_collections(void)
Definition: cu_filterm.c:51
static void do_test_filterm_single_geometries(void)
Definition: cu_filterm.c:37
void filterm_suite_setup(void)
Definition: cu_filterm.c:59
#define PG_ADD_TEST(suite, testfunc)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
LWGEOM * lwgeom_filter_m(LWGEOM *geom, double min, double max, int returnm)
Definition: lwmval.c:221
#define WKT_EXTENDED
Definition: liblwgeom.h:2077
void lwfree(void *mem)
Definition: lwutil.c:244
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:676
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904