PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_lwmline_clip()

static void test_lwmline_clip ( void  )
static

Definition at line 576 of file cu_algorithm.c.

References LW_PARSER_CHECK_NONE, lwcollection_free(), lwfree(), lwgeom_from_wkt(), lwgeom_to_ewkt(), lwline_clip_to_ordinate_range(), lwline_free(), lwmline_clip_to_ordinate_range(), and lwmline_free().

Referenced by algorithms_suite_setup().

577 {
578  LWCOLLECTION *c;
579  char *ewkt;
580  LWMLINE *mline = NULL;
581  LWLINE *line = NULL;
582 
583  /*
584  ** Set up the input line. Trivial one-member case.
585  */
586  mline = (LWMLINE*)lwgeom_from_wkt("MULTILINESTRING((0 0,0 1,0 2,0 3,0 4))", LW_PARSER_CHECK_NONE);
587 
588  /* Clip in the middle, mid-range. */
589  c = lwmline_clip_to_ordinate_range(mline, 'Y', 1.5, 2.5);
590  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
591  //printf("c = %s\n", ewkt);
592  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 1.5,0 2,0 2.5))");
593  lwfree(ewkt);
595 
596  lwmline_free(mline);
597 
598  /*
599  ** Set up the input line. Two-member case.
600  */
601  mline = (LWMLINE*)lwgeom_from_wkt("MULTILINESTRING((1 0,1 1,1 2,1 3,1 4), (0 0,0 1,0 2,0 3,0 4))", LW_PARSER_CHECK_NONE);
602 
603  /* Clip off the top. */
604  c = lwmline_clip_to_ordinate_range(mline, 'Y', 3.5, 5.5);
605  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
606  //printf("c = %s\n", ewkt);
607  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((1 3.5,1 4),(0 3.5,0 4))");
608  lwfree(ewkt);
610 
611  lwmline_free(mline);
612 
613  /*
614  ** Set up staggered input line to create multi-type output.
615  */
616  mline = (LWMLINE*)lwgeom_from_wkt("MULTILINESTRING((1 0,1 -1,1 -2,1 -3,1 -4), (0 0,0 1,0 2,0 3,0 4))", LW_PARSER_CHECK_NONE);
617 
618  /* Clip from 0 upwards.. */
619  c = lwmline_clip_to_ordinate_range(mline, 'Y', 0.0, 2.5);
620  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
621  //printf("c = %s\n", ewkt);
622  CU_ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(1 0),LINESTRING(0 0,0 1,0 2,0 2.5))");
623  lwfree(ewkt);
625 
626  lwmline_free(mline);
627 
628  /*
629  ** Set up input line from MAC
630  */
631  line = (LWLINE*)lwgeom_from_wkt("LINESTRING(0 0 0 0,1 1 1 1,2 2 2 2,3 3 3 3,4 4 4 4,3 3 3 5,2 2 2 6,1 1 1 7,0 0 0 8)", LW_PARSER_CHECK_NONE);
632 
633  /* Clip from 3 to 3.5 */
634  c = lwline_clip_to_ordinate_range(line, 'Z', 3.0, 3.5);
635  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
636  //printf("c = %s\n", ewkt);
637  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((3 3 3 3,3.5 3.5 3.5 3.5),(3.5 3.5 3.5 4.5,3 3 3 5))");
638  lwfree(ewkt);
640 
641  /* Clip from 2 to 3.5 */
642  c = lwline_clip_to_ordinate_range(line, 'Z', 2.0, 3.5);
643  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
644  //printf("c = %s\n", ewkt);
645  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((2 2 2 2,3 3 3 3,3.5 3.5 3.5 3.5),(3.5 3.5 3.5 4.5,3 3 3 5,2 2 2 6))");
646  lwfree(ewkt);
648 
649  /* Clip from 3 to 4 */
650  c = lwline_clip_to_ordinate_range(line, 'Z', 3.0, 4.0);
651  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
652  //printf("c = %s\n", ewkt);
653  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((3 3 3 3,4 4 4 4,3 3 3 5))");
654  lwfree(ewkt);
656 
657  /* Clip from 2 to 3 */
658  c = lwline_clip_to_ordinate_range(line, 'Z', 2.0, 3.0);
659  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
660  //printf("c = %s\n", ewkt);
661  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((2 2 2 2,3 3 3 3),(3 3 3 5,2 2 2 6))");
662  lwfree(ewkt);
664 
665 
666  lwline_free(line);
667 
668 }
void lwmline_free(LWMLINE *mline)
Definition: lwmline.c:112
void lwfree(void *mem)
Definition: lwutil.c:244
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:518
void lwline_free(LWLINE *line)
Definition: lwline.c:76
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
LWCOLLECTION * lwline_clip_to_ordinate_range(const LWLINE *line, char ordinate, double from, double to)
Clip a line based on the from/to range of one of its ordinates.
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
LWCOLLECTION * lwmline_clip_to_ordinate_range(const LWMLINE *mline, char ordinate, double from, double to)
Clip a multi-line based on the from/to range of one of its ordinates.
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:340
Here is the call graph for this function:
Here is the caller graph for this function: