PostGIS  2.1.10dev-r@@SVN_REVISION@@
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.

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

Definition at line 448 of file lwlinearreferencing.c.

References LWCOLLECTION::bbox, COLLECTIONTYPE, LWCOLLECTION::flags, FLAGS_SET_M, FLAGS_SET_Z, LWMLINE::geoms, LWCOLLECTION::geoms, lwalloc(), lwcollection_construct_empty(), lwerror(), lwfree(), lwgeom_add_bbox(), lwgeom_drop_bbox(), lwgeom_has_m(), lwgeom_has_z(), lwline_clip_to_ordinate_range(), lwmline_as_lwgeom(), lwrealloc(), MULTILINETYPE, LWMLINE::ngeoms, LWCOLLECTION::ngeoms, LWMLINE::srid, LWMLINE::type, and LWCOLLECTION::type.

Referenced by lwgeom_clip_to_ordinate_range(), and test_lwmline_clip().

449 {
450  LWCOLLECTION *lwgeom_out = NULL;
451 
452  if ( ! mline )
453  {
454  lwerror("Null input geometry.");
455  return NULL;
456  }
457 
458  if ( mline->ngeoms == 1)
459  {
460  lwgeom_out = lwline_clip_to_ordinate_range(mline->geoms[0], ordinate, from, to);
461  }
462  else
463  {
464  LWCOLLECTION *col;
465  char hasz = lwgeom_has_z(lwmline_as_lwgeom(mline));
466  char hasm = lwgeom_has_m(lwmline_as_lwgeom(mline));
467  int i, j;
468  char homogeneous = 1;
469  size_t geoms_size = 0;
470  lwgeom_out = lwcollection_construct_empty(MULTILINETYPE, mline->srid, hasz, hasm);
471  FLAGS_SET_Z(lwgeom_out->flags, hasz);
472  FLAGS_SET_M(lwgeom_out->flags, hasm);
473  for ( i = 0; i < mline->ngeoms; i ++ )
474  {
475  col = lwline_clip_to_ordinate_range(mline->geoms[i], ordinate, from, to);
476  if ( col )
477  {
478  /* Something was left after the clip. */
479  if ( lwgeom_out->ngeoms + col->ngeoms > geoms_size )
480  {
481  geoms_size += 16;
482  if ( lwgeom_out->geoms )
483  {
484  lwgeom_out->geoms = lwrealloc(lwgeom_out->geoms, geoms_size * sizeof(LWGEOM*));
485  }
486  else
487  {
488  lwgeom_out->geoms = lwalloc(geoms_size * sizeof(LWGEOM*));
489  }
490  }
491  for ( j = 0; j < col->ngeoms; j++ )
492  {
493  lwgeom_out->geoms[lwgeom_out->ngeoms] = col->geoms[j];
494  lwgeom_out->ngeoms++;
495  }
496  if ( col->type != mline->type )
497  {
498  homogeneous = 0;
499  }
500  /* Shallow free the struct, leaving the geoms behind. */
501  if ( col->bbox ) lwfree(col->bbox);
502  lwfree(col->geoms);
503  lwfree(col);
504  }
505  }
506  if ( lwgeom_out->bbox )
507  {
508  lwgeom_drop_bbox((LWGEOM*)lwgeom_out);
509  lwgeom_add_bbox((LWGEOM*)lwgeom_out);
510  }
511 
512  if ( ! homogeneous )
513  {
514  lwgeom_out->type = COLLECTIONTYPE;
515  }
516  }
517 
518  return lwgeom_out;
519 
520 }
uint8_t type
Definition: liblwgeom.h:433
void lwfree(void *mem)
Definition: lwutil.c:190
uint8_t type
Definition: liblwgeom.h:459
GBOX * bbox
Definition: liblwgeom.h:461
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition: lwgeom.c:209
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...
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:792
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:542
int ngeoms
Definition: liblwgeom.h:437
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
uint8_t flags
Definition: liblwgeom.h:460
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:112
LWGEOM ** geoms
Definition: liblwgeom.h:465
LWLINE ** geoms
Definition: liblwgeom.h:439
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:183
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:555
void * lwalloc(size_t size)
Definition: lwutil.c:175
#define MULTILINETYPE
Definition: liblwgeom.h:64
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:799
#define COLLECTIONTYPE
Definition: liblwgeom.h:66
int32_t srid
Definition: liblwgeom.h:436
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:113

Here is the call graph for this function:

Here is the caller graph for this function: