PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ lwline_locate_between_m()

static LWGEOM * lwline_locate_between_m ( LWLINE lwline_in,
double  m0,
double  m1 
)
static

Definition at line 552 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().

553 {
554  POINTARRAY *ipa=lwline_in->points;
555  int i;
556  LWGEOM **geoms;
557  int ngeoms;
558  int outtype;
559  int typeflag=0; /* see flags below */
560  const int pointflag=0x01;
561  const int lineflag=0x10;
562  POINTARRAYSET paset=ptarray_locate_between_m(ipa, m0, m1);
563 
564  POSTGIS_DEBUGF(2, "lwline_locate_between called for lwline %p", lwline_in);
565 
566  POSTGIS_DEBUGF(3, " ptarray_locate... returned %d pointarrays",
567  paset.nptarrays);
568 
569  if ( paset.nptarrays == 0 )
570  {
571  return NULL;
572  }
573 
574  ngeoms=paset.nptarrays;
575  /* TODO: rework this to reduce used memory */
576  geoms=lwalloc(sizeof(LWGEOM *)*ngeoms);
577  for (i=0; i<ngeoms; i++)
578  {
579  LWPOINT *lwpoint;
580  LWLINE *lwline;
581 
582  POINTARRAY *pa=paset.ptarrays[i];
583 
584  /* This is a point */
585  if ( pa->npoints == 1 )
586  {
587  lwpoint = lwpoint_construct(lwline_in->srid, NULL, pa);
588  geoms[i]=(LWGEOM *)lwpoint;
589  typeflag|=pointflag;
590  }
591 
592  /* This is a line */
593  else if ( pa->npoints > 1 )
594  {
595  lwline = lwline_construct(lwline_in->srid, NULL, pa);
596  geoms[i]=(LWGEOM *)lwline;
597  typeflag|=lineflag;
598  }
599 
600  /* This is a bug */
601  else
602  {
603  lwpgerror("ptarray_locate_between_m returned a POINARRAY set containing POINTARRAY with 0 points");
604  }
605 
606  }
607 
608  if ( ngeoms == 1 )
609  {
610  return geoms[0];
611  }
612  else
613  {
614  /* Choose best type */
615  if ( typeflag == 1 ) outtype=MULTIPOINTTYPE;
616  else if ( typeflag == 2 ) outtype=MULTILINETYPE;
617  else outtype = COLLECTIONTYPE;
618 
619  return (LWGEOM *)lwcollection_construct(outtype,
620  lwline_in->srid, NULL, ngeoms, geoms);
621  }
622 }
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:43
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
POINTARRAY ** ptarrays
int32_t srid
Definition: liblwgeom.h:423
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
void * lwalloc(size_t size)
Definition: lwutil.c:229
#define MULTILINETYPE
Definition: liblwgeom.h:88
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
POINTARRAY * points
Definition: liblwgeom.h:424
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: