PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid_pointoff()

Datum LWGEOM_snaptogrid_pointoff ( PG_FUNCTION_ARGS  )

Definition at line 357 of file lwgeom_functions_analytic.c.

358 {
359  GSERIALIZED *in_geom, *in_point;
360  LWGEOM *in_lwgeom;
361  LWPOINT *in_lwpoint;
362  GSERIALIZED *out_geom = NULL;
363  LWGEOM *out_lwgeom;
364  gridspec grid;
365  /* BOX3D box3d; */
366  POINT4D offsetpoint;
367 
368  in_geom = PG_GETARG_GSERIALIZED_P(0);
369 
370  /* Return input geometry if input geometry is empty */
371  if ( gserialized_is_empty(in_geom) )
372  {
373  PG_RETURN_POINTER(in_geom);
374  }
375 
376  in_point = PG_GETARG_GSERIALIZED_P(1);
377  in_lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(in_point));
378  if ( in_lwpoint == NULL )
379  {
380  lwpgerror("Offset geometry must be a point");
381  }
382 
383  grid.xsize = PG_GETARG_FLOAT8(2);
384  grid.ysize = PG_GETARG_FLOAT8(3);
385  grid.zsize = PG_GETARG_FLOAT8(4);
386  grid.msize = PG_GETARG_FLOAT8(5);
387 
388  /* Take offsets from point geometry */
389  getPoint4d_p(in_lwpoint->point, 0, &offsetpoint);
390  grid.ipx = offsetpoint.x;
391  grid.ipy = offsetpoint.y;
392  if (FLAGS_GET_Z(in_lwpoint->flags) ) grid.ipz = offsetpoint.z;
393  else grid.ipz=0;
394  if (FLAGS_GET_M(in_lwpoint->flags) ) grid.ipm = offsetpoint.m;
395  else grid.ipm=0;
396 
397 #if POSTGIS_DEBUG_LEVEL >= 4
398  grid_print(&grid);
399 #endif
400 
401  /* Return input geometry if input grid is meaningless */
402  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
403  {
404  PG_RETURN_POINTER(in_geom);
405  }
406 
407  in_lwgeom = lwgeom_from_gserialized(in_geom);
408 
409  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
410 
411  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
412  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
413 
414  /* COMPUTE_BBOX TAINTING */
415  if (in_lwgeom->bbox)
416  {
417  lwgeom_refresh_bbox(out_lwgeom);
418  }
419 
420  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
421 
422  out_geom = geometry_serialize(out_lwgeom);
423 
424  PG_RETURN_POINTER(out_geom);
425 }
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
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:123
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
POINTARRAY * point
Definition: liblwgeom.h:414
uint8_t flags
Definition: liblwgeom.h:411
double m
Definition: liblwgeom.h:355
double x
Definition: liblwgeom.h:355
double z
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355
Snap to grid.

References LWGEOM::bbox, LWPOINT::flags, FLAGS_GET_M, FLAGS_GET_Z, geometry_serialize(), getPoint4d_p(), gserialized_is_empty(), gridspec_t::ipm, gridspec_t::ipx, gridspec_t::ipy, gridspec_t::ipz, lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwgeom_grid(), lwgeom_refresh_bbox(), lwtype_name(), POINT4D::m, gridspec_t::msize, LWPOINT::point, LWGEOM::type, POINT4D::x, gridspec_t::xsize, POINT4D::y, gridspec_t::ysize, POINT4D::z, and gridspec_t::zsize.

Here is the call graph for this function: