PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_lwgeom_simplify()

static void test_lwgeom_simplify ( void  )
static

Definition at line 945 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().

946 {
947  LWGEOM *l;
948  LWGEOM *g;
949  char *ewkt;
950 
951  /* Simplify but only so far... */
952  g = lwgeom_from_wkt("LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)", LW_PARSER_CHECK_NONE);
953  l = lwgeom_simplify(g, 10, LW_TRUE);
954  ewkt = lwgeom_to_ewkt(l);
955  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,0 0)");
956  lwgeom_free(g);
957  lwgeom_free(l);
958  lwfree(ewkt);
959 
960  /* Simplify but only so far... */
961  g = lwgeom_from_wkt("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", LW_PARSER_CHECK_NONE);
962  l = lwgeom_simplify(g, 10, LW_TRUE);
963  ewkt = lwgeom_to_ewkt(l);
964  CU_ASSERT_STRING_EQUAL(ewkt, "POLYGON((0 0,1 0,1 1,0 0))");
965  lwgeom_free(g);
966  lwgeom_free(l);
967  lwfree(ewkt);
968 
969  /* Simplify and collapse */
970  g = lwgeom_from_wkt("LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)", LW_PARSER_CHECK_NONE);
971  l = lwgeom_simplify(g, 10, LW_FALSE);
972  CU_ASSERT_EQUAL(l, NULL);
973  lwgeom_free(g);
974  lwgeom_free(l);
975 
976  /* Simplify and collapse */
977  g = lwgeom_from_wkt("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", LW_PARSER_CHECK_NONE);
978  l = lwgeom_simplify(g, 10, LW_FALSE);
979  CU_ASSERT_EQUAL(l, NULL);
980  lwgeom_free(g);
981  lwgeom_free(l);
982 
983  /* Not simplifiable */
984  g = lwgeom_from_wkt("LINESTRING(0 0, 50 1.00001, 100 0)", LW_PARSER_CHECK_NONE);
985  l = lwgeom_simplify(g, 1.0, LW_FALSE);
986  ewkt = lwgeom_to_ewkt(l);
987  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,50 1.00001,100 0)");
988  lwgeom_free(g);
989  lwgeom_free(l);
990  lwfree(ewkt);
991 
992  /* Simplifiable */
993  g = lwgeom_from_wkt("LINESTRING(0 0,50 0.99999,100 0)", LW_PARSER_CHECK_NONE);
994  l = lwgeom_simplify(g, 1.0, LW_FALSE);
995  ewkt = lwgeom_to_ewkt(l);
996  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,100 0)");
997  lwgeom_free(g);
998  lwgeom_free(l);
999  lwfree(ewkt);
1000 }
void lwfree(void *mem)
Definition: lwutil.c:244
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:518
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1602
Here is the call graph for this function:
Here is the caller graph for this function: