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

References FP_EQUALS, LWCOLLECTION::geoms, LINETYPE, lwcollection_add_lwgeom(), lwcollection_as_lwgeom(), lwcollection_construct_empty(), lwerror(), lwgeom_as_lwline(), lwgeom_is_empty(), lwgeom_offsetcurve(), lwline_clip_to_ordinate_range(), lwmline_clip_to_ordinate_range(), lwmpoint_clip_to_ordinate_range(), lwnotice(), lwpoint_clip_to_ordinate_range(), lwtype_name(), MULTILINETYPE, MULTIPOINTTYPE, LWCOLLECTION::ngeoms, POINTTYPE, LWGEOM::srid, and LWGEOM::type.

Referenced by lwgeom_locate_between(), ST_LocateBetween(), and ST_LocateBetweenElevations().

761 {
762  LWCOLLECTION *out_col;
763  LWCOLLECTION *out_offset;
764  int i;
765 
766  if ( ! lwin )
767  lwerror("lwgeom_clip_to_ordinate_range: null input geometry!");
768 
769  switch ( lwin->type )
770  {
771  case LINETYPE:
772  out_col = lwline_clip_to_ordinate_range((LWLINE*)lwin, ordinate, from, to);
773  break;
774  case MULTILINETYPE:
775  out_col = lwmline_clip_to_ordinate_range((LWMLINE*)lwin, ordinate, from, to);
776  break;
777  case MULTIPOINTTYPE:
778  out_col = lwmpoint_clip_to_ordinate_range((LWMPOINT*)lwin, ordinate, from, to);
779  break;
780  case POINTTYPE:
781  out_col = lwpoint_clip_to_ordinate_range((LWPOINT*)lwin, ordinate, from, to);
782  break;
783  default:
784  lwerror("This function does not accept %s geometries.", lwtype_name(lwin->type));
785  return NULL;;
786  }
787 
788  /* Stop if result is NULL */
789  if ( out_col == NULL )
790  lwerror("lwgeom_clip_to_ordinate_range clipping routine returned NULL");
791 
792  /* Return if we aren't going to offset the result */
793  if ( FP_EQUALS(offset, 0.0) || lwgeom_is_empty(lwcollection_as_lwgeom(out_col)) )
794  return out_col;
795 
796  /* Construct a collection to hold our outputs. */
797  /* Things get ugly: GEOS offset drops Z's and M's so we have to drop ours */
798  out_offset = lwcollection_construct_empty(MULTILINETYPE, lwin->srid, 0, 0);
799 
800  /* Try and offset the linear portions of the return value */
801  for ( i = 0; i < out_col->ngeoms; i++ )
802  {
803  int type = out_col->geoms[i]->type;
804  if ( type == POINTTYPE )
805  {
806  lwnotice("lwgeom_clip_to_ordinate_range cannot offset a clipped point");
807  continue;
808  }
809  else if ( type == LINETYPE )
810  {
811  /* lwgeom_offsetcurve(line, offset, quadsegs, joinstyle (round), mitrelimit) */
812  LWGEOM *lwoff = lwgeom_offsetcurve(lwgeom_as_lwline(out_col->geoms[i]), offset, 8, 1, 5.0);
813  if ( ! lwoff )
814  {
815  lwerror("lwgeom_offsetcurve returned null");
816  }
817  lwcollection_add_lwgeom(out_offset, lwoff);
818  }
819  else
820  {
821  lwerror("lwgeom_clip_to_ordinate_range found an unexpected type (%s) in the offset routine",lwtype_name(type));
822  }
823  }
824 
825  return out_offset;
826 }
#define LINETYPE
Definition: liblwgeom.h:71
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.
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.
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:61
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
LWGEOM * lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit)
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...
int32_t srid
Definition: liblwgeom.h:383
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
LWGEOM ** geoms
Definition: liblwgeom.h:493
LWCOLLECTION * lwmline_clip_to_ordinate_range(const LWMLINE *mline, char ordinate, double from, double to)
Clip an input MULTILINESTRING between two values, on any ordinate input.
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
uint8_t type
Definition: liblwgeom.h:380
#define FP_EQUALS(A, B)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1297
#define MULTILINETYPE
Definition: liblwgeom.h:74
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
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
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:219

Here is the call graph for this function:

Here is the caller graph for this function: