PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ LWGEOM_line_interpolate_point()

Datum LWGEOM_line_interpolate_point ( PG_FUNCTION_ARGS  )

Definition at line 183 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.

Referenced by LWGEOM_ChaikinSmoothing().

184 {
185  GSERIALIZED *gser = PG_GETARG_GSERIALIZED_P(0);
186  GSERIALIZED *result;
187  double distance_fraction = PG_GETARG_FLOAT8(1);
188  int repeat = PG_NARGS() > 2 && PG_GETARG_BOOL(2);
189  int srid = gserialized_get_srid(gser);
190  LWLINE* lwline;
191  LWGEOM* lwresult;
192  POINTARRAY* opa;
193 
194  if ( distance_fraction < 0 || distance_fraction > 1 )
195  {
196  elog(ERROR,"line_interpolate_point: 2nd arg isn't within [0,1]");
197  PG_FREE_IF_COPY(gser, 0);
198  PG_RETURN_NULL();
199  }
200 
201  if ( gserialized_get_type(gser) != LINETYPE )
202  {
203  elog(ERROR,"line_interpolate_point: 1st arg isn't a line");
204  PG_FREE_IF_COPY(gser, 0);
205  PG_RETURN_NULL();
206  }
207 
209  opa = lwline_interpolate_points(lwline, distance_fraction, repeat);
210 
211  lwgeom_free(lwline_as_lwgeom(lwline));
212  PG_FREE_IF_COPY(gser, 0);
213 
214  if (opa->npoints <= 1)
215  {
216  lwresult = lwpoint_as_lwgeom(lwpoint_construct(srid, NULL, opa));
217  } else {
218  lwresult = lwmpoint_as_lwgeom(lwmpoint_construct(srid, opa));
219  }
220 
221  result = geometry_serialize(lwresult);
222  lwgeom_free(lwresult);
223 
224  PG_RETURN_POINTER(result);
225 }
#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:1144
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:330
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
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:295
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: