PostGIS  2.5.7dev-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 468 of file lwlinearreferencing.c.

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

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

Here is the call graph for this function:
Here is the caller graph for this function: