PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid()

Datum LWGEOM_snaptogrid ( PG_FUNCTION_ARGS  )

Definition at line 338 of file lwgeom_functions_analytic.c.

339 {
340  LWGEOM *in_lwgeom;
341  GSERIALIZED *out_geom = NULL;
342  LWGEOM *out_lwgeom;
343  gridspec grid;
344 
345  GSERIALIZED *in_geom = PG_GETARG_GSERIALIZED_P(0);
346 
347  /* Set grid values to zero to start */
348  memset(&grid, 0, sizeof(gridspec));
349 
350  grid.ipx = PG_GETARG_FLOAT8(1);
351  grid.ipy = PG_GETARG_FLOAT8(2);
352  grid.xsize = PG_GETARG_FLOAT8(3);
353  grid.ysize = PG_GETARG_FLOAT8(4);
354 
355  /* Return input geometry if input geometry is empty */
356  if ( gserialized_is_empty(in_geom) )
357  {
358  PG_RETURN_POINTER(in_geom);
359  }
360 
361  /* Return input geometry if input grid is meaningless */
362  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
363  {
364  PG_RETURN_POINTER(in_geom);
365  }
366 
367  in_lwgeom = lwgeom_from_gserialized(in_geom);
368 
369  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
370 
371  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
372  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
373 
374  /* COMPUTE_BBOX TAINTING */
375  if ( in_lwgeom->bbox )
376  lwgeom_refresh_bbox(out_lwgeom);
377 
378  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
379 
380  out_geom = geometry_serialize(out_lwgeom);
381 
382  PG_RETURN_POINTER(out_geom);
383 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:689
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2245
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:448
GBOX * bbox
Definition: liblwgeom.h:444
double zsize
Definition: liblwgeom.h:1348
double ysize
Definition: liblwgeom.h:1347
double xsize
Definition: liblwgeom.h:1346
double ipx
Definition: liblwgeom.h:1342
double msize
Definition: liblwgeom.h:1349
double ipy
Definition: liblwgeom.h:1343
Snap-to-grid.
Definition: liblwgeom.h:1341

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: