PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_removepoint()

Datum LWGEOM_removepoint ( PG_FUNCTION_ARGS  )

Definition at line 2249 of file lwgeom_functions_basic.c.

2250 {
2251  GSERIALIZED *pglwg1, *result;
2252  LWLINE *line, *outline;
2253  int32 which;
2254 
2255  POSTGIS_DEBUG(2, "LWGEOM_removepoint called.");
2256 
2257  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
2258  which = PG_GETARG_INT32(1);
2259 
2260  if (gserialized_get_type(pglwg1) != LINETYPE)
2261  {
2262  elog(ERROR, "First argument must be a LINESTRING");
2263  PG_RETURN_NULL();
2264  }
2265 
2266  line = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
2267 
2268  if (which < 0 || (uint32_t)which > line->points->npoints - 1)
2269  {
2270  elog(ERROR, "Point index out of range (%u..%u)", 0, line->points->npoints - 1);
2271  PG_RETURN_NULL();
2272  }
2273 
2274  if (line->points->npoints < 3)
2275  {
2276  elog(ERROR, "Can't remove points from a single segment line");
2277  PG_RETURN_NULL();
2278  }
2279 
2280  outline = lwline_removepoint(line, (uint32_t)which);
2281  /* Release memory */
2282  lwline_free(line);
2283 
2284  result = geometry_serialize((LWGEOM *)outline);
2286 
2287  PG_FREE_IF_COPY(pglwg1, 0);
2288  PG_RETURN_POINTER(result);
2289 }
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:161
#define LINETYPE
Definition: liblwgeom.h:117
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:347
void lwline_free(LWLINE *line)
Definition: lwline.c:67
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
unsigned int int32
Definition: shpopen.c:273
POINTARRAY * points
Definition: liblwgeom.h:469
uint32_t npoints
Definition: liblwgeom.h:413

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

Here is the call graph for this function: