PostGIS  2.1.10dev-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 751 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().

752 {
753  LWCOLLECTION *out_col;
754  LWCOLLECTION *out_offset;
755  int i;
756 
757  if ( ! lwin )
758  lwerror("lwgeom_clip_to_ordinate_range: null input geometry!");
759 
760  switch ( lwin->type )
761  {
762  case LINETYPE:
763  out_col = lwline_clip_to_ordinate_range((LWLINE*)lwin, ordinate, from, to);
764  break;
765  case MULTILINETYPE:
766  out_col = lwmline_clip_to_ordinate_range((LWMLINE*)lwin, ordinate, from, to);
767  break;
768  case MULTIPOINTTYPE:
769  out_col = lwmpoint_clip_to_ordinate_range((LWMPOINT*)lwin, ordinate, from, to);
770  break;
771  case POINTTYPE:
772  out_col = lwpoint_clip_to_ordinate_range((LWPOINT*)lwin, ordinate, from, to);
773  break;
774  default:
775  lwerror("This function does not accept %s geometries.", lwtype_name(lwin->type));
776  return NULL;;
777  }
778 
779  /* Stop if result is NULL */
780  if ( out_col == NULL )
781  lwerror("lwgeom_clip_to_ordinate_range clipping routine returned NULL");
782 
783  /* Return if we aren't going to offset the result */
784  if ( FP_EQUALS(offset, 0.0) || lwgeom_is_empty(lwcollection_as_lwgeom(out_col)) )
785  return out_col;
786 
787  /* Construct a collection to hold our outputs. */
788  /* Things get ugly: GEOS offset drops Z's and M's so we have to drop ours */
789  out_offset = lwcollection_construct_empty(MULTILINETYPE, lwin->srid, 0, 0);
790 
791  /* Try and offset the linear portions of the return value */
792  for ( i = 0; i < out_col->ngeoms; i++ )
793  {
794  int type = out_col->geoms[i]->type;
795  if ( type == POINTTYPE )
796  {
797  lwnotice("lwgeom_clip_to_ordinate_range cannot offset a clipped point");
798  continue;
799  }
800  else if ( type == LINETYPE )
801  {
802  /* lwgeom_offsetcurve(line, offset, quadsegs, joinstyle (round), mitrelimit) */
803  LWGEOM *lwoff = lwgeom_offsetcurve(lwgeom_as_lwline(out_col->geoms[i]), offset, 8, 1, 5.0);
804  if ( ! lwoff )
805  {
806  lwerror("lwgeom_offsetcurve returned null");
807  }
808  lwcollection_add_lwgeom(out_offset, lwoff);
809  }
810  else
811  {
812  lwerror("lwgeom_clip_to_ordinate_range found an unexpected type (%s) in the offset routine",lwtype_name(type));
813  }
814  }
815 
816  return out_offset;
817 }
#define LINETYPE
Definition: liblwgeom.h:61
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.
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
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:355
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
LWGEOM ** geoms
Definition: liblwgeom.h:465
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:60
uint8_t type
Definition: liblwgeom.h:352
#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:1229
#define MULTILINETYPE
Definition: liblwgeom.h:64
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
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: