PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwgeom_clip_to_ordinate_range()

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 778 of file lwlinearreferencing.c.

779 {
780  LWCOLLECTION *out_col;
781  LWCOLLECTION *out_offset;
782  uint32_t i;
783 
784  if ( ! lwin )
785  lwerror("lwgeom_clip_to_ordinate_range: null input geometry!");
786 
787  switch ( lwin->type )
788  {
789  case LINETYPE:
790  out_col = lwline_clip_to_ordinate_range((LWLINE*)lwin, ordinate, from, to);
791  break;
792  case MULTILINETYPE:
793  out_col = lwmline_clip_to_ordinate_range((LWMLINE*)lwin, ordinate, from, to);
794  break;
795  case MULTIPOINTTYPE:
796  out_col = lwmpoint_clip_to_ordinate_range((LWMPOINT*)lwin, ordinate, from, to);
797  break;
798  case POINTTYPE:
799  out_col = lwpoint_clip_to_ordinate_range((LWPOINT*)lwin, ordinate, from, to);
800  break;
801  default:
802  lwerror("This function does not accept %s geometries.", lwtype_name(lwin->type));
803  return NULL;;
804  }
805 
806  /* Stop if result is NULL */
807  if ( out_col == NULL )
808  lwerror("lwgeom_clip_to_ordinate_range clipping routine returned NULL");
809 
810  /* Return if we aren't going to offset the result */
811  if (FP_IS_ZERO(offset) ||
813  return out_col;
814 
815  /* Construct a collection to hold our outputs. */
816  /* Things get ugly: GEOS offset drops Z's and M's so we have to drop ours */
817  out_offset = lwcollection_construct_empty(MULTILINETYPE, lwin->srid, 0, 0);
818 
819  /* Try and offset the linear portions of the return value */
820  for ( i = 0; i < out_col->ngeoms; i++ )
821  {
822  int type = out_col->geoms[i]->type;
823  if ( type == POINTTYPE )
824  {
825  lwnotice("lwgeom_clip_to_ordinate_range cannot offset a clipped point");
826  continue;
827  }
828  else if ( type == LINETYPE )
829  {
830  /* lwgeom_offsetcurve(line, offset, quadsegs, joinstyle (round), mitrelimit) */
831  LWGEOM *lwoff = lwgeom_offsetcurve(out_col->geoms[i], offset, 8, 1, 5.0);
832  if ( ! lwoff )
833  {
834  lwerror("lwgeom_offsetcurve returned null");
835  }
836  lwcollection_add_lwgeom(out_offset, lwoff);
837  }
838  else
839  {
840  lwerror("lwgeom_clip_to_ordinate_range found an unexpected type (%s) in the offset routine",lwtype_name(type));
841  }
842  }
843 
844  return out_offset;
845 }
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:300
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
#define MULTILINETYPE
Definition: liblwgeom.h:89
#define LINETYPE
Definition: liblwgeom.h:86
LWGEOM * lwgeom_offsetcurve(const LWGEOM *geom, double size, int quadsegs, int joinStyle, double mitreLimit)
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
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:1393
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
#define FP_IS_ZERO(A)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
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.
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...
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 * 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.
type
Definition: ovdump.py:41
uint32_t ngeoms
Definition: liblwgeom.h:510
LWGEOM ** geoms
Definition: liblwgeom.h:512
uint8_t type
Definition: liblwgeom.h:399
int32_t srid
Definition: liblwgeom.h:402
unsigned int uint32_t
Definition: uthash.h:78

References FP_IS_ZERO, LWCOLLECTION::geoms, LINETYPE, lwcollection_add_lwgeom(), lwcollection_as_lwgeom(), lwcollection_construct_empty(), lwerror(), 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, LWGEOM::type, LWLINE::type, and ovdump::type.

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

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