PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ LWGEOM_removepoint()

Datum LWGEOM_removepoint ( PG_FUNCTION_ARGS  )

Definition at line 2376 of file lwgeom_functions_basic.c.

2377 {
2378  GSERIALIZED *pglwg1, *result;
2379  LWLINE *line, *outline;
2380  int32 which;
2381 
2382  POSTGIS_DEBUG(2, "LWGEOM_removepoint called.");
2383 
2384  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
2385  which = PG_GETARG_INT32(1);
2386 
2387  if (gserialized_get_type(pglwg1) != LINETYPE)
2388  {
2389  elog(ERROR, "First argument must be a LINESTRING");
2390  PG_RETURN_NULL();
2391  }
2392 
2393  line = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
2394 
2395  if (which < 0 || (uint32_t)which > line->points->npoints - 1)
2396  {
2397  elog(ERROR, "Point index out of range (%u..%u)", 0, line->points->npoints - 1);
2398  PG_RETURN_NULL();
2399  }
2400 
2401  if (line->points->npoints < 3)
2402  {
2403  elog(ERROR, "Can't remove points from a single segment line");
2404  PG_RETURN_NULL();
2405  }
2406 
2407  outline = lwline_removepoint(line, (uint32_t)which);
2408  /* Release memory */
2409  lwline_free(line);
2410 
2411  result = geometry_serialize((LWGEOM *)outline);
2413 
2414  PG_FREE_IF_COPY(pglwg1, 0);
2415  PG_RETURN_POINTER(result);
2416 }
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
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
#define LINETYPE
Definition: liblwgeom.h:103
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:347
void lwline_free(LWLINE *line)
Definition: lwline.c:67
unsigned int int32
Definition: shpopen.c:54
POINTARRAY * points
Definition: liblwgeom.h:483
uint32_t npoints
Definition: liblwgeom.h:427

References gserialized_get_type(), LINETYPE, lwgeom_as_lwline(), lwgeom_from_gserialized(), lwline_free(), lwline_removepoint(), POINTARRAY::npoints, genraster::outline, LWLINE::points, and result.

Here is the call graph for this function: