PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ LWGEOM_line_interpolate_point()

Datum LWGEOM_line_interpolate_point ( PG_FUNCTION_ARGS  )

Definition at line 182 of file lwgeom_functions_analytic.c.

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

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: