PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ test_lwgeom_simplify()

static void test_lwgeom_simplify ( void  )
static

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

929 {
930  LWGEOM *l;
931  LWGEOM *g;
932  char *ewkt;
933 
934  /* Simplify but only so far... */
935  g = lwgeom_from_wkt("LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)", LW_PARSER_CHECK_NONE);
936  l = lwgeom_simplify(g, 10, LW_TRUE);
937  ewkt = lwgeom_to_ewkt(l);
938  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,0 0)");
939  lwgeom_free(g);
940  lwgeom_free(l);
941  lwfree(ewkt);
942 
943  /* Simplify but only so far... */
944  g = lwgeom_from_wkt("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", LW_PARSER_CHECK_NONE);
945  l = lwgeom_simplify(g, 10, LW_TRUE);
946  ewkt = lwgeom_to_ewkt(l);
947  CU_ASSERT_STRING_EQUAL(ewkt, "POLYGON((0 0,1 0,1 1,0 0))");
948  lwgeom_free(g);
949  lwgeom_free(l);
950  lwfree(ewkt);
951 
952  /* Simplify and collapse */
953  g = lwgeom_from_wkt("LINESTRING(0 0, 1 0, 1 1, 0 1, 0 0)", LW_PARSER_CHECK_NONE);
954  l = lwgeom_simplify(g, 10, LW_FALSE);
955  CU_ASSERT_EQUAL(l, NULL);
956  lwgeom_free(g);
957  lwgeom_free(l);
958 
959  /* Simplify and collapse */
960  g = lwgeom_from_wkt("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", LW_PARSER_CHECK_NONE);
961  l = lwgeom_simplify(g, 10, LW_FALSE);
962  CU_ASSERT_EQUAL(l, NULL);
963  lwgeom_free(g);
964  lwgeom_free(l);
965 
966  /* Not simplifiable */
967  g = lwgeom_from_wkt("LINESTRING(0 0, 50 1.00001, 100 0)", LW_PARSER_CHECK_NONE);
968  l = lwgeom_simplify(g, 1.0, LW_FALSE);
969  ewkt = lwgeom_to_ewkt(l);
970  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,50 1.00001,100 0)");
971  lwgeom_free(g);
972  lwgeom_free(l);
973  lwfree(ewkt);
974 
975  /* Simplifiable */
976  g = lwgeom_from_wkt("LINESTRING(0 0,50 0.99999,100 0)", LW_PARSER_CHECK_NONE);
977  l = lwgeom_simplify(g, 1.0, LW_FALSE);
978  ewkt = lwgeom_to_ewkt(l);
979  CU_ASSERT_STRING_EQUAL(ewkt, "LINESTRING(0 0,100 0)");
980  lwgeom_free(g);
981  lwgeom_free(l);
982  lwfree(ewkt);
983 }
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_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1985
#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:1571
Here is the call graph for this function:
Here is the caller graph for this function: