PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_lwgeom_simplify()

static void test_lwgeom_simplify ( void  )
static

Definition at line 1058 of file cu_algorithm.c.

1059 {
1060  LWGEOM *l;
1061  LWGEOM *g;
1062  char *ewkt;
1063 
1064  /* Simplify but only so far... */
1065  g = lwgeom_from_wkt("LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)", LW_PARSER_CHECK_NONE);
1066  l = lwgeom_simplify(g, 10, LW_TRUE);
1067  ewkt = lwgeom_to_ewkt(l);
1068  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,0 0)");
1069  lwgeom_free(g);
1070  lwgeom_free(l);
1071  lwfree(ewkt);
1072 
1073  /* Simplify but only so far... */
1074  g = lwgeom_from_wkt("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", LW_PARSER_CHECK_NONE);
1075  l = lwgeom_simplify(g, 10, LW_TRUE);
1076  ewkt = lwgeom_to_ewkt(l);
1077  CU_ASSERT_STRING_EQUAL(ewkt, "POLYGON((0 0,1 0,1 1,0 0))");
1078  lwgeom_free(g);
1079  lwgeom_free(l);
1080  lwfree(ewkt);
1081 
1082  /* Simplify and collapse */
1083  g = lwgeom_from_wkt("LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)", LW_PARSER_CHECK_NONE);
1084  l = lwgeom_simplify(g, 10, LW_FALSE);
1085  CU_ASSERT_EQUAL(l, NULL);
1086  lwgeom_free(g);
1087  lwgeom_free(l);
1088 
1089  /* Simplify and collapse */
1090  g = lwgeom_from_wkt("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", LW_PARSER_CHECK_NONE);
1091  l = lwgeom_simplify(g, 10, LW_FALSE);
1092  CU_ASSERT_EQUAL(l, NULL);
1093  lwgeom_free(g);
1094  lwgeom_free(l);
1095 
1096  /* Not simplifiable */
1097  g = lwgeom_from_wkt("LINESTRING(0 0, 50 1.00001, 100 0)", LW_PARSER_CHECK_NONE);
1098  l = lwgeom_simplify(g, 1.0, LW_FALSE);
1099  ewkt = lwgeom_to_ewkt(l);
1100  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,50 1.00001,100 0)");
1101  lwgeom_free(g);
1102  lwgeom_free(l);
1103  lwfree(ewkt);
1104 
1105  /* Simplifiable */
1106  g = lwgeom_from_wkt("LINESTRING(0 0,50 0.99999,100 0)", LW_PARSER_CHECK_NONE);
1107  l = lwgeom_simplify(g, 1.0, LW_FALSE);
1108  ewkt = lwgeom_to_ewkt(l);
1109  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,100 0)");
1110  lwgeom_free(g);
1111  lwgeom_free(l);
1112  lwfree(ewkt);
1113 }
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1857
#define LW_FALSE
Definition: liblwgeom.h:77
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:556
void lwfree(void *mem)
Definition: lwutil.c:244
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76

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().

Here is the call graph for this function:
Here is the caller graph for this function: