PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid()

Datum LWGEOM_snaptogrid ( PG_FUNCTION_ARGS  )

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

296 {
297  LWGEOM *in_lwgeom;
298  GSERIALIZED *out_geom = NULL;
299  LWGEOM *out_lwgeom;
300  gridspec grid;
301 
302  GSERIALIZED *in_geom = PG_GETARG_GSERIALIZED_P(0);
303 
304  /* Set grid values to zero to start */
305  memset(&grid, 0, sizeof(gridspec));
306 
307  grid.ipx = PG_GETARG_FLOAT8(1);
308  grid.ipy = PG_GETARG_FLOAT8(2);
309  grid.xsize = PG_GETARG_FLOAT8(3);
310  grid.ysize = PG_GETARG_FLOAT8(4);
311 
312  /* Return input geometry if input geometry is empty */
313  if ( gserialized_is_empty(in_geom) )
314  {
315  PG_RETURN_POINTER(in_geom);
316  }
317 
318  /* Return input geometry if input grid is meaningless */
319  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
320  {
321  PG_RETURN_POINTER(in_geom);
322  }
323 
324  in_lwgeom = lwgeom_from_gserialized(in_geom);
325 
326  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
327 
328  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
329  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
330 
331  /* COMPUTE_BBOX TAINTING */
332  if ( in_lwgeom->bbox )
333  lwgeom_add_bbox(out_lwgeom);
334 
335 
336  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
337 
338  out_geom = geometry_serialize(out_lwgeom);
339 
340  PG_RETURN_POINTER(out_geom);
341 }
GBOX * bbox
Definition: liblwgeom.h:400
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2243
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
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:686
uint8_t type
Definition: liblwgeom.h:398
Snap to grid.
Here is the call graph for this function: