PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ ptarray_locate_between_m()

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

Definition at line 436 of file lwgeom_functions_lrs.c.

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

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

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