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

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

254 {
255  LWGEOM *in_lwgeom;
256  GSERIALIZED *out_geom = NULL;
257  LWGEOM *out_lwgeom;
258  gridspec grid;
259 
260  GSERIALIZED *in_geom = PG_GETARG_GSERIALIZED_P(0);
261 
262  /* Set grid values to zero to start */
263  memset(&grid, 0, sizeof(gridspec));
264 
265  grid.ipx = PG_GETARG_FLOAT8(1);
266  grid.ipy = PG_GETARG_FLOAT8(2);
267  grid.xsize = PG_GETARG_FLOAT8(3);
268  grid.ysize = PG_GETARG_FLOAT8(4);
269 
270  /* Return input geometry if input geometry is empty */
271  if ( gserialized_is_empty(in_geom) )
272  {
273  PG_RETURN_POINTER(in_geom);
274  }
275 
276  /* Return input geometry if input grid is meaningless */
277  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
278  {
279  PG_RETURN_POINTER(in_geom);
280  }
281 
282  in_lwgeom = lwgeom_from_gserialized(in_geom);
283 
284  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
285 
286  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
287  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
288 
289  /* COMPUTE_BBOX TAINTING */
290  if ( in_lwgeom->bbox )
291  lwgeom_add_bbox(out_lwgeom);
292 
293 
294  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
295 
296  out_geom = geometry_serialize(out_lwgeom);
297 
298  PG_RETURN_POINTER(out_geom);
299 }
GBOX * bbox
Definition: liblwgeom.h:397
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2236
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:679
uint8_t type
Definition: liblwgeom.h:395
Snap to grid.

Here is the call graph for this function: