PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ lwpoint_clip_to_ordinate_range()

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.

Clip a point based on the from/to range of one of its ordinates.

Definition at line 364 of file lwlinearreferencing.c.

References LWCOLLECTION::bbox, lwcollection_add_lwgeom(), lwcollection_construct_empty(), lwerror(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_refresh_bbox(), lwpoint_as_lwgeom(), lwpoint_clone(), lwpoint_get_ordinate(), lwpoint_getPoint4d_p(), MULTIPOINTTYPE, and LWPOINT::srid.

Referenced by lwgeom_clip_to_ordinate_range().

365 {
366  LWCOLLECTION *lwgeom_out = NULL;
367  char hasz, hasm;
368  POINT4D p4d;
369  double ordinate_value;
370 
371  /* Nothing to do with NULL */
372  if ( ! point )
373  lwerror("Null input geometry.");
374 
375  /* Ensure 'from' is less than 'to'. */
376  if ( to < from )
377  {
378  double t = from;
379  from = to;
380  to = t;
381  }
382 
383  /* Read Z/M info */
384  hasz = lwgeom_has_z(lwpoint_as_lwgeom(point));
385  hasm = lwgeom_has_m(lwpoint_as_lwgeom(point));
386 
387  /* Prepare return object */
388  lwgeom_out = lwcollection_construct_empty(MULTIPOINTTYPE, point->srid, hasz, hasm);
389 
390  /* Test if ordinate is in range */
391  lwpoint_getPoint4d_p(point, &p4d);
392  ordinate_value = lwpoint_get_ordinate(&p4d, ordinate);
393  if ( from <= ordinate_value && to >= ordinate_value )
394  {
395  LWPOINT *lwp = lwpoint_clone(point);
396  lwcollection_add_lwgeom(lwgeom_out, lwpoint_as_lwgeom(lwp));
397  }
398 
399  /* Set the bbox, if necessary */
400  if ( lwgeom_out->bbox )
401  {
402  lwgeom_refresh_bbox((LWGEOM*)lwgeom_out);
403  }
404 
405  return lwgeom_out;
406 }
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:698
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
GBOX * bbox
Definition: liblwgeom.h:507
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
Definition: lwpoint.c:239
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:930
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
int32_t srid
Definition: liblwgeom.h:412
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:937
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: