PostGIS  2.3.7dev-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 471 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().

472 {
473  LWCOLLECTION *lwgeom_out = NULL;
474 
475  if ( ! mline )
476  {
477  lwerror("Null input geometry.");
478  return NULL;
479  }
480 
481  if ( mline->ngeoms == 1)
482  {
483  lwgeom_out = lwline_clip_to_ordinate_range(mline->geoms[0], ordinate, from, to);
484  }
485  else
486  {
487  LWCOLLECTION *col;
488  char hasz = lwgeom_has_z(lwmline_as_lwgeom(mline));
489  char hasm = lwgeom_has_m(lwmline_as_lwgeom(mline));
490  int i, j;
491  char homogeneous = 1;
492  size_t geoms_size = 0;
493  lwgeom_out = lwcollection_construct_empty(MULTILINETYPE, mline->srid, hasz, hasm);
494  FLAGS_SET_Z(lwgeom_out->flags, hasz);
495  FLAGS_SET_M(lwgeom_out->flags, hasm);
496  for ( i = 0; i < mline->ngeoms; i ++ )
497  {
498  col = lwline_clip_to_ordinate_range(mline->geoms[i], ordinate, from, to);
499  if ( col )
500  {
501  /* Something was left after the clip. */
502  if ( lwgeom_out->ngeoms + col->ngeoms > geoms_size )
503  {
504  geoms_size += 16;
505  if ( lwgeom_out->geoms )
506  {
507  lwgeom_out->geoms = lwrealloc(lwgeom_out->geoms, geoms_size * sizeof(LWGEOM*));
508  }
509  else
510  {
511  lwgeom_out->geoms = lwalloc(geoms_size * sizeof(LWGEOM*));
512  }
513  }
514  for ( j = 0; j < col->ngeoms; j++ )
515  {
516  lwgeom_out->geoms[lwgeom_out->ngeoms] = col->geoms[j];
517  lwgeom_out->ngeoms++;
518  }
519  if ( col->type != mline->type )
520  {
521  homogeneous = 0;
522  }
523  /* Shallow free the struct, leaving the geoms behind. */
524  if ( col->bbox ) lwfree(col->bbox);
525  lwfree(col->geoms);
526  lwfree(col);
527  }
528  }
529  if ( lwgeom_out->bbox )
530  {
531  lwgeom_drop_bbox((LWGEOM*)lwgeom_out);
532  lwgeom_add_bbox((LWGEOM*)lwgeom_out);
533  }
534 
535  if ( ! homogeneous )
536  {
537  lwgeom_out->type = COLLECTIONTYPE;
538  }
539  }
540 
541  return lwgeom_out;
542 
543 }
uint8_t type
Definition: liblwgeom.h:476
void lwfree(void *mem)
Definition: lwutil.c:242
uint8_t type
Definition: liblwgeom.h:502
GBOX * bbox
Definition: liblwgeom.h:504
LWGEOM * lwmline_as_lwgeom(const LWMLINE *obj)
Definition: lwgeom.c:222
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:849
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:599
int ngeoms
Definition: liblwgeom.h:480
uint8_t flags
Definition: liblwgeom.h:503
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:145
LWGEOM ** geoms
Definition: liblwgeom.h:508
LWLINE ** geoms
Definition: liblwgeom.h:482
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:235
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:612
void * lwalloc(size_t size)
Definition: lwutil.c:227
#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:856
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
#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: