PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid()

Datum LWGEOM_snaptogrid ( PG_FUNCTION_ARGS  )

Definition at line 319 of file lwgeom_functions_analytic.c.

References LWGEOM::bbox, geometry_serialize(), gserialized_is_empty(), gridspec_t::ipm, gridspec_t::ipx, gridspec_t::ipy, gridspec_t::ipz, lwgeom_add_bbox(), lwgeom_drop_bbox(), lwgeom_from_gserialized(), lwgeom_grid(), LWGEOM_snaptogrid_pointoff(), lwtype_name(), gridspec_t::msize, PG_FUNCTION_INFO_V1(), LWGEOM::type, gridspec_t::xsize, gridspec_t::ysize, and gridspec_t::zsize.

320 {
321  LWGEOM *in_lwgeom;
322  GSERIALIZED *out_geom = NULL;
323  LWGEOM *out_lwgeom;
324  gridspec grid;
325 
326  GSERIALIZED *in_geom = PG_GETARG_GSERIALIZED_P(0);
327 
328  /* Set grid values to zero to start */
329  memset(&grid, 0, sizeof(gridspec));
330 
331  grid.ipx = PG_GETARG_FLOAT8(1);
332  grid.ipy = PG_GETARG_FLOAT8(2);
333  grid.xsize = PG_GETARG_FLOAT8(3);
334  grid.ysize = PG_GETARG_FLOAT8(4);
335 
336  /* Return input geometry if input geometry is empty */
337  if ( gserialized_is_empty(in_geom) )
338  {
339  PG_RETURN_POINTER(in_geom);
340  }
341 
342  /* Return input geometry if input grid is meaningless */
343  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
344  {
345  PG_RETURN_POINTER(in_geom);
346  }
347 
348  in_lwgeom = lwgeom_from_gserialized(in_geom);
349 
350  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
351 
352  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
353  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
354 
355  /* COMPUTE_BBOX TAINTING */
356  if ( in_lwgeom->bbox )
357  {
358  lwgeom_drop_bbox(out_lwgeom);
359  lwgeom_add_bbox(out_lwgeom);
360  }
361 
362  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
363 
364  out_geom = geometry_serialize(out_lwgeom);
365 
366  PG_RETURN_POINTER(out_geom);
367 }
GBOX * bbox
Definition: liblwgeom.h:398
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:1912
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:635
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:648
uint8_t type
Definition: liblwgeom.h:396
Snap to grid.
Here is the call graph for this function: