PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_removepoint()

Datum LWGEOM_removepoint ( PG_FUNCTION_ARGS  )

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

2218 {
2219  GSERIALIZED *pglwg1, *result;
2220  LWLINE *line, *outline;
2221  uint32 which;
2222 
2223  POSTGIS_DEBUG(2, "LWGEOM_removepoint called.");
2224 
2225  pglwg1 = PG_GETARG_GSERIALIZED_P(0);
2226  which = PG_GETARG_INT32(1);
2227 
2228  if ( gserialized_get_type(pglwg1) != LINETYPE )
2229  {
2230  elog(ERROR, "First argument must be a LINESTRING");
2231  PG_RETURN_NULL();
2232  }
2233 
2234  line = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
2235 
2236  if ( which > line->points->npoints-1 )
2237  {
2238  elog(ERROR, "Point index out of range (%d..%d)", 0, line->points->npoints-1);
2239  PG_RETURN_NULL();
2240  }
2241 
2242  if ( line->points->npoints < 3 )
2243  {
2244  elog(ERROR, "Can't remove points from a single segment line");
2245  PG_RETURN_NULL();
2246  }
2247 
2248  outline = lwline_removepoint(line, which);
2249  /* Release memory */
2250  lwline_free(line);
2251 
2252  result = geometry_serialize((LWGEOM *)outline);
2253  lwline_free(outline);
2254 
2255  PG_FREE_IF_COPY(pglwg1, 0);
2256  PG_RETURN_POINTER(result);
2257 }
#define LINETYPE
Definition: liblwgeom.h:86
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.
int npoints
Definition: liblwgeom.h:371
void lwline_free(LWLINE *line)
Definition: lwline.c:76
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWLINE * lwline_removepoint(LWLINE *line, uint32_t which)
Definition: lwline.c:363
POINTARRAY * points
Definition: liblwgeom.h:422
Here is the call graph for this function:
Here is the caller graph for this function: