PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_line_interpolate_point()

Datum LWGEOM_line_interpolate_point ( PG_FUNCTION_ARGS  )

Definition at line 176 of file lwgeom_functions_analytic.c.

177 {
178  GSERIALIZED *gser = PG_GETARG_GSERIALIZED_P(0);
180  double distance_fraction = PG_GETARG_FLOAT8(1);
181  int repeat = PG_NARGS() > 2 && PG_GETARG_BOOL(2);
182  int32_t srid = gserialized_get_srid(gser);
183  LWLINE* lwline;
184  LWGEOM* lwresult;
185  POINTARRAY* opa;
186 
187  if ( distance_fraction < 0 || distance_fraction > 1 )
188  {
189  elog(ERROR,"line_interpolate_point: 2nd arg isn't within [0,1]");
190  PG_FREE_IF_COPY(gser, 0);
191  PG_RETURN_NULL();
192  }
193 
194  if ( gserialized_get_type(gser) != LINETYPE )
195  {
196  elog(ERROR,"line_interpolate_point: 1st arg isn't a line");
197  PG_FREE_IF_COPY(gser, 0);
198  PG_RETURN_NULL();
199  }
200 
202  opa = lwline_interpolate_points(lwline, distance_fraction, repeat);
203 
204  lwgeom_free(lwline_as_lwgeom(lwline));
205  PG_FREE_IF_COPY(gser, 0);
206 
207  if (opa->npoints <= 1)
208  {
209  lwresult = lwpoint_as_lwgeom(lwpoint_construct(srid, NULL, opa));
210  } else {
211  lwresult = lwmpoint_as_lwgeom(lwmpoint_construct(srid, opa));
212  }
213 
214  result = geometry_serialize(lwresult);
215  lwgeom_free(lwresult);
216 
217  PG_RETURN_POINTER(result);
218 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:155
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:118
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:339
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
#define LINETYPE
Definition: liblwgeom.h:103
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:304
POINTARRAY * lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat)
Interpolate one or more points along a line.
Definition: lwline.c:528
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:344
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
LWMPOINT * lwmpoint_construct(int32_t srid, const POINTARRAY *pa)
Definition: lwmpoint.c:52
uint32_t npoints
Definition: liblwgeom.h:427

References 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(), POINTARRAY::npoints, and result.

Here is the call graph for this function: