PostGIS  2.3.7dev-r@@SVN_REVISION@@
Datum LWGEOM_removepoint ( PG_FUNCTION_ARGS  )

Definition at line 2248 of file lwgeom_functions_basic.c.

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

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

Here is the call graph for this function: