PostGIS  2.1.10dev-r@@SVN_REVISION@@
static POINTARRAYSET ptarray_locate_between_m ( POINTARRAY ipa,
double  m0,
double  m1 
)
static

Definition at line 428 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(), lwerror(), 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().

429 {
430  POINTARRAYSET ret;
431  POINTARRAY *dpa=NULL;
432  int i;
433 
434  ret.nptarrays=0;
435 
436  /*
437  * We allocate space for as many pointarray as
438  * segments in the input POINTARRAY, as worst
439  * case is for each segment to cross the M range
440  * window.
441  * TODO: rework this to reduce used memory
442  */
443  ret.ptarrays=lwalloc(sizeof(POINTARRAY *)*ipa->npoints-1);
444 
445  POSTGIS_DEBUGF(2, "ptarray_locate...: called for pointarray %x, m0:%g, m1:%g",
446  ipa, m0, m1);
447 
448 
449  for (i=1; i<ipa->npoints; i++)
450  {
451  POINT4D p1, p2;
452  int clipval;
453 
454  getPoint4d_p(ipa, i-1, &p1);
455  getPoint4d_p(ipa, i, &p2);
456 
457  POSTGIS_DEBUGF(3, " segment %d-%d [ %g %g %g %g - %g %g %g %g ]",
458  i-1, i,
459  p1.x, p1.y, p1.z, p1.m,
460  p2.x, p2.y, p2.z, p2.m);
461 
462  clipval = clip_seg_by_m_range(&p1, &p2, m0, m1);
463 
464  /* segment completely outside, nothing to do */
465  if (! clipval ) continue;
466 
467  POSTGIS_DEBUGF(3, " clipped to: [ %g %g %g %g - %g %g %g %g ] clipval: %x", p1.x, p1.y, p1.z, p1.m,
468  p2.x, p2.y, p2.z, p2.m, clipval);
469 
470  /* If no points have been accumulated so far, then if clipval != 0 the first point must be the
471  start of the intersection */
472  if (dpa == NULL)
473  {
474  POSTGIS_DEBUGF(3, " 1 creating new POINTARRAY with first point %g,%g,%g,%g", p1.x, p1.y, p1.z, p1.m);
475 
477  ptarray_append_point(dpa, &p1, LW_TRUE);
478  }
479 
480  /* Otherwise always add the next point, avoiding duplicates */
481  if (dpa)
482  ptarray_append_point(dpa, &p2, LW_FALSE);
483 
484  /*
485  * second point has been clipped
486  */
487  if ( clipval & 0x0100 || i == ipa->npoints-1 )
488  {
489  POSTGIS_DEBUGF(3, " closing pointarray %x with %d points", dpa, dpa->npoints);
490 
491  ret.ptarrays[ret.nptarrays++] = dpa;
492  dpa = NULL;
493  }
494  }
495 
496  /*
497  * if dpa!=NULL it means we didn't close it yet.
498  * this should never happen.
499  */
500  if ( dpa != NULL ) lwerror("Something wrong with algorithm");
501 
502  return ret;
503 }
double x
Definition: liblwgeom.h:308
double m
Definition: liblwgeom.h:308
int npoints
Definition: liblwgeom.h:327
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:57
POINTARRAY ** ptarrays
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
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:141
#define LW_FALSE
Definition: liblwgeom.h:52
uint8_t flags
Definition: liblwgeom.h:325
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
double z
Definition: liblwgeom.h:308
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
void * lwalloc(size_t size)
Definition: lwutil.c:175
double y
Definition: liblwgeom.h:308
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:217
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: