PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum LWGEOM_snaptogrid ( PG_FUNCTION_ARGS  )

Definition at line 294 of file lwgeom_functions_analytic.c.

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

295 {
296  LWGEOM *in_lwgeom;
297  GSERIALIZED *out_geom = NULL;
298  LWGEOM *out_lwgeom;
299  gridspec grid;
300 
301  GSERIALIZED *in_geom = PG_GETARG_GSERIALIZED_P(0);
302 
303  /* Set grid values to zero to start */
304  memset(&grid, 0, sizeof(gridspec));
305 
306  grid.ipx = PG_GETARG_FLOAT8(1);
307  grid.ipy = PG_GETARG_FLOAT8(2);
308  grid.xsize = PG_GETARG_FLOAT8(3);
309  grid.ysize = PG_GETARG_FLOAT8(4);
310 
311  /* Return input geometry if input geometry is empty */
312  if ( gserialized_is_empty(in_geom) )
313  {
314  PG_RETURN_POINTER(in_geom);
315  }
316 
317  /* Return input geometry if input grid is meaningless */
318  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
319  {
320  PG_RETURN_POINTER(in_geom);
321  }
322 
323  in_lwgeom = lwgeom_from_gserialized(in_geom);
324 
325  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
326 
327  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
328  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
329 
330  /* COMPUTE_BBOX TAINTING */
331  if ( in_lwgeom->bbox )
332  lwgeom_add_bbox(out_lwgeom);
333 
334 
335  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
336 
337  out_geom = geometry_serialize(out_lwgeom);
338 
339  PG_RETURN_POINTER(out_geom);
340 }
GBOX * bbox
Definition: liblwgeom.h:382
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:1868
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:139
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
uint8_t type
Definition: liblwgeom.h:380
Snap to grid.

Here is the call graph for this function: