PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid()

Datum LWGEOM_snaptogrid ( PG_FUNCTION_ARGS  )

Definition at line 296 of file lwgeom_functions_analytic.c.

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

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

Here is the call graph for this function: