PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_setpoint_linestring()

Datum LWGEOM_setpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 2260 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().

2261 {
2262  GSERIALIZED *pglwg1, *pglwg2, *result;
2263  LWGEOM *lwg;
2264  LWLINE *line;
2265  LWPOINT *lwpoint;
2266  POINT4D newpoint;
2267  int32 which;
2268 
2269  POSTGIS_DEBUG(2, "LWGEOM_setpoint_linestring called.");
2270 
2271  /* we copy input as we're going to modify it */
2272  pglwg1 = PG_GETARG_GSERIALIZED_P_COPY(0);
2273 
2274  which = PG_GETARG_INT32(1);
2275  pglwg2 = PG_GETARG_GSERIALIZED_P(2);
2276 
2277 
2278  /* Extract a POINT4D from the point */
2279  lwg = lwgeom_from_gserialized(pglwg2);
2280  lwpoint = lwgeom_as_lwpoint(lwg);
2281  if ( ! lwpoint )
2282  {
2283  elog(ERROR, "Third argument must be a POINT");
2284  PG_RETURN_NULL();
2285  }
2286  getPoint4d_p(lwpoint->point, 0, &newpoint);
2287  lwpoint_free(lwpoint);
2288  PG_FREE_IF_COPY(pglwg2, 2);
2289 
2290  lwg = lwgeom_from_gserialized(pglwg1);
2291  line = lwgeom_as_lwline(lwg);
2292  if ( ! line )
2293  {
2294  elog(ERROR, "First argument must be a LINESTRING");
2295  PG_RETURN_NULL();
2296  }
2297  if(which < 0){
2298  /* Use backward indexing for negative values */
2299  which = which + line->points->npoints ;
2300  }
2301  if ( which > line->points->npoints-1 || which < 0 )
2302  {
2303  elog(ERROR, "abs(Point index) out of range (-)(%d..%d)", 0, line->points->npoints-1);
2304  PG_RETURN_NULL();
2305  }
2306 
2307  /*
2308  * This will change pointarray of the serialized pglwg1,
2309  */
2310  lwline_setPoint4d(line, which, &newpoint);
2311  result = geometry_serialize((LWGEOM *)line);
2312 
2313  /* Release memory */
2314  lwline_free(line);
2315  pfree(pglwg1); /* we forced copy, POINARRAY is released now */
2316 
2317  PG_RETURN_POINTER(result);
2318 }
unsigned int int32
Definition: shpopen.c:273
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:371
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:129
POINTARRAY * point
Definition: liblwgeom.h:411
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:380
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
POINTARRAY * points
Definition: liblwgeom.h:422
Here is the call graph for this function:
Here is the caller graph for this function: