PostGIS  2.2.7dev-r@@SVN_REVISION@@
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 351 of file lwlinearreferencing.c.

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

Referenced by lwgeom_clip_to_ordinate_range().

352 {
353  LWCOLLECTION *lwgeom_out = NULL;
354  char hasz, hasm;
355  POINT4D p4d;
356  double ordinate_value;
357 
358  /* Nothing to do with NULL */
359  if ( ! point )
360  lwerror("Null input geometry.");
361 
362  /* Ensure 'from' is less than 'to'. */
363  if ( to < from )
364  {
365  double t = from;
366  from = to;
367  to = t;
368  }
369 
370  /* Read Z/M info */
371  hasz = lwgeom_has_z(lwpoint_as_lwgeom(point));
372  hasm = lwgeom_has_m(lwpoint_as_lwgeom(point));
373 
374  /* Prepare return object */
375  lwgeom_out = lwcollection_construct_empty(MULTIPOINTTYPE, point->srid, hasz, hasm);
376 
377  /* Test if ordinate is in range */
378  lwpoint_getPoint4d_p(point, &p4d);
379  ordinate_value = lwpoint_get_ordinate(&p4d, ordinate);
380  if ( from <= ordinate_value && to >= ordinate_value )
381  {
382  LWPOINT *lwp = lwpoint_clone(point);
383  lwcollection_add_lwgeom(lwgeom_out, lwpoint_as_lwgeom(lwp));
384  }
385 
386  /* Set the bbox, if necessary */
387  if ( lwgeom_out->bbox )
388  {
389  lwgeom_drop_bbox((LWGEOM*)lwgeom_out);
390  lwgeom_add_bbox((LWGEOM*)lwgeom_out);
391  }
392 
393  return lwgeom_out;
394 }
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:73
GBOX * bbox
Definition: liblwgeom.h:489
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:836
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:586
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
Definition: lwpoint.c:208
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:44
int32_t srid
Definition: liblwgeom.h:394
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:254
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:843
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:174
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74

Here is the call graph for this function:

Here is the caller graph for this function: