PostGIS  2.5.0dev-r@@SVN_REVISION@@
static void test_lwgeom_simplify ( void  )
static

Definition at line 1041 of file cu_algorithm.c.

References LW_FALSE, LW_PARSER_CHECK_NONE, LW_TRUE, lwfree(), lwgeom_free(), lwgeom_from_wkt(), lwgeom_simplify(), and lwgeom_to_ewkt().

Referenced by algorithms_suite_setup().

1042 {
1043  LWGEOM *l;
1044  LWGEOM *g;
1045  char *ewkt;
1046 
1047  /* Simplify but only so far... */
1048  g = lwgeom_from_wkt("LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)", LW_PARSER_CHECK_NONE);
1049  l = lwgeom_simplify(g, 10, LW_TRUE);
1050  ewkt = lwgeom_to_ewkt(l);
1051  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,0 0)");
1052  lwgeom_free(g);
1053  lwgeom_free(l);
1054  lwfree(ewkt);
1055 
1056  /* Simplify but only so far... */
1057  g = lwgeom_from_wkt("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", LW_PARSER_CHECK_NONE);
1058  l = lwgeom_simplify(g, 10, LW_TRUE);
1059  ewkt = lwgeom_to_ewkt(l);
1060  CU_ASSERT_STRING_EQUAL(ewkt, "POLYGON((0 0,1 0,1 1,0 0))");
1061  lwgeom_free(g);
1062  lwgeom_free(l);
1063  lwfree(ewkt);
1064 
1065  /* Simplify and collapse */
1066  g = lwgeom_from_wkt("LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)", LW_PARSER_CHECK_NONE);
1067  l = lwgeom_simplify(g, 10, LW_FALSE);
1068  CU_ASSERT_EQUAL(l, NULL);
1069  lwgeom_free(g);
1070  lwgeom_free(l);
1071 
1072  /* Simplify and collapse */
1073  g = lwgeom_from_wkt("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", LW_PARSER_CHECK_NONE);
1074  l = lwgeom_simplify(g, 10, LW_FALSE);
1075  CU_ASSERT_EQUAL(l, NULL);
1076  lwgeom_free(g);
1077  lwgeom_free(l);
1078 
1079  /* Not simplifiable */
1080  g = lwgeom_from_wkt("LINESTRING(0 0, 50 1.00001, 100 0)", LW_PARSER_CHECK_NONE);
1081  l = lwgeom_simplify(g, 1.0, LW_FALSE);
1082  ewkt = lwgeom_to_ewkt(l);
1083  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,50 1.00001,100 0)");
1084  lwgeom_free(g);
1085  lwgeom_free(l);
1086  lwfree(ewkt);
1087 
1088  /* Simplifiable */
1089  g = lwgeom_from_wkt("LINESTRING(0 0,50 0.99999,100 0)", LW_PARSER_CHECK_NONE);
1090  l = lwgeom_simplify(g, 1.0, LW_FALSE);
1091  ewkt = lwgeom_to_ewkt(l);
1092  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,100 0)");
1093  lwgeom_free(g);
1094  lwgeom_free(l);
1095  lwfree(ewkt);
1096 }
void lwfree(void *mem)
Definition: lwutil.c:244
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:549
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1998
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1835

Here is the call graph for this function:

Here is the caller graph for this function: