PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ test_lwmline_clip()

static void test_lwmline_clip ( void  )
static

Definition at line 797 of file cu_algorithm.c.

798 {
799  LWCOLLECTION *c;
800  char *ewkt;
801  LWGEOM *mline = NULL;
802  LWGEOM *line = NULL;
803 
804  /*
805  ** Set up the input line. Trivial one-member case.
806  */
807  mline = lwgeom_from_wkt("MULTILINESTRING((0 0,0 1,0 2,0 3,0 4))", LW_PARSER_CHECK_NONE);
808 
809  /* Clip in the middle, mid-range. */
810  c = lwgeom_clip_to_ordinate_range(mline, 'Y', 1.5, 2.5, 0);
811  ewkt = lwgeom_to_ewkt((LWGEOM *)c);
812  ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 1.5,0 2,0 2.5))");
813  lwfree(ewkt);
815 
816  lwgeom_free(mline);
817 
818  /*
819  ** Set up the input line. Two-member case.
820  */
821  mline = 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);
822 
823  /* Clip off the top. */
824  c = lwgeom_clip_to_ordinate_range(mline, 'Y', 3.5, 5.5, 0);
825  ewkt = lwgeom_to_ewkt((LWGEOM *)c);
826  ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((1 3.5,1 4),(0 3.5,0 4))");
827  lwfree(ewkt);
829 
830  lwgeom_free(mline);
831 
832  /*
833  ** Set up staggered input line to create multi-type output.
834  */
835  mline =
836  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);
837 
838  /* Clip from 0 upwards.. */
839  c = lwgeom_clip_to_ordinate_range(mline, 'Y', 0.0, 2.5, 0);
840  ewkt = lwgeom_to_ewkt((LWGEOM *)c);
841  ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(1 0),LINESTRING(0 0,0 1,0 2,0 2.5))");
842  lwfree(ewkt);
844 
845  lwgeom_free(mline);
846 
847  /*
848  ** Set up input line from MAC
849  */
850  line = 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)",
852 
853  /* Clip from 3 to 3.5 */
854  c = lwgeom_clip_to_ordinate_range(line, 'Z', 3.0, 3.5, 0);
855  ewkt = lwgeom_to_ewkt((LWGEOM *)c);
856  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))");
857  lwfree(ewkt);
859 
860  /* Clip from 2 to 3.5 */
861  c = lwgeom_clip_to_ordinate_range(line, 'Z', 2.0, 3.5, 0);
862  ewkt = lwgeom_to_ewkt((LWGEOM *)c);
863  ASSERT_STRING_EQUAL(ewkt,
864  "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))");
865  lwfree(ewkt);
867 
868  /* Clip from 3 to 4 */
869  c = lwgeom_clip_to_ordinate_range(line, 'Z', 3.0, 4.0, 0);
870  ewkt = lwgeom_to_ewkt((LWGEOM *)c);
871  ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((3 3 3 3,4 4 4 4,3 3 3 5))");
872  lwfree(ewkt);
874 
875  /* Clip from 2 to 3 */
876  c = lwgeom_clip_to_ordinate_range(line, 'Z', 2.0, 3.0, 0);
877  ewkt = lwgeom_to_ewkt((LWGEOM *)c);
878  ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((2 2 2 2,3 3 3 3),(3 3 3 5,2 2 2 6))");
879  lwfree(ewkt);
881 
882  lwgeom_free(line);
883 }
#define ASSERT_STRING_EQUAL(o, e)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2060
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:547
void lwfree(void *mem)
Definition: lwutil.c:242
LWCOLLECTION * lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset)
Given a geometry clip based on the from/to range of one of its ordinates (x, y, z,...
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:357
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:905

References ASSERT_STRING_EQUAL, LW_PARSER_CHECK_NONE, lwcollection_free(), lwfree(), lwgeom_clip_to_ordinate_range(), lwgeom_free(), lwgeom_from_wkt(), and lwgeom_to_ewkt().

Referenced by algorithms_suite_setup().

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