PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_lwmline_clip()

static void test_lwmline_clip ( void  )
static

Definition at line 655 of file cu_algorithm.c.

656 {
657  LWCOLLECTION *c;
658  char *ewkt;
659  LWMLINE *mline = NULL;
660  LWLINE *line = NULL;
661 
662  /*
663  ** Set up the input line. Trivial one-member case.
664  */
665  mline = (LWMLINE*)lwgeom_from_wkt("MULTILINESTRING((0 0,0 1,0 2,0 3,0 4))", LW_PARSER_CHECK_NONE);
666 
667  /* Clip in the middle, mid-range. */
668  c = lwmline_clip_to_ordinate_range(mline, 'Y', 1.5, 2.5);
669  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
670  //printf("c = %s\n", ewkt);
671  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 1.5,0 2,0 2.5))");
672  lwfree(ewkt);
674 
675  lwmline_free(mline);
676 
677  /*
678  ** Set up the input line. Two-member case.
679  */
680  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);
681 
682  /* Clip off the top. */
683  c = lwmline_clip_to_ordinate_range(mline, 'Y', 3.5, 5.5);
684  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
685  //printf("c = %s\n", ewkt);
686  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((1 3.5,1 4),(0 3.5,0 4))");
687  lwfree(ewkt);
689 
690  lwmline_free(mline);
691 
692  /*
693  ** Set up staggered input line to create multi-type output.
694  */
695  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);
696 
697  /* Clip from 0 upwards.. */
698  c = lwmline_clip_to_ordinate_range(mline, 'Y', 0.0, 2.5);
699  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
700  //printf("c = %s\n", ewkt);
701  CU_ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(1 0),LINESTRING(0 0,0 1,0 2,0 2.5))");
702  lwfree(ewkt);
704 
705  lwmline_free(mline);
706 
707  /*
708  ** Set up input line from MAC
709  */
710  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);
711 
712  /* Clip from 3 to 3.5 */
713  c = lwline_clip_to_ordinate_range(line, 'Z', 3.0, 3.5);
714  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
715  //printf("c = %s\n", ewkt);
716  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))");
717  lwfree(ewkt);
719 
720  /* Clip from 2 to 3.5 */
721  c = lwline_clip_to_ordinate_range(line, 'Z', 2.0, 3.5);
722  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
723  //printf("c = %s\n", ewkt);
724  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))");
725  lwfree(ewkt);
727 
728  /* Clip from 3 to 4 */
729  c = lwline_clip_to_ordinate_range(line, 'Z', 3.0, 4.0);
730  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
731  //printf("c = %s\n", ewkt);
732  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((3 3 3 3,4 4 4 4,3 3 3 5))");
733  lwfree(ewkt);
735 
736  /* Clip from 2 to 3 */
737  c = lwline_clip_to_ordinate_range(line, 'Z', 2.0, 3.0);
738  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
739  //printf("c = %s\n", ewkt);
740  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((2 2 2 2,3 3 3 3),(3 3 3 5,2 2 2 6))");
741  lwfree(ewkt);
743 
744 
745  lwline_free(line);
746 
747 }
#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
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:356
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
void lwmline_free(LWMLINE *mline)
Definition: lwmline.c:112
void lwline_free(LWLINE *line)
Definition: lwline.c:76
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.
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.

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

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