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

◆ lwgeom_clip_to_ordinate_range()

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, m).

Use for m- and z- clipping.

Definition at line 823 of file lwlinearreferencing.c.

824{
825 LWCOLLECTION *out_col;
826 LWCOLLECTION *out_offset;
827 uint32_t i;
828
829 /* Ensure 'from' is less than 'to'. */
830 if (to < from)
831 {
832 double t = from;
833 from = to;
834 to = t;
835 }
836
837 if (!lwin)
838 lwerror("lwgeom_clip_to_ordinate_range: null input geometry!");
839
840 switch (lwin->type)
841 {
842 case LINETYPE:
843 out_col = lwline_clip_to_ordinate_range((LWLINE *)lwin, ordinate, from, to);
844 break;
845 case MULTIPOINTTYPE:
846 out_col = lwmpoint_clip_to_ordinate_range((LWMPOINT *)lwin, ordinate, from, to);
847 break;
848 case POINTTYPE:
849 out_col = lwpoint_clip_to_ordinate_range((LWPOINT *)lwin, ordinate, from, to);
850 break;
851 case POLYGONTYPE:
852 out_col = lwpoly_clip_to_ordinate_range((LWPOLY *)lwin, ordinate, from, to);
853 break;
854 case TRIANGLETYPE:
855 out_col = lwtriangle_clip_to_ordinate_range((LWTRIANGLE *)lwin, ordinate, from, to);
856 break;
857 case TINTYPE:
858 case MULTILINETYPE:
859 case MULTIPOLYGONTYPE:
860 case COLLECTIONTYPE:
862 out_col = lwcollection_clip_to_ordinate_range((LWCOLLECTION *)lwin, ordinate, from, to);
863 break;
864 default:
865 lwerror("This function does not accept %s geometries.", lwtype_name(lwin->type));
866 return NULL;
867 }
868
869 /* Stop if result is NULL */
870 if (!out_col)
871 lwerror("lwgeom_clip_to_ordinate_range clipping routine returned NULL");
872
873 /* Return if we aren't going to offset the result */
874 if (FP_IS_ZERO(offset) || lwgeom_is_empty(lwcollection_as_lwgeom(out_col)))
875 return out_col;
876
877 /* Construct a collection to hold our outputs. */
878 /* Things get ugly: GEOS offset drops Z's and M's so we have to drop ours */
879 out_offset = lwcollection_construct_empty(MULTILINETYPE, lwin->srid, 0, 0);
880
881 /* Try and offset the linear portions of the return value */
882 for (i = 0; i < out_col->ngeoms; i++)
883 {
884 int type = out_col->geoms[i]->type;
885 if (type == POINTTYPE)
886 {
887 lwnotice("lwgeom_clip_to_ordinate_range cannot offset a clipped point");
888 continue;
889 }
890 else if (type == LINETYPE)
891 {
892 /* lwgeom_offsetcurve(line, offset, quadsegs, joinstyle (round), mitrelimit) */
893 LWGEOM *lwoff = lwgeom_offsetcurve(out_col->geoms[i], offset, 8, 1, 5.0);
894 if (!lwoff)
895 {
896 lwerror("lwgeom_offsetcurve returned null");
897 }
898 lwcollection_add_lwgeom(out_offset, lwoff);
899 }
900 else
901 {
902 lwerror("lwgeom_clip_to_ordinate_range found an unexpected type (%s) in the offset routine",
903 lwtype_name(type));
904 }
905 }
906
907 return out_offset;
908}
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
#define COLLECTIONTYPE
Definition liblwgeom.h:108
#define MULTILINETYPE
Definition liblwgeom.h:106
#define LINETYPE
Definition liblwgeom.h:103
#define MULTIPOINTTYPE
Definition liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:102
#define TINTYPE
Definition liblwgeom.h:116
#define MULTIPOLYGONTYPE
Definition liblwgeom.h:107
#define POLYGONTYPE
Definition liblwgeom.h:104
#define POLYHEDRALSURFACETYPE
Definition liblwgeom.h:114
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
#define TRIANGLETYPE
Definition liblwgeom.h:115
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition lwgeom.c:337
#define FP_IS_ZERO(A)
void lwnotice(const char *fmt,...) __attribute__((format(printf
Write a notice out to the notice handler.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199
static LWCOLLECTION * lwcollection_clip_to_ordinate_range(const LWCOLLECTION *icol, char ordinate, double from, double to)
Clip an input COLLECTION between two values, on any ordinate input.
static LWCOLLECTION * lwpoint_clip_to_ordinate_range(const LWPOINT *point, char ordinate, double from, double to)
Clip an input POINT between two values, on any ordinate input.
static LWCOLLECTION * lwline_clip_to_ordinate_range(const LWLINE *line, char ordinate, double from, double to)
Take in a LINESTRING and return a MULTILINESTRING of those portions of the LINESTRING between the fro...
static LWCOLLECTION * lwtriangle_clip_to_ordinate_range(const LWTRIANGLE *tri, char ordinate, double from, double to)
Clip an input LWTRIANGLE between two values, on any ordinate input.
static LWCOLLECTION * lwpoly_clip_to_ordinate_range(const LWPOLY *poly, char ordinate, double from, double to)
Clip an input LWPOLY between two values, on any ordinate input.
static LWCOLLECTION * lwmpoint_clip_to_ordinate_range(const LWMPOINT *mpoint, char ordinate, double from, double to)
Clip an input MULTIPOINT between two values, on any ordinate input.
uint32_t ngeoms
Definition liblwgeom.h:580
LWGEOM ** geoms
Definition liblwgeom.h:575
uint8_t type
Definition liblwgeom.h:462
int32_t srid
Definition liblwgeom.h:460

References COLLECTIONTYPE, FP_IS_ZERO, LWCOLLECTION::geoms, LINETYPE, lwcollection_add_lwgeom(), lwcollection_as_lwgeom(), lwcollection_clip_to_ordinate_range(), lwcollection_construct_empty(), lwerror(), lwgeom_is_empty(), lwgeom_offsetcurve(), lwline_clip_to_ordinate_range(), lwmpoint_clip_to_ordinate_range(), lwnotice(), lwpoint_clip_to_ordinate_range(), lwpoly_clip_to_ordinate_range(), lwtriangle_clip_to_ordinate_range(), lwtype_name(), MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, LWCOLLECTION::ngeoms, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, LWGEOM::srid, TINTYPE, TRIANGLETYPE, LWGEOM::type, and LWLINE::type.

Referenced by lwcollection_clip_to_ordinate_range(), lwgeom_locate_between(), lwgeom_solid_contains_lwgeom(), ST_LocateBetween(), ST_LocateBetweenElevations(), test_lwline_clip(), test_lwline_clip_big(), test_lwmline_clip(), test_lwpoly_clip(), and test_lwtriangle_clip().

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