PostGIS  2.5.0dev-r@@SVN_REVISION@@
LWCOLLECTION* lwmline_clip_to_ordinate_range ( const LWMLINE mline,
char  ordinate,
double  from,
double  to 
)

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

Use for m- and z- clipping

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

Definition at line 469 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_has_m(), lwgeom_has_z(), lwgeom_refresh_bbox(), 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().

470 {
471  LWCOLLECTION *lwgeom_out = NULL;
472 
473  if ( ! mline )
474  {
475  lwerror("Null input geometry.");
476  return NULL;
477  }
478 
479  if ( mline->ngeoms == 1)
480  {
481  lwgeom_out = lwline_clip_to_ordinate_range(mline->geoms[0], ordinate, from, to);
482  }
483  else
484  {
485  LWCOLLECTION *col;
486  char hasz = lwgeom_has_z(lwmline_as_lwgeom(mline));
487  char hasm = lwgeom_has_m(lwmline_as_lwgeom(mline));
488  uint32_t i, j;
489  char homogeneous = 1;
490  size_t geoms_size = 0;
491  lwgeom_out = lwcollection_construct_empty(MULTILINETYPE, mline->srid, hasz, hasm);
492  FLAGS_SET_Z(lwgeom_out->flags, hasz);
493  FLAGS_SET_M(lwgeom_out->flags, hasm);
494  for ( i = 0; i < mline->ngeoms; i ++ )
495  {
496  col = lwline_clip_to_ordinate_range(mline->geoms[i], ordinate, from, to);
497  if ( col )
498  {
499  /* Something was left after the clip. */
500  if ( lwgeom_out->ngeoms + col->ngeoms > geoms_size )
501  {
502  geoms_size += 16;
503  if ( lwgeom_out->geoms )
504  {
505  lwgeom_out->geoms = lwrealloc(lwgeom_out->geoms, geoms_size * sizeof(LWGEOM*));
506  }
507  else
508  {
509  lwgeom_out->geoms = lwalloc(geoms_size * sizeof(LWGEOM*));
510  }
511  }
512  for ( j = 0; j < col->ngeoms; j++ )
513  {
514  lwgeom_out->geoms[lwgeom_out->ngeoms] = col->geoms[j];
515  lwgeom_out->ngeoms++;
516  }
517  if ( col->type != mline->type )
518  {
519  homogeneous = 0;
520  }
521  /* Shallow free the struct, leaving the geoms behind. */
522  if ( col->bbox ) lwfree(col->bbox);
523  lwfree(col->geoms);
524  lwfree(col);
525  }
526  }
527  if ( lwgeom_out->bbox )
528  {
529  lwgeom_refresh_bbox((LWGEOM*)lwgeom_out);
530  }
531 
532  if ( ! homogeneous )
533  {
534  lwgeom_out->type = COLLECTIONTYPE;
535  }
536  }
537 
538  return lwgeom_out;
539 
540 }
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:691
uint8_t type
Definition: liblwgeom.h:476
void lwfree(void *mem)
Definition: lwutil.c:244
uint8_t type
Definition: liblwgeom.h:502
GBOX * bbox
Definition: liblwgeom.h:504
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition: lwgeom.c:289
uint32_t ngeoms
Definition: liblwgeom.h:506
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:923
unsigned int uint32_t
Definition: uthash.h:78
uint8_t flags
Definition: liblwgeom.h:503
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:145
LWGEOM ** geoms
Definition: liblwgeom.h:508
uint32_t ngeoms
Definition: liblwgeom.h:480
LWLINE ** geoms
Definition: liblwgeom.h:482
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
void * lwalloc(size_t size)
Definition: lwutil.c:229
#define MULTILINETYPE
Definition: liblwgeom.h:88
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:930
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
int32_t srid
Definition: liblwgeom.h:479
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:146

Here is the call graph for this function:

Here is the caller graph for this function: