PostGIS  2.2.7dev-r@@SVN_REVISION@@
static LWGEOM * lwline_locate_between_m ( LWLINE lwline_in,
double  m0,
double  m1 
)
static

Definition at line 539 of file lwgeom_functions_lrs.c.

References COLLECTIONTYPE, lwalloc(), lwcollection_construct(), lwline_construct(), lwpoint_construct(), MULTILINETYPE, MULTIPOINTTYPE, POINTARRAY::npoints, POINTARRAYSET::nptarrays, LWLINE::points, ptarray_locate_between_m(), POINTARRAYSET::ptarrays, and LWLINE::srid.

Referenced by lwgeom_locate_between_m().

540 {
541  POINTARRAY *ipa=lwline_in->points;
542  int i;
543  LWGEOM **geoms;
544  int ngeoms;
545  int outtype;
546  int typeflag=0; /* see flags below */
547  const int pointflag=0x01;
548  const int lineflag=0x10;
549  POINTARRAYSET paset=ptarray_locate_between_m(ipa, m0, m1);
550 
551  POSTGIS_DEBUGF(2, "lwline_locate_between called for lwline %p", lwline_in);
552 
553  POSTGIS_DEBUGF(3, " ptarray_locate... returned %d pointarrays",
554  paset.nptarrays);
555 
556  if ( paset.nptarrays == 0 )
557  {
558  return NULL;
559  }
560 
561  ngeoms=paset.nptarrays;
562  /* TODO: rework this to reduce used memory */
563  geoms=lwalloc(sizeof(LWGEOM *)*ngeoms);
564  for (i=0; i<ngeoms; i++)
565  {
566  LWPOINT *lwpoint;
567  LWLINE *lwline;
568 
569  POINTARRAY *pa=paset.ptarrays[i];
570 
571  /* This is a point */
572  if ( pa->npoints == 1 )
573  {
574  lwpoint = lwpoint_construct(lwline_in->srid, NULL, pa);
575  geoms[i]=(LWGEOM *)lwpoint;
576  typeflag|=pointflag;
577  }
578 
579  /* This is a line */
580  else if ( pa->npoints > 1 )
581  {
582  lwline = lwline_construct(lwline_in->srid, NULL, pa);
583  geoms[i]=(LWGEOM *)lwline;
584  typeflag|=lineflag;
585  }
586 
587  /* This is a bug */
588  else
589  {
590  lwpgerror("ptarray_locate_between_m returned a POINARRAY set containing POINTARRAY with 0 points");
591  }
592 
593  }
594 
595  if ( ngeoms == 1 )
596  {
597  return geoms[0];
598  }
599  else
600  {
601  /* Choose best type */
602  if ( typeflag == 1 ) outtype=MULTIPOINTTYPE;
603  else if ( typeflag == 2 ) outtype=MULTILINETYPE;
604  else outtype = COLLECTIONTYPE;
605 
606  return (LWGEOM *)lwcollection_construct(outtype,
607  lwline_in->srid, NULL, ngeoms, geoms);
608  }
609 }
static POINTARRAYSET ptarray_locate_between_m(POINTARRAY *ipa, double m0, double m1)
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:30
int npoints
Definition: liblwgeom.h:355
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
POINTARRAY ** ptarrays
int32_t srid
Definition: liblwgeom.h:405
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:98
void * lwalloc(size_t size)
Definition: lwutil.c:199
#define MULTILINETYPE
Definition: liblwgeom.h:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
POINTARRAY * points
Definition: liblwgeom.h:406

Here is the call graph for this function:

Here is the caller graph for this function: