PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ LWGEOM_setpoint_linestring()

Datum LWGEOM_setpoint_linestring ( PG_FUNCTION_ARGS  )

Definition at line 2419 of file lwgeom_functions_basic.c.

2420 {
2421  GSERIALIZED *pglwg1, *pglwg2, *result;
2422  LWGEOM *lwg;
2423  LWLINE *line;
2424  LWPOINT *lwpoint;
2425  POINT4D newpoint;
2426  int64_t which;
2427 
2428  POSTGIS_DEBUG(2, "LWGEOM_setpoint_linestring called.");
2429 
2430  /* we copy input as we're going to modify it */
2431  pglwg1 = PG_GETARG_GSERIALIZED_P_COPY(0);
2432 
2433  which = PG_GETARG_INT32(1);
2434  pglwg2 = PG_GETARG_GSERIALIZED_P(2);
2435 
2436  /* Extract a POINT4D from the point */
2437  lwg = lwgeom_from_gserialized(pglwg2);
2438  lwpoint = lwgeom_as_lwpoint(lwg);
2439  if (!lwpoint)
2440  {
2441  elog(ERROR, "Third argument must be a POINT");
2442  PG_RETURN_NULL();
2443  }
2444  getPoint4d_p(lwpoint->point, 0, &newpoint);
2445  lwpoint_free(lwpoint);
2446  PG_FREE_IF_COPY(pglwg2, 2);
2447 
2448  lwg = lwgeom_from_gserialized(pglwg1);
2449  line = lwgeom_as_lwline(lwg);
2450 
2451  if (!line)
2452  {
2453  elog(ERROR, "First argument must be a LINESTRING");
2454  PG_RETURN_NULL();
2455  }
2456 
2457  if ( line->points->npoints < 1 ) {
2458  elog(ERROR, "Line has no points");
2459  PG_RETURN_NULL();
2460  }
2461 
2462  if (!lwgeom_isfinite(lwg))
2463  {
2464  elog(ERROR, "Geometry contains invalid coordinate");
2465  PG_RETURN_NULL();
2466  }
2467 
2468  if (which < 0)
2469  {
2470  /* Use backward indexing for negative values */
2471  which += (int64_t)line->points->npoints;
2472  }
2473  if ((uint32_t)which > line->points->npoints - 1)
2474  {
2475  elog(ERROR, "abs(Point index) out of range (-)(%u..%u)", 0, line->points->npoints - 1);
2476  PG_RETURN_NULL();
2477  }
2478 
2479  /*
2480  * This will change pointarray of the serialized pglwg1,
2481  */
2482  lwline_setPoint4d(line, (uint32_t)which, &newpoint);
2483  result = geometry_serialize((LWGEOM *)line);
2484 
2485  /* Release memory */
2486  lwline_free(line);
2487  pfree(pglwg1); /* we forced copy, POINARRAY is released now */
2488 
2489  PG_RETURN_POINTER(result);
2490 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
int lwgeom_isfinite(const LWGEOM *lwgeom)
Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
Definition: lwgeom.c:2681
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:125
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
Definition: lwline.c:364
void lwline_free(LWLINE *line)
Definition: lwline.c:67
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwinline.h:131
POINTARRAY * points
Definition: liblwgeom.h:483
POINTARRAY * point
Definition: liblwgeom.h:471
uint32_t npoints
Definition: liblwgeom.h:427

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

Here is the call graph for this function: