PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ LWGEOM_snaptogrid()

Datum LWGEOM_snaptogrid ( PG_FUNCTION_ARGS  )

Definition at line 332 of file lwgeom_functions_analytic.c.

333{
334 LWGEOM *in_lwgeom;
335 GSERIALIZED *out_geom = NULL;
336 LWGEOM *out_lwgeom;
337 gridspec grid;
338
339 GSERIALIZED *in_geom = PG_GETARG_GSERIALIZED_P(0);
340
341 /* Set grid values to zero to start */
342 memset(&grid, 0, sizeof(gridspec));
343
344 grid.ipx = PG_GETARG_FLOAT8(1);
345 grid.ipy = PG_GETARG_FLOAT8(2);
346 grid.xsize = PG_GETARG_FLOAT8(3);
347 grid.ysize = PG_GETARG_FLOAT8(4);
348
349 /* Return input geometry if input geometry is empty */
350 if ( gserialized_is_empty(in_geom) )
351 {
352 PG_RETURN_POINTER(in_geom);
353 }
354
355 /* Return input geometry if input grid is meaningless */
356 if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
357 {
358 PG_RETURN_POINTER(in_geom);
359 }
360
361 in_lwgeom = lwgeom_from_gserialized(in_geom);
362
363 POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
364
365 out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
366 if ( out_lwgeom == NULL ) PG_RETURN_NULL();
367
368 /* COMPUTE_BBOX TAINTING */
369 if ( in_lwgeom->bbox )
370 lwgeom_refresh_bbox(out_lwgeom);
371
372 POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
373
374 out_geom = geometry_serialize(out_lwgeom);
375
376 PG_RETURN_POINTER(out_geom);
377}
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.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition lwgeom.c:735
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, gridspec *grid)
Definition lwgeom.c:2421
uint8_t type
Definition liblwgeom.h:462
GBOX * bbox
Definition liblwgeom.h:458
double zsize
Definition liblwgeom.h:1407
double ysize
Definition liblwgeom.h:1406
double xsize
Definition liblwgeom.h:1405
double ipx
Definition liblwgeom.h:1401
double msize
Definition liblwgeom.h:1408
double ipy
Definition liblwgeom.h:1402
Snap-to-grid.
Definition liblwgeom.h:1400

References LWGEOM::bbox, 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: