PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_lwline_clip()

static void test_lwline_clip ( void  )
static

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

468 {
469  LWCOLLECTION *c;
470  LWLINE *line = NULL;
471  LWLINE *l51 = NULL;
472  char *ewkt;
473 
474  /* Vertical line with vertices at y integers */
475  l51 = (LWLINE*)lwgeom_from_wkt("LINESTRING(0 0, 0 1, 0 2, 0 3, 0 4)", LW_PARSER_CHECK_NONE);
476 
477  /* Clip in the middle, mid-range. */
478  c = lwline_clip_to_ordinate_range(l51, 'Y', 1.5, 2.5);
479  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
480  //printf("c = %s\n", ewkt);
481  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 1.5,0 2,0 2.5))");
482  lwfree(ewkt);
484 
485  /* Clip off the top. */
486  c = lwline_clip_to_ordinate_range(l51, 'Y', 3.5, 5.5);
487  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
488  //printf("c = %s\n", ewkt);
489  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 3.5,0 4))");
490  lwfree(ewkt);
492 
493  /* Clip off the bottom. */
494  c = lwline_clip_to_ordinate_range(l51, 'Y', -1.5, 2.5);
495  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
496  //printf("c = %s\n", ewkt);
497  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 0,0 1,0 2,0 2.5))" );
498  lwfree(ewkt);
500 
501  /* Range holds entire object. */
502  c = lwline_clip_to_ordinate_range(l51, 'Y', -1.5, 5.5);
503  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
504  //printf("c = %s\n", ewkt);
505  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 0,0 1,0 2,0 3,0 4))" );
506  lwfree(ewkt);
508 
509  /* Clip on vertices. */
510  c = lwline_clip_to_ordinate_range(l51, 'Y', 1.0, 2.0);
511  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
512  //printf("c = %s\n", ewkt);
513  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 1,0 2))" );
514  lwfree(ewkt);
516 
517  /* Clip on vertices off the bottom. */
518  c = lwline_clip_to_ordinate_range(l51, 'Y', -1.0, 2.0);
519  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
520  //printf("c = %s\n", ewkt);
521  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 0,0 1,0 2))" );
522  lwfree(ewkt);
524 
525  /* Clip on top. */
526  c = lwline_clip_to_ordinate_range(l51, 'Y', -1.0, 0.0);
527  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
528  //printf("c = %s\n", ewkt);
529  CU_ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(0 0))" );
530  lwfree(ewkt);
532 
533  /* ST_LocateBetweenElevations(ST_GeomFromEWKT('LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)'), 1, 2)) */
534  line = (LWLINE*)lwgeom_from_wkt("LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)", LW_PARSER_CHECK_NONE);
535  c = lwline_clip_to_ordinate_range(line, 'Z', 1.0, 2.0);
536  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
537  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((2 2 2,1 1 1))" );
538  lwfree(ewkt);
540  lwline_free(line);
541 
542  /* ST_LocateBetweenElevations('LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)', 1, 2)) */
543  line = (LWLINE*)lwgeom_from_wkt("LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)", LW_PARSER_CHECK_NONE);
544  c = lwline_clip_to_ordinate_range(line, 'Z', 1.0, 2.0);
545  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
546  //printf("a = %s\n", ewkt);
547  CU_ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((2 2 2,1 1 1))" );
548  lwfree(ewkt);
550  lwline_free(line);
551 
552  /* ST_LocateBetweenElevations('LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)', 1, 1)) */
553  line = (LWLINE*)lwgeom_from_wkt("LINESTRING(1 2 3, 4 5 6, 6 6 6, 1 1 1)", LW_PARSER_CHECK_NONE);
554  c = lwline_clip_to_ordinate_range(line, 'Z', 1.0, 1.0);
555  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
556  //printf("b = %s\n", ewkt);
557  CU_ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(1 1 1))" );
558  lwfree(ewkt);
560  lwline_free(line);
561 
562  /* ST_LocateBetweenElevations('LINESTRING(1 1 1, 1 2 2)', 1,1) */
563  line = (LWLINE*)lwgeom_from_wkt("LINESTRING(1 1 1, 1 2 2)", LW_PARSER_CHECK_NONE);
564  c = lwline_clip_to_ordinate_range(line, 'Z', 1.0, 1.0);
565  ewkt = lwgeom_to_ewkt((LWGEOM*)c);
566  //printf("c = %s\n", ewkt);
567  CU_ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(1 1 1))" );
568  lwfree(ewkt);
570  lwline_free(line);
571 
572  lwline_free(l51);
573 
574 }
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
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: