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

Definition at line 2253 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, LWLINE::points, and result.

2254 {
2255  GSERIALIZED *pglwg1, *result;
2256  LWLINE *line, *outline;
2257  uint32 which;
2258 
2259  POSTGIS_DEBUG(2, "LWGEOM_removepoint called.");
2260 
2261  pglwg1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2262  which = PG_GETARG_INT32(1);
2263 
2264  if ( gserialized_get_type(pglwg1) != LINETYPE )
2265  {
2266  elog(ERROR, "First argument must be a LINESTRING");
2267  PG_RETURN_NULL();
2268  }
2269 
2270  line = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
2271 
2272  if ( which > line->points->npoints-1 )
2273  {
2274  elog(ERROR, "Point index out of range (%d..%d)", 0, line->points->npoints-1);
2275  PG_RETURN_NULL();
2276  }
2277 
2278  if ( line->points->npoints < 3 )
2279  {
2280  elog(ERROR, "Can't remove points from a single segment line");
2281  PG_RETURN_NULL();
2282  }
2283 
2284  outline = lwline_removepoint(line, which);
2285  /* Release memory */
2286  lwline_free(line);
2287 
2288  result = geometry_serialize((LWGEOM *)outline);
2289  lwline_free(outline);
2290 
2291  PG_FREE_IF_COPY(pglwg1, 0);
2292  PG_RETURN_POINTER(result);
2293 }
#define LINETYPE
Definition: liblwgeom.h:61
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:56
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:327
void lwline_free(LWLINE *line)
Definition: lwline.c:63
char ** result
Definition: liblwgeom.h:218
unsigned int uint32
Definition: shpopen.c:274
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:333
POINTARRAY * points
Definition: liblwgeom.h:378

Here is the call graph for this function: