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

Definition at line 2231 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, and LWLINE::points.

2232 {
2233  GSERIALIZED *pglwg1, *pglwg2, *result;
2234  LWGEOM *lwg;
2235  LWLINE *line;
2236  LWPOINT *lwpoint;
2237  POINT4D newpoint;
2238  uint32 which;
2239 
2240  POSTGIS_DEBUG(2, "LWGEOM_setpoint_linestring called.");
2241 
2242  /* we copy input as we're going to modify it */
2243  pglwg1 = PG_GETARG_GSERIALIZED_P_COPY(0);
2244 
2245  which = PG_GETARG_INT32(1);
2246  pglwg2 = PG_GETARG_GSERIALIZED_P(2);
2247 
2248 
2249  /* Extract a POINT4D from the point */
2250  lwg = lwgeom_from_gserialized(pglwg2);
2251  lwpoint = lwgeom_as_lwpoint(lwg);
2252  if ( ! lwpoint )
2253  {
2254  elog(ERROR, "Third argument must be a POINT");
2255  PG_RETURN_NULL();
2256  }
2257  getPoint4d_p(lwpoint->point, 0, &newpoint);
2258  lwpoint_free(lwpoint);
2259  PG_FREE_IF_COPY(pglwg2, 2);
2260 
2261  lwg = lwgeom_from_gserialized(pglwg1);
2262  line = lwgeom_as_lwline(lwg);
2263  if ( ! line )
2264  {
2265  elog(ERROR, "First argument must be a LINESTRING");
2266  PG_RETURN_NULL();
2267  }
2268  if ( lwgeom_is_empty(lwg) )
2269  {
2270  elog(ERROR, "Cannot set point values on EMPTY geometry, use ST_AddPoint to add points");
2271  PG_RETURN_NULL();
2272  }
2273  if ( which > line->points->npoints-1 )
2274  {
2275  elog(ERROR, "Point index out of range (%d..%d)", 0, line->points->npoints-1);
2276  PG_RETURN_NULL();
2277  }
2278 
2279  /*
2280  * This will change pointarray of the serialized pglwg1,
2281  */
2282  lwline_setPoint4d(line, which, &newpoint);
2283  result = geometry_serialize((LWGEOM *)line);
2284 
2285  /* Release memory */
2286  lwline_free(line);
2287  pfree(pglwg1); /* we forced copy, POINARRAY is released now */
2288 
2289  PG_RETURN_POINTER(result);
2290 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:355
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:182
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:395
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:351
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:1297
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231
POINTARRAY * points
Definition: liblwgeom.h:406

Here is the call graph for this function: