PostGIS  3.0.6dev-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 829 of file lwlinearreferencing.c.

830 {
831  LWCOLLECTION *out_col;
832  LWCOLLECTION *out_offset;
833  uint32_t i;
834 
835  /* Ensure 'from' is less than 'to'. */
836  if (to < from)
837  {
838  double t = from;
839  from = to;
840  to = t;
841  }
842 
843  if (!lwin)
844  lwerror("lwgeom_clip_to_ordinate_range: null input geometry!");
845 
846  switch (lwin->type)
847  {
848  case LINETYPE:
849  out_col = lwline_clip_to_ordinate_range((LWLINE *)lwin, ordinate, from, to);
850  break;
851  case MULTIPOINTTYPE:
852  out_col = lwmpoint_clip_to_ordinate_range((LWMPOINT *)lwin, ordinate, from, to);
853  break;
854  case POINTTYPE:
855  out_col = lwpoint_clip_to_ordinate_range((LWPOINT *)lwin, ordinate, from, to);
856  break;
857  case POLYGONTYPE:
858  out_col = lwpoly_clip_to_ordinate_range((LWPOLY *)lwin, ordinate, from, to);
859  break;
860  case TRIANGLETYPE:
861  out_col = lwtriangle_clip_to_ordinate_range((LWTRIANGLE *)lwin, ordinate, from, to);
862  break;
863  case TINTYPE:
864  case MULTILINETYPE:
865  case MULTIPOLYGONTYPE:
866  case COLLECTIONTYPE:
868  out_col = lwcollection_clip_to_ordinate_range((LWCOLLECTION *)lwin, ordinate, from, to);
869  break;
870  default:
871  lwerror("This function does not accept %s geometries.", lwtype_name(lwin->type));
872  return NULL;
873  }
874 
875  /* Stop if result is NULL */
876  if (!out_col)
877  lwerror("lwgeom_clip_to_ordinate_range clipping routine returned NULL");
878 
879  /* Return if we aren't going to offset the result */
880  if (FP_IS_ZERO(offset) || lwgeom_is_empty(lwcollection_as_lwgeom(out_col)))
881  return out_col;
882 
883  /* Construct a collection to hold our outputs. */
884  /* Things get ugly: GEOS offset drops Z's and M's so we have to drop ours */
885  out_offset = lwcollection_construct_empty(MULTILINETYPE, lwin->srid, 0, 0);
886 
887  /* Try and offset the linear portions of the return value */
888  for (i = 0; i < out_col->ngeoms; i++)
889  {
890  int type = out_col->geoms[i]->type;
891  if (type == POINTTYPE)
892  {
893  lwnotice("lwgeom_clip_to_ordinate_range cannot offset a clipped point");
894  continue;
895  }
896  else if (type == LINETYPE)
897  {
898  /* lwgeom_offsetcurve(line, offset, quadsegs, joinstyle (round), mitrelimit) */
899  LWGEOM *lwoff = lwgeom_offsetcurve(out_col->geoms[i], offset, 8, 1, 5.0);
900  if (!lwoff)
901  {
902  lwerror("lwgeom_offsetcurve returned null");
903  }
904  lwcollection_add_lwgeom(out_offset, lwoff);
905  }
906  else
907  {
908  lwerror("lwgeom_clip_to_ordinate_range found an unexpected type (%s) in the offset routine",
909  lwtype_name(type));
910  }
911  }
912 
913  return out_offset;
914 }
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:291
#define COLLECTIONTYPE
Definition: liblwgeom.h:122
#define MULTILINETYPE
Definition: liblwgeom.h:120
#define LINETYPE
Definition: liblwgeom.h:117
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
#define MULTIPOINTTYPE
Definition: liblwgeom.h:119
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:116
#define TINTYPE
Definition: liblwgeom.h:130
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:121
#define POLYGONTYPE
Definition: liblwgeom.h:118
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:128
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:129
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:193
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:566
LWGEOM ** geoms
Definition: liblwgeom.h:561
uint8_t type
Definition: liblwgeom.h:448
int32_t srid
Definition: liblwgeom.h:446

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: