PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwmline_clip_to_ordinate_range()

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 457 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().

458 {
459  LWCOLLECTION *lwgeom_out = NULL;
460 
461  if ( ! mline )
462  {
463  lwerror("Null input geometry.");
464  return NULL;
465  }
466 
467  if ( mline->ngeoms == 1)
468  {
469  lwgeom_out = lwline_clip_to_ordinate_range(mline->geoms[0], ordinate, from, to);
470  }
471  else
472  {
473  LWCOLLECTION *col;
474  char hasz = lwgeom_has_z(lwmline_as_lwgeom(mline));
475  char hasm = lwgeom_has_m(lwmline_as_lwgeom(mline));
476  int i, j;
477  char homogeneous = 1;
478  size_t geoms_size = 0;
479  lwgeom_out = lwcollection_construct_empty(MULTILINETYPE, mline->srid, hasz, hasm);
480  FLAGS_SET_Z(lwgeom_out->flags, hasz);
481  FLAGS_SET_M(lwgeom_out->flags, hasm);
482  for ( i = 0; i < mline->ngeoms; i ++ )
483  {
484  col = lwline_clip_to_ordinate_range(mline->geoms[i], ordinate, from, to);
485  if ( col )
486  {
487  /* Something was left after the clip. */
488  if ( lwgeom_out->ngeoms + col->ngeoms > geoms_size )
489  {
490  geoms_size += 16;
491  if ( lwgeom_out->geoms )
492  {
493  lwgeom_out->geoms = lwrealloc(lwgeom_out->geoms, geoms_size * sizeof(LWGEOM*));
494  }
495  else
496  {
497  lwgeom_out->geoms = lwalloc(geoms_size * sizeof(LWGEOM*));
498  }
499  }
500  for ( j = 0; j < col->ngeoms; j++ )
501  {
502  lwgeom_out->geoms[lwgeom_out->ngeoms] = col->geoms[j];
503  lwgeom_out->ngeoms++;
504  }
505  if ( col->type != mline->type )
506  {
507  homogeneous = 0;
508  }
509  /* Shallow free the struct, leaving the geoms behind. */
510  if ( col->bbox ) lwfree(col->bbox);
511  lwfree(col->geoms);
512  lwfree(col);
513  }
514  }
515  if ( lwgeom_out->bbox )
516  {
517  lwgeom_drop_bbox((LWGEOM*)lwgeom_out);
518  lwgeom_add_bbox((LWGEOM*)lwgeom_out);
519  }
520 
521  if ( ! homogeneous )
522  {
523  lwgeom_out->type = COLLECTIONTYPE;
524  }
525  }
526 
527  return lwgeom_out;
528 
529 }
uint8_t type
Definition: liblwgeom.h:461
void lwfree(void *mem)
Definition: lwutil.c:214
uint8_t type
Definition: liblwgeom.h:487
GBOX * bbox
Definition: liblwgeom.h:489
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:836
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:586
int ngeoms
Definition: liblwgeom.h:465
uint8_t flags
Definition: liblwgeom.h:488
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:130
LWGEOM ** geoms
Definition: liblwgeom.h:493
LWLINE ** geoms
Definition: liblwgeom.h:467
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:207
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
void * lwalloc(size_t size)
Definition: lwutil.c:199
#define MULTILINETYPE
Definition: liblwgeom.h:74
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:843
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
int32_t srid
Definition: liblwgeom.h:464
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:131
Here is the call graph for this function:
Here is the caller graph for this function: