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

Definition at line 2225 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.

2226 {
2227  GSERIALIZED *pglwg1, *result;
2228  LWLINE *line, *outline;
2229  uint32 which;
2230 
2231  POSTGIS_DEBUG(2, "LWGEOM_removepoint called.");
2232 
2233  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
2234  which = PG_GETARG_INT32(1);
2235 
2236  if ( gserialized_get_type(pglwg1) != LINETYPE )
2237  {
2238  elog(ERROR, "First argument must be a LINESTRING");
2239  PG_RETURN_NULL();
2240  }
2241 
2242  line = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
2243 
2244  if ( which > line->points->npoints-1 )
2245  {
2246  elog(ERROR, "Point index out of range (%d..%d)", 0, line->points->npoints-1);
2247  PG_RETURN_NULL();
2248  }
2249 
2250  if ( line->points->npoints < 3 )
2251  {
2252  elog(ERROR, "Can't remove points from a single segment line");
2253  PG_RETURN_NULL();
2254  }
2255 
2256  outline = lwline_removepoint(line, which);
2257  /* Release memory */
2258  lwline_free(line);
2259 
2260  result = geometry_serialize((LWGEOM *)outline);
2261  lwline_free(outline);
2262 
2263  PG_FREE_IF_COPY(pglwg1, 0);
2264  PG_RETURN_POINTER(result);
2265 }
#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:86
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwline_free(LWLINE *line)
Definition: lwline.c:76
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:169
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:356
POINTARRAY * points
Definition: liblwgeom.h:421
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function: