PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ test_lwline_clip()

static void test_lwline_clip ( void  )
static

Definition at line 546 of file cu_algorithm.c.

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

Referenced by algorithms_suite_setup().

547 {
548  LWCOLLECTION *c;
549  LWLINE *line = NULL;
550  LWLINE *l51 = NULL;
551  char *ewkt;
552 
553  /* Vertical line with vertices at y integers */
554  l51 = (LWLINE*)lwgeom_from_wkt("LINESTRING(0 0, 0 1, 0 2, 0 3, 0 4)", LW_PARSER_CHECK_NONE);
555 
556  /* Clip in the middle, mid-range. */
557  c = lwline_clip_to_ordinate_range(l51, 'Y', 1.5, 2.5);
558  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
559  //printf("c = %s\n", ewkt);
560  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 1.5,0 2,0 2.5))");
561  lwfree(ewkt);
563 
564  /* Clip off the top. */
565  c = lwline_clip_to_ordinate_range(l51, 'Y', 3.5, 5.5);
566  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
567  //printf("c = %s\n", ewkt);
568  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 3.5,0 4))");
569  lwfree(ewkt);
571 
572  /* Clip off the bottom. */
573  c = lwline_clip_to_ordinate_range(l51, 'Y', -1.5, 2.5);
574  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
575  //printf("c = %s\n", ewkt);
576  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 0,0 1,0 2,0 2.5))" );
577  lwfree(ewkt);
579 
580  /* Range holds entire object. */
581  c = lwline_clip_to_ordinate_range(l51, 'Y', -1.5, 5.5);
582  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
583  //printf("c = %s\n", ewkt);
584  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 0,0 1,0 2,0 3,0 4))" );
585  lwfree(ewkt);
587 
588  /* Clip on vertices. */
589  c = lwline_clip_to_ordinate_range(l51, 'Y', 1.0, 2.0);
590  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
591  //printf("c = %s\n", ewkt);
592  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 1,0 2))" );
593  lwfree(ewkt);
595 
596  /* Clip on vertices off the bottom. */
597  c = lwline_clip_to_ordinate_range(l51, 'Y', -1.0, 2.0);
598  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
599  //printf("c = %s\n", ewkt);
600  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 0,0 1,0 2))" );
601  lwfree(ewkt);
603 
604  /* Clip on top. */
605  c = lwline_clip_to_ordinate_range(l51, 'Y', -1.0, 0.0);
606  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
607  //printf("c = %s\n", ewkt);
608  CU_ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(0 0))" );
609  lwfree(ewkt);
611 
612  /* ST_LocateBetweenElevations(ST_GeomFromEWKT('LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)'), 1, 2)) */
613  line = (LWLINE*)lwgeom_from_wkt("LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)", LW_PARSER_CHECK_NONE);
614  c = lwline_clip_to_ordinate_range(line, 'Z', 1.0, 2.0);
615  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
616  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((2 2 2,1 1 1))" );
617  lwfree(ewkt);
619  lwline_free(line);
620 
621  /* ST_LocateBetweenElevations('LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)', 1, 2)) */
622  line = (LWLINE*)lwgeom_from_wkt("LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)", LW_PARSER_CHECK_NONE);
623  c = lwline_clip_to_ordinate_range(line, 'Z', 1.0, 2.0);
624  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
625  //printf("a = %s\n", ewkt);
626  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((2 2 2,1 1 1))" );
627  lwfree(ewkt);
629  lwline_free(line);
630 
631  /* ST_LocateBetweenElevations('LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)', 1, 1)) */
632  line = (LWLINE*)lwgeom_from_wkt("LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)", LW_PARSER_CHECK_NONE);
633  c = lwline_clip_to_ordinate_range(line, 'Z', 1.0, 1.0);
634  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
635  //printf("b = %s\n", ewkt);
636  CU_ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(1 1 1))" );
637  lwfree(ewkt);
639  lwline_free(line);
640 
641  /* ST_LocateBetweenElevations('LINESTRING(1 1 1, 1 2 2)', 1,1) */
642  line = (LWLINE*)lwgeom_from_wkt("LINESTRING(1 1 1, 1 2 2)", LW_PARSER_CHECK_NONE);
643  c = lwline_clip_to_ordinate_range(line, 'Z', 1.0, 1.0);
644  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
645  //printf("c = %s\n", ewkt);
646  CU_ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(1 1 1))" );
647  lwfree(ewkt);
649  lwline_free(line);
650 
651  lwline_free(l51);
652 
653 }
void lwfree(void *mem)
Definition: lwutil.c:244
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:556
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:2004
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:356
Here is the call graph for this function:
Here is the caller graph for this function: