PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ ptarray_locate_between_m()

static POINTARRAYSET ptarray_locate_between_m ( POINTARRAY ipa,
double  m0,
double  m1 
)
static

Definition at line 423 of file lwgeom_functions_lrs.c.

References clip_seg_by_m_range(), POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, getPoint4d_p(), LW_FALSE, LW_TRUE, lwalloc(), POINT4D::m, POINTARRAY::npoints, POINTARRAYSET::nptarrays, ptarray_append_point(), ptarray_construct_empty(), POINTARRAYSET::ptarrays, POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by lwline_locate_between_m().

424 {
425  POINTARRAYSET ret;
426  POINTARRAY *dpa=NULL;
427  int i;
428 
429  ret.nptarrays=0;
430 
431  /*
432  * We allocate space for as many pointarray as
433  * segments in the input POINTARRAY, as worst
434  * case is for each segment to cross the M range
435  * window.
436  * TODO: rework this to reduce used memory
437  */
438  ret.ptarrays=lwalloc(sizeof(POINTARRAY *)*ipa->npoints-1);
439 
440  POSTGIS_DEBUGF(2, "ptarray_locate...: called for pointarray %p, m0:%g, m1:%g",
441  ipa, m0, m1);
442 
443 
444  for (i=1; i<ipa->npoints; i++)
445  {
446  POINT4D p1, p2;
447  int clipval;
448 
449  getPoint4d_p(ipa, i-1, &p1);
450  getPoint4d_p(ipa, i, &p2);
451 
452  POSTGIS_DEBUGF(3, " segment %d-%d [ %g %g %g %g - %g %g %g %g ]",
453  i-1, i,
454  p1.x, p1.y, p1.z, p1.m,
455  p2.x, p2.y, p2.z, p2.m);
456 
457  clipval = clip_seg_by_m_range(&p1, &p2, m0, m1);
458 
459  /* segment completely outside, nothing to do */
460  if (! clipval ) continue;
461 
462  POSTGIS_DEBUGF(3, " clipped to: [ %g %g %g %g - %g %g %g %g ] clipval: %d", p1.x, p1.y, p1.z, p1.m,
463  p2.x, p2.y, p2.z, p2.m, clipval);
464 
465  /* If no points have been accumulated so far, then if clipval != 0 the first point must be the
466  start of the intersection */
467  if (dpa == NULL)
468  {
469  POSTGIS_DEBUGF(3, " 1 creating new POINTARRAY with first point %g,%g,%g,%g", p1.x, p1.y, p1.z, p1.m);
470 
472  ptarray_append_point(dpa, &p1, LW_TRUE);
473  }
474 
475  /* Otherwise always add the next point, avoiding duplicates */
476  if (dpa)
477  ptarray_append_point(dpa, &p2, LW_FALSE);
478 
479  /*
480  * second point has been clipped
481  */
482  if ( clipval & 0x0100 || i == ipa->npoints-1 )
483  {
484  POSTGIS_DEBUGF(3, " closing pointarray %p with %d points", dpa, dpa->npoints);
485 
486  ret.ptarrays[ret.nptarrays++] = dpa;
487  dpa = NULL;
488  }
489  }
490 
491  /*
492  * if dpa!=NULL it means we didn't close it yet.
493  * this should never happen.
494  */
495  if ( dpa != NULL ) lwpgerror("Something wrong with algorithm");
496 
497  return ret;
498 }
double x
Definition: liblwgeom.h:336
double m
Definition: liblwgeom.h:336
int npoints
Definition: liblwgeom.h:355
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
POINTARRAY ** ptarrays
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:62
uint8_t flags
Definition: liblwgeom.h:353
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:124
double z
Definition: liblwgeom.h:336
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:125
void * lwalloc(size_t size)
Definition: lwutil.c:199
double y
Definition: liblwgeom.h:336
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231
static int clip_seg_by_m_range(POINT4D *p1, POINT4D *p2, double m0, double m1)
Here is the call graph for this function:
Here is the caller graph for this function: