PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ LWGEOM_removepoint()

Datum LWGEOM_removepoint ( PG_FUNCTION_ARGS  )

Definition at line 2228 of file lwgeom_functions_basic.c.

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

Referenced by LWGEOM_addpoint().

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