PostGIS  2.4.9dev-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 470 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().

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