PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum LWGEOM_setpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 2296 of file lwgeom_functions_basic.c.

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

2297 {
2298  GSERIALIZED *pglwg1, *pglwg2, *result;
2299  LWGEOM *lwg;
2300  LWLINE *line;
2301  LWPOINT *lwpoint;
2302  POINT4D newpoint;
2303  uint32 which;
2304 
2305  POSTGIS_DEBUG(2, "LWGEOM_setpoint_linestring called.");
2306 
2307  /* we copy input as we're going to modify it */
2308  pglwg1 = (GSERIALIZED *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
2309 
2310  which = PG_GETARG_INT32(1);
2311  pglwg2 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(2));
2312 
2313 
2314  /* Extract a POINT4D from the point */
2315  lwg = lwgeom_from_gserialized(pglwg2);
2316  lwpoint = lwgeom_as_lwpoint(lwg);
2317  if ( ! lwpoint )
2318  {
2319  elog(ERROR, "Third argument must be a POINT");
2320  PG_RETURN_NULL();
2321  }
2322  getPoint4d_p(lwpoint->point, 0, &newpoint);
2323  lwpoint_free(lwpoint);
2324  PG_FREE_IF_COPY(pglwg2, 2);
2325 
2326  lwg = lwgeom_from_gserialized(pglwg1);
2327  line = lwgeom_as_lwline(lwg);
2328  if ( ! line )
2329  {
2330  elog(ERROR, "First argument must be a LINESTRING");
2331  PG_RETURN_NULL();
2332  }
2333  if ( lwgeom_is_empty(lwg) )
2334  {
2335  elog(ERROR, "Cannot set point values on EMPTY geometry, use ST_AddPoint to add points");
2336  PG_RETURN_NULL();
2337  }
2338  if ( which > line->points->npoints-1 )
2339  {
2340  elog(ERROR, "Point index out of range (%d..%d)", 0, line->points->npoints-1);
2341  PG_RETURN_NULL();
2342  }
2343 
2344  /*
2345  * This will change pointarray of the serialized pglwg1,
2346  */
2347  lwline_setPoint4d(line, which, &newpoint);
2348  result = geometry_serialize((LWGEOM *)line);
2349 
2350  /* Release memory */
2351  lwline_free(line);
2352  pfree(pglwg1); /* we forced copy, POINARRAY is released now */
2353 
2354  PG_RETURN_POINTER(result);
2355 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:327
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:180
void lwline_free(LWLINE *line)
Definition: lwline.c:63
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
POINTARRAY * point
Definition: liblwgeom.h:367
char ** result
Definition: liblwgeom.h:218
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:350
unsigned int uint32
Definition: shpopen.c:274
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1229
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:217
POINTARRAY * points
Definition: liblwgeom.h:378

Here is the call graph for this function: