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

Definition at line 544 of file lwgeom_functions_lrs.c.

References COLLECTIONTYPE, lwalloc(), lwcollection_construct(), lwerror(), 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().

545 {
546  POINTARRAY *ipa=lwline_in->points;
547  int i;
548  LWGEOM **geoms;
549  int ngeoms;
550  int outtype;
551  int typeflag=0; /* see flags below */
552  const int pointflag=0x01;
553  const int lineflag=0x10;
554  POINTARRAYSET paset=ptarray_locate_between_m(ipa, m0, m1);
555 
556  POSTGIS_DEBUGF(2, "lwline_locate_between called for lwline %x", lwline_in);
557 
558  POSTGIS_DEBUGF(3, " ptarray_locate... returned %d pointarrays",
559  paset.nptarrays);
560 
561  if ( paset.nptarrays == 0 )
562  {
563  return NULL;
564  }
565 
566  ngeoms=paset.nptarrays;
567  /* TODO: rework this to reduce used memory */
568  geoms=lwalloc(sizeof(LWGEOM *)*ngeoms);
569  for (i=0; i<ngeoms; i++)
570  {
571  LWPOINT *lwpoint;
572  LWLINE *lwline;
573 
574  POINTARRAY *pa=paset.ptarrays[i];
575 
576  /* This is a point */
577  if ( pa->npoints == 1 )
578  {
579  lwpoint = lwpoint_construct(lwline_in->srid, NULL, pa);
580  geoms[i]=(LWGEOM *)lwpoint;
581  typeflag|=pointflag;
582  }
583 
584  /* This is a line */
585  else if ( pa->npoints > 1 )
586  {
587  lwline = lwline_construct(lwline_in->srid, NULL, pa);
588  geoms[i]=(LWGEOM *)lwline;
589  typeflag|=lineflag;
590  }
591 
592  /* This is a bug */
593  else
594  {
595  lwerror("ptarray_locate_between_m returned a POINARRAY set containing POINTARRAY with 0 points");
596  }
597 
598  }
599 
600  if ( ngeoms == 1 )
601  {
602  return geoms[0];
603  }
604  else
605  {
606  /* Choose best type */
607  if ( typeflag == 1 ) outtype=MULTIPOINTTYPE;
608  else if ( typeflag == 2 ) outtype=MULTILINETYPE;
609  else outtype = COLLECTIONTYPE;
610 
611  return (LWGEOM *)lwcollection_construct(outtype,
612  lwline_in->srid, NULL, ngeoms, geoms);
613  }
614 }
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:327
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
POINTARRAY ** ptarrays
int32_t srid
Definition: liblwgeom.h:377
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
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:96
void * lwalloc(size_t size)
Definition: lwutil.c:175
#define MULTILINETYPE
Definition: liblwgeom.h:64
#define COLLECTIONTYPE
Definition: liblwgeom.h:66
POINTARRAY * points
Definition: liblwgeom.h:378

Here is the call graph for this function:

Here is the caller graph for this function: