PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum LWGEOM_line_interpolate_point ( PG_FUNCTION_ARGS  )

Definition at line 141 of file lwgeom_functions_analytic.c.

References geometry_serialize(), gserialized_get_srid(), gserialized_get_type(), LINETYPE, lwgeom_as_lwline(), lwgeom_free(), lwgeom_from_gserialized(), lwline_as_lwgeom(), lwline_interpolate_points(), lwmpoint_as_lwgeom(), lwmpoint_construct(), lwpoint_as_lwgeom(), lwpoint_construct(), and POINTARRAY::npoints.

142 {
143  GSERIALIZED *gser = PG_GETARG_GSERIALIZED_P(0);
144  GSERIALIZED *result;
145  double distance_fraction = PG_GETARG_FLOAT8(1);
146  int repeat = PG_NARGS() > 2 && PG_GETARG_BOOL(2);
147  int srid = gserialized_get_srid(gser);
148  LWLINE* lwline;
149  LWGEOM* lwresult;
150  POINTARRAY* opa;
151 
152  if ( distance_fraction < 0 || distance_fraction > 1 )
153  {
154  elog(ERROR,"line_interpolate_point: 2nd arg isn't within [0,1]");
155  PG_FREE_IF_COPY(gser, 0);
156  PG_RETURN_NULL();
157  }
158 
159  if ( gserialized_get_type(gser) != LINETYPE )
160  {
161  elog(ERROR,"line_interpolate_point: 1st arg isn't a line");
162  PG_FREE_IF_COPY(gser, 0);
163  PG_RETURN_NULL();
164  }
165 
167  opa = lwline_interpolate_points(lwline, distance_fraction, repeat);
168 
169  lwgeom_free(lwline_as_lwgeom(lwline));
170  PG_FREE_IF_COPY(gser, 0);
171 
172  if (opa->npoints <= 1)
173  {
174  lwresult = lwpoint_as_lwgeom(lwpoint_construct(srid, NULL, opa));
175  } else {
176  lwresult = lwmpoint_as_lwgeom(lwmpoint_construct(srid, opa));
177  }
178 
179  result = geometry_serialize(lwresult);
180  lwgeom_free(lwresult);
181 
182  PG_RETURN_POINTER(result);
183 }
#define LINETYPE
Definition: liblwgeom.h:85
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:86
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
LWMPOINT * lwmpoint_construct(int srid, const POINTARRAY *pa)
Definition: lwmpoint.c:52
POINTARRAY * lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat)
Interpolate one or more points along a line.
Definition: lwline.c:542
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:329
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:169
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:334
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:99
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:294
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function: