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

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

317 {
318  LWGEOM *in_lwgeom;
319  GSERIALIZED *out_geom = NULL;
320  LWGEOM *out_lwgeom;
321  gridspec grid;
322 
323  GSERIALIZED *in_geom = PG_GETARG_GSERIALIZED_P(0);
324 
325  /* Set grid values to zero to start */
326  memset(&grid, 0, sizeof(gridspec));
327 
328  grid.ipx = PG_GETARG_FLOAT8(1);
329  grid.ipy = PG_GETARG_FLOAT8(2);
330  grid.xsize = PG_GETARG_FLOAT8(3);
331  grid.ysize = PG_GETARG_FLOAT8(4);
332 
333  /* Return input geometry if input geometry is empty */
334  if ( gserialized_is_empty(in_geom) )
335  {
336  PG_RETURN_POINTER(in_geom);
337  }
338 
339  /* Return input geometry if input grid is meaningless */
340  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
341  {
342  PG_RETURN_POINTER(in_geom);
343  }
344 
345  in_lwgeom = lwgeom_from_gserialized(in_geom);
346 
347  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
348 
349  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
350  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
351 
352  /* COMPUTE_BBOX TAINTING */
353  if ( in_lwgeom->bbox )
354  lwgeom_add_bbox(out_lwgeom);
355 
356 
357  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
358 
359  out_geom = geometry_serialize(out_lwgeom);
360 
361  PG_RETURN_POINTER(out_geom);
362 }
GBOX * bbox
Definition: liblwgeom.h:397
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:1881
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:153
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:612
uint8_t type
Definition: liblwgeom.h:395
Snap to grid.

Here is the call graph for this function: