PostGIS  2.4.9dev-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 415 of file lwlinearreferencing.c.

References LWCOLLECTION::bbox, LWMPOINT::geoms, lwcollection_add_lwgeom(), lwcollection_construct_empty(), lwerror(), lwgeom_add_bbox(), lwgeom_drop_bbox(), lwgeom_has_m(), lwgeom_has_z(), 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().

416 {
417  LWCOLLECTION *lwgeom_out = NULL;
418  char hasz, hasm;
419  int i;
420 
421  /* Nothing to do with NULL */
422  if ( ! mpoint )
423  lwerror("Null input geometry.");
424 
425  /* Ensure 'from' is less than 'to'. */
426  if ( to < from )
427  {
428  double t = from;
429  from = to;
430  to = t;
431  }
432 
433  /* Read Z/M info */
434  hasz = lwgeom_has_z(lwmpoint_as_lwgeom(mpoint));
435  hasm = lwgeom_has_m(lwmpoint_as_lwgeom(mpoint));
436 
437  /* Prepare return object */
438  lwgeom_out = lwcollection_construct_empty(MULTIPOINTTYPE, mpoint->srid, hasz, hasm);
439 
440  /* For each point, is its ordinate value between from and to? */
441  for ( i = 0; i < mpoint->ngeoms; i ++ )
442  {
443  POINT4D p4d;
444  double ordinate_value;
445 
446  lwpoint_getPoint4d_p(mpoint->geoms[i], &p4d);
447  ordinate_value = lwpoint_get_ordinate(&p4d, ordinate);
448 
449  if ( from <= ordinate_value && to >= ordinate_value )
450  {
451  LWPOINT *lwp = lwpoint_clone(mpoint->geoms[i]);
452  lwcollection_add_lwgeom(lwgeom_out, lwpoint_as_lwgeom(lwp));
453  }
454  }
455 
456  /* Set the bbox, if necessary */
457  if ( lwgeom_out->bbox )
458  {
459  lwgeom_drop_bbox((LWGEOM*)lwgeom_out);
460  lwgeom_add_bbox((LWGEOM*)lwgeom_out);
461  }
462 
463  return lwgeom_out;
464 }
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:88
GBOX * bbox
Definition: liblwgeom.h:505
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:885
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:635
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
Definition: lwpoint.c:239
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
LWPOINT ** geoms
Definition: liblwgeom.h:470
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:648
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:303
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
int ngeoms
Definition: liblwgeom.h:468
int32_t srid
Definition: liblwgeom.h:467
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:892
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
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:263
Here is the call graph for this function:
Here is the caller graph for this function: