PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwmpoint_clip_to_ordinate_range()

LWCOLLECTION* lwmpoint_clip_to_ordinate_range ( const LWMPOINT mpoint,
char  ordinate,
double  from,
double  to 
)

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

Use for m- and z- clipping

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

Definition at line 414 of file lwlinearreferencing.c.

415 {
416  LWCOLLECTION *lwgeom_out = NULL;
417  char hasz, hasm;
418  uint32_t i;
419 
420  /* Nothing to do with NULL */
421  if ( ! mpoint )
422  lwerror("Null input geometry.");
423 
424  /* Ensure 'from' is less than 'to'. */
425  if ( to < from )
426  {
427  double t = from;
428  from = to;
429  to = t;
430  }
431 
432  /* Read Z/M info */
433  hasz = lwgeom_has_z(lwmpoint_as_lwgeom(mpoint));
434  hasm = lwgeom_has_m(lwmpoint_as_lwgeom(mpoint));
435 
436  /* Prepare return object */
437  lwgeom_out = lwcollection_construct_empty(MULTIPOINTTYPE, mpoint->srid, hasz, hasm);
438 
439  /* For each point, is its ordinate value between from and to? */
440  for ( i = 0; i < mpoint->ngeoms; i ++ )
441  {
442  POINT4D p4d;
443  double ordinate_value;
444 
445  lwpoint_getPoint4d_p(mpoint->geoms[i], &p4d);
446  ordinate_value = lwpoint_get_ordinate(&p4d, ordinate);
447 
448  if ( from <= ordinate_value && to >= ordinate_value )
449  {
450  LWPOINT *lwp = lwpoint_clone(mpoint->geoms[i]);
451  lwcollection_add_lwgeom(lwgeom_out, lwpoint_as_lwgeom(lwp));
452  }
453  }
454 
455  /* Set the bbox, if necessary */
456  if ( lwgeom_out->bbox )
457  {
458  lwgeom_refresh_bbox((LWGEOM*)lwgeom_out);
459  }
460 
461  return lwgeom_out;
462 }
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:698
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:295
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:930
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:937
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
Definition: lwpoint.c:239
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
GBOX * bbox
Definition: liblwgeom.h:508
int32_t srid
Definition: liblwgeom.h:470
uint32_t ngeoms
Definition: liblwgeom.h:471
LWPOINT ** geoms
Definition: liblwgeom.h:473
unsigned int uint32_t
Definition: uthash.h:78

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

Referenced by lwgeom_clip_to_ordinate_range().

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