PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_setpoint_linestring()

Datum LWGEOM_setpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 2276 of file lwgeom_functions_basic.c.

2277 {
2278  GSERIALIZED *pglwg1, *pglwg2, *result;
2279  LWGEOM *lwg;
2280  LWLINE *line;
2281  LWPOINT *lwpoint;
2282  POINT4D newpoint;
2283  int32 which;
2284 
2285  POSTGIS_DEBUG(2, "LWGEOM_setpoint_linestring called.");
2286 
2287  /* we copy input as we're going to modify it */
2288  pglwg1 = PG_GETARG_GSERIALIZED_P_COPY(0);
2289 
2290  which = PG_GETARG_INT32(1);
2291  pglwg2 = PG_GETARG_GSERIALIZED_P(2);
2292 
2293 
2294  /* Extract a POINT4D from the point */
2295  lwg = lwgeom_from_gserialized(pglwg2);
2296  lwpoint = lwgeom_as_lwpoint(lwg);
2297  if ( ! lwpoint )
2298  {
2299  elog(ERROR, "Third argument must be a POINT");
2300  PG_RETURN_NULL();
2301  }
2302  getPoint4d_p(lwpoint->point, 0, &newpoint);
2303  lwpoint_free(lwpoint);
2304  PG_FREE_IF_COPY(pglwg2, 2);
2305 
2306  lwg = lwgeom_from_gserialized(pglwg1);
2307  line = lwgeom_as_lwline(lwg);
2308  if ( ! line )
2309  {
2310  elog(ERROR, "First argument must be a LINESTRING");
2311  PG_RETURN_NULL();
2312  }
2313 
2314  if ( line->points->npoints < 1 ) {
2315  elog(ERROR, "Line has no points");
2316  PG_RETURN_NULL();
2317  }
2318 
2319  if(which < 0){
2320  /* Use backward indexing for negative values */
2321  which = which + line->points->npoints ;
2322  }
2323  if ( (uint32_t)which + 1 > line->points->npoints )
2324  {
2325  elog(ERROR, "abs(Point index) out of range (-)(%d..%d)", 0, line->points->npoints-1);
2326  PG_RETURN_NULL();
2327  }
2328 
2329  /*
2330  * This will change pointarray of the serialized pglwg1,
2331  */
2332  lwline_setPoint4d(line, (uint32_t)which, &newpoint);
2333  result = geometry_serialize((LWGEOM *)line);
2334 
2335  /* Release memory */
2336  lwline_free(line);
2337  pfree(pglwg1); /* we forced copy, POINARRAY is released now */
2338 
2339  PG_RETURN_POINTER(result);
2340 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:123
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:373
void lwline_free(LWLINE *line)
Definition: lwline.c:76
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
unsigned int int32
Definition: shpopen.c:273
POINTARRAY * points
Definition: liblwgeom.h:425
POINTARRAY * point
Definition: liblwgeom.h:414
uint32_t npoints
Definition: liblwgeom.h:374
unsigned int uint32_t
Definition: uthash.h:78

References geometry_serialize(), getPoint4d_p(), lwgeom_as_lwline(), lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwline_free(), lwline_setPoint4d(), lwpoint_free(), POINTARRAY::npoints, LWPOINT::point, and LWLINE::points.

Here is the call graph for this function: