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

◆ 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
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)...
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,...
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition lwgeom.c:332
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:372
POINTARRAY * lwline_interpolate_points(const LWLINE *line, double length_fraction, char repeat)
Interpolate one or more points along a line.
Definition lwline.c:538
LWMPOINT * lwmpoint_construct(int32_t srid, const POINTARRAY *pa)
Definition lwmpoint.c:52
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LINETYPE
Definition liblwgeom.h:103
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
Definition lwpoint.c:129
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:367
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition lwgeom.c:207
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: