PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ LWGEOM_setpoint_linestring()

Datum LWGEOM_setpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 2271 of file lwgeom_functions_basic.c.

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

Referenced by LWGEOM_removepoint().

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