PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ 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 835 of file lwlinearreferencing.c.

836 {
837  LWCOLLECTION *out_col;
838  LWCOLLECTION *out_offset;
839  uint32_t i;
840 
841  /* Ensure 'from' is less than 'to'. */
842  if (to < from)
843  {
844  double t = from;
845  from = to;
846  to = t;
847  }
848 
849  if (!lwin)
850  lwerror("lwgeom_clip_to_ordinate_range: null input geometry!");
851 
852  switch (lwin->type)
853  {
854  case LINETYPE:
855  out_col = lwline_clip_to_ordinate_range((LWLINE *)lwin, ordinate, from, to);
856  break;
857  case MULTIPOINTTYPE:
858  out_col = lwmpoint_clip_to_ordinate_range((LWMPOINT *)lwin, ordinate, from, to);
859  break;
860  case POINTTYPE:
861  out_col = lwpoint_clip_to_ordinate_range((LWPOINT *)lwin, ordinate, from, to);
862  break;
863  case POLYGONTYPE:
864  out_col = lwpoly_clip_to_ordinate_range((LWPOLY *)lwin, ordinate, from, to);
865  break;
866  case TRIANGLETYPE:
867  out_col = lwtriangle_clip_to_ordinate_range((LWTRIANGLE *)lwin, ordinate, from, to);
868  break;
869  case TINTYPE:
870  case MULTILINETYPE:
871  case MULTIPOLYGONTYPE:
872  case COLLECTIONTYPE:
874  out_col = lwcollection_clip_to_ordinate_range((LWCOLLECTION *)lwin, ordinate, from, to);
875  break;
876  default:
877  lwerror("This function does not accept %s geometries.", lwtype_name(lwin->type));
878  return NULL;
879  }
880 
881  /* Stop if result is NULL */
882  if (!out_col)
883  lwerror("lwgeom_clip_to_ordinate_range clipping routine returned NULL");
884 
885  /* Return if we aren't going to offset the result */
886  if (FP_IS_ZERO(offset) || lwgeom_is_empty(lwcollection_as_lwgeom(out_col)))
887  return out_col;
888 
889  /* Construct a collection to hold our outputs. */
890  /* Things get ugly: GEOS offset drops Z's and M's so we have to drop ours */
891  out_offset = lwcollection_construct_empty(MULTILINETYPE, lwin->srid, 0, 0);
892 
893  /* Try and offset the linear portions of the return value */
894  for (i = 0; i < out_col->ngeoms; i++)
895  {
896  int type = out_col->geoms[i]->type;
897  if (type == POINTTYPE)
898  {
899  lwnotice("lwgeom_clip_to_ordinate_range cannot offset a clipped point");
900  continue;
901  }
902  else if (type == LINETYPE)
903  {
904  /* lwgeom_offsetcurve(line, offset, quadsegs, joinstyle (round), mitrelimit) */
905  LWGEOM *lwoff = lwgeom_offsetcurve(out_col->geoms[i], offset, 8, 1, 5.0);
906  if (!lwoff)
907  {
908  lwerror("lwgeom_offsetcurve returned null");
909  }
910  lwcollection_add_lwgeom(out_offset, lwoff);
911  }
912  else
913  {
914  lwerror("lwgeom_clip_to_ordinate_range found an unexpected type (%s) in the offset routine",
915  lwtype_name(type));
916  }
917  }
918 
919  return out_offset;
920 }
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:309
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
#define MULTILINETYPE
Definition: liblwgeom.h:106
#define LINETYPE
Definition: liblwgeom.h:103
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
#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
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwcollection.c:92
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
#define TRIANGLETYPE
Definition: liblwgeom.h:115
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:188
#define FP_IS_ZERO(A)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
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:203
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.
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 * 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 * 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 * 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.
type
Definition: ovdump.py:42
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, LWLINE::type, and ovdump::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: