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

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

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