PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ LWGEOM_removepoint()

Datum LWGEOM_removepoint ( PG_FUNCTION_ARGS  )

Definition at line 2188 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().

2189 {
2190  GSERIALIZED *pglwg1, *result;
2191  LWLINE *line, *outline;
2192  uint32 which;
2193 
2194  POSTGIS_DEBUG(2, "LWGEOM_removepoint called.");
2195 
2196  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
2197  which = PG_GETARG_INT32(1);
2198 
2199  if ( gserialized_get_type(pglwg1) != LINETYPE )
2200  {
2201  elog(ERROR, "First argument must be a LINESTRING");
2202  PG_RETURN_NULL();
2203  }
2204 
2205  line = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
2206 
2207  if ( which > line->points->npoints-1 )
2208  {
2209  elog(ERROR, "Point index out of range (%d..%d)", 0, line->points->npoints-1);
2210  PG_RETURN_NULL();
2211  }
2212 
2213  if ( line->points->npoints < 3 )
2214  {
2215  elog(ERROR, "Can't remove points from a single segment line");
2216  PG_RETURN_NULL();
2217  }
2218 
2219  outline = lwline_removepoint(line, which);
2220  /* Release memory */
2221  lwline_free(line);
2222 
2223  result = geometry_serialize((LWGEOM *)outline);
2224  lwline_free(outline);
2225 
2226  PG_FREE_IF_COPY(pglwg1, 0);
2227  PG_RETURN_POINTER(result);
2228 }
#define LINETYPE
Definition: liblwgeom.h:71
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:55
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:355
void lwline_free(LWLINE *line)
Definition: lwline.c:63
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:334
POINTARRAY * points
Definition: liblwgeom.h:406
Here is the call graph for this function:
Here is the caller graph for this function: