PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_line_interpolate_point()

Datum LWGEOM_line_interpolate_point ( PG_FUNCTION_ARGS  )

Definition at line 184 of file lwgeom_functions_analytic.c.

185 {
186  GSERIALIZED *gser = PG_GETARG_GSERIALIZED_P(0);
187  GSERIALIZED *result;
188  double distance_fraction = PG_GETARG_FLOAT8(1);
189  int repeat = PG_NARGS() > 2 && PG_GETARG_BOOL(2);
190  int srid = gserialized_get_srid(gser);
191  LWLINE* lwline;
192  LWGEOM* lwresult;
193  POINTARRAY* opa;
194 
195  if ( distance_fraction < 0 || distance_fraction > 1 )
196  {
197  elog(ERROR,"line_interpolate_point: 2nd arg isn't within [0,1]");
198  PG_FREE_IF_COPY(gser, 0);
199  PG_RETURN_NULL();
200  }
201 
202  if ( gserialized_get_type(gser) != LINETYPE )
203  {
204  elog(ERROR,"line_interpolate_point: 1st arg isn't a line");
205  PG_FREE_IF_COPY(gser, 0);
206  PG_RETURN_NULL();
207  }
208 
210  opa = lwline_interpolate_points(lwline, distance_fraction, repeat);
211 
212  lwgeom_free(lwline_as_lwgeom(lwline));
213  PG_FREE_IF_COPY(gser, 0);
214 
215  if (opa->npoints <= 1)
216  {
217  lwresult = lwpoint_as_lwgeom(lwpoint_construct(srid, NULL, opa));
218  } else {
219  lwresult = lwmpoint_as_lwgeom(lwmpoint_construct(srid, opa));
220  }
221 
222  result = geometry_serialize(lwresult);
223  lwgeom_free(lwresult);
224 
225  PG_RETURN_POINTER(result);
226 }
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:100
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:330
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LINETYPE
Definition: liblwgeom.h:86
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:295
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 * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
LWMPOINT * lwmpoint_construct(int srid, const POINTARRAY *pa)
Definition: lwmpoint.c:52
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint32_t npoints
Definition: liblwgeom.h:374

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.

Here is the call graph for this function: