PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_lwmline_clip ( void  )
static

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

574 {
575  LWCOLLECTION *c;
576  char *ewkt;
577  LWMLINE *mline = NULL;
578  LWLINE *line = NULL;
579 
580  /*
581  ** Set up the input line. Trivial one-member case.
582  */
583  mline = (LWMLINE*)lwgeom_from_wkt("MULTILINESTRING((0 0,0 1,0 2,0 3,0 4))", LW_PARSER_CHECK_NONE);
584 
585  /* Clip in the middle, mid-range. */
586  c = lwmline_clip_to_ordinate_range(mline, 'Y', 1.5, 2.5);
587  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
588  //printf("c = %s\n", ewkt);
589  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 1.5,0 2,0 2.5))");
590  lwfree(ewkt);
592 
593  lwmline_free(mline);
594 
595  /*
596  ** Set up the input line. Two-member case.
597  */
598  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);
599 
600  /* Clip off the top. */
601  c = lwmline_clip_to_ordinate_range(mline, 'Y', 3.5, 5.5);
602  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
603  //printf("c = %s\n", ewkt);
604  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((1 3.5,1 4),(0 3.5,0 4))");
605  lwfree(ewkt);
607 
608  lwmline_free(mline);
609 
610  /*
611  ** Set up staggered input line to create multi-type output.
612  */
613  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);
614 
615  /* Clip from 0 upwards.. */
616  c = lwmline_clip_to_ordinate_range(mline, 'Y', 0.0, 2.5);
617  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
618  //printf("c = %s\n", ewkt);
619  CU_ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(1 0),LINESTRING(0 0,0 1,0 2,0 2.5))");
620  lwfree(ewkt);
622 
623  lwmline_free(mline);
624 
625  /*
626  ** Set up input line from MAC
627  */
628  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);
629 
630  /* Clip from 3 to 3.5 */
631  c = lwline_clip_to_ordinate_range(line, 'Z', 3.0, 3.5);
632  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
633  //printf("c = %s\n", ewkt);
634  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))");
635  lwfree(ewkt);
637 
638  /* Clip from 2 to 3.5 */
639  c = lwline_clip_to_ordinate_range(line, 'Z', 2.0, 3.5);
640  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
641  //printf("c = %s\n", ewkt);
642  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))");
643  lwfree(ewkt);
645 
646  /* Clip from 3 to 4 */
647  c = lwline_clip_to_ordinate_range(line, 'Z', 3.0, 4.0);
648  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
649  //printf("c = %s\n", ewkt);
650  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((3 3 3 3,4 4 4 4,3 3 3 5))");
651  lwfree(ewkt);
653 
654  /* Clip from 2 to 3 */
655  c = lwline_clip_to_ordinate_range(line, 'Z', 2.0, 3.0);
656  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
657  //printf("c = %s\n", ewkt);
658  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((2 2 2 2,3 3 3 3),(3 3 3 5,2 2 2 6))");
659  lwfree(ewkt);
661 
662 
663  lwline_free(line);
664 
665 }
void lwmline_free(LWMLINE *mline)
Definition: lwmline.c:99
void lwfree(void *mem)
Definition: lwutil.c:190
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:425
void lwline_free(LWLINE *line)
Definition: lwline.c:63
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
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:1706
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:316

Here is the call graph for this function:

Here is the caller graph for this function: