PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_removepoint()

Datum LWGEOM_removepoint ( PG_FUNCTION_ARGS  )

Definition at line 2233 of file lwgeom_functions_basic.c.

2234 {
2235  GSERIALIZED *pglwg1, *result;
2236  LWLINE *line, *outline;
2237  uint32 which;
2238 
2239  POSTGIS_DEBUG(2, "LWGEOM_removepoint called.");
2240 
2241  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
2242  which = PG_GETARG_INT32(1);
2243 
2244  if ( gserialized_get_type(pglwg1) != LINETYPE )
2245  {
2246  elog(ERROR, "First argument must be a LINESTRING");
2247  PG_RETURN_NULL();
2248  }
2249 
2250  line = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
2251 
2252  if ( which > line->points->npoints-1 )
2253  {
2254  elog(ERROR, "Point index out of range (%d..%d)", 0, line->points->npoints-1);
2255  PG_RETURN_NULL();
2256  }
2257 
2258  if ( line->points->npoints < 3 )
2259  {
2260  elog(ERROR, "Can't remove points from a single segment line");
2261  PG_RETURN_NULL();
2262  }
2263 
2264  outline = lwline_removepoint(line, which);
2265  /* Release memory */
2266  lwline_free(line);
2267 
2268  result = geometry_serialize((LWGEOM *)outline);
2270 
2271  PG_FREE_IF_COPY(pglwg1, 0);
2272  PG_RETURN_POINTER(result);
2273 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: g_serialized.c:86
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
#define LINETYPE
Definition: liblwgeom.h:86
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:356
void lwline_free(LWLINE *line)
Definition: lwline.c:76
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
POINTARRAY * points
Definition: liblwgeom.h:425
uint32_t npoints
Definition: liblwgeom.h:374

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: