PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ test_lwmline_clip()

static void test_lwmline_clip ( void  )
static

Definition at line 802 of file cu_algorithm.c.

803{
804 LWCOLLECTION *c;
805 char *ewkt;
806 LWGEOM *mline = NULL;
807 LWGEOM *line = NULL;
808
809 /*
810 ** Set up the input line. Trivial one-member case.
811 */
812 mline = lwgeom_from_wkt("MULTILINESTRING((0 0,0 1,0 2,0 3,0 4))", LW_PARSER_CHECK_NONE);
813
814 /* Clip in the middle, mid-range. */
815 c = lwgeom_clip_to_ordinate_range(mline, 'Y', 1.5, 2.5, 0);
816 ewkt = lwgeom_to_ewkt((LWGEOM *)c);
817 ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((0 1.5,0 2,0 2.5))");
818 lwfree(ewkt);
820
821 lwgeom_free(mline);
822
823 /*
824 ** Set up the input line. Two-member case.
825 */
826 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);
827
828 /* Clip off the top. */
829 c = lwgeom_clip_to_ordinate_range(mline, 'Y', 3.5, 5.5, 0);
830 ewkt = lwgeom_to_ewkt((LWGEOM *)c);
831 ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((1 3.5,1 4),(0 3.5,0 4))");
832 lwfree(ewkt);
834
835 lwgeom_free(mline);
836
837 /*
838 ** Set up staggered input line to create multi-type output.
839 */
840 mline =
841 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);
842
843 /* Clip from 0 upwards.. */
844 c = lwgeom_clip_to_ordinate_range(mline, 'Y', 0.0, 2.5, 0);
845 ewkt = lwgeom_to_ewkt((LWGEOM *)c);
846 ASSERT_STRING_EQUAL(ewkt, "GEOMETRYCOLLECTION(POINT(1 0),LINESTRING(0 0,0 1,0 2,0 2.5))");
847 lwfree(ewkt);
849
850 lwgeom_free(mline);
851
852 /*
853 ** Set up input line from MAC
854 */
855 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)",
857
858 /* Clip from 3 to 3.5 */
859 c = lwgeom_clip_to_ordinate_range(line, 'Z', 3.0, 3.5, 0);
860 ewkt = lwgeom_to_ewkt((LWGEOM *)c);
861 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))");
862 lwfree(ewkt);
864
865 /* Clip from 2 to 3.5 */
866 c = lwgeom_clip_to_ordinate_range(line, 'Z', 2.0, 3.5, 0);
867 ewkt = lwgeom_to_ewkt((LWGEOM *)c);
869 "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))");
870 lwfree(ewkt);
872
873 /* Clip from 3 to 4 */
874 c = lwgeom_clip_to_ordinate_range(line, 'Z', 3.0, 4.0, 0);
875 ewkt = lwgeom_to_ewkt((LWGEOM *)c);
876 ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((3 3 3 3,4 4 4 4,3 3 3 5))");
877 lwfree(ewkt);
879
880 /* Clip from 2 to 3 */
881 c = lwgeom_clip_to_ordinate_range(line, 'Z', 2.0, 3.0, 0);
882 ewkt = lwgeom_to_ewkt((LWGEOM *)c);
883 ASSERT_STRING_EQUAL(ewkt, "MULTILINESTRING((2 2 2 2,3 3 3 3),(3 3 3 5,2 2 2 6))");
884 lwfree(ewkt);
886
887 lwgeom_free(line);
888}
#define ASSERT_STRING_EQUAL(o, e)
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2149
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,...
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an allocated string.
Definition lwgeom.c:593
void lwfree(void *mem)
Definition lwutil.c:248
void lwcollection_free(LWCOLLECTION *col)
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:940

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: