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

Definition at line 315 of file lwgeom_functions_analytic.c.

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_add_bbox(), lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwgeom_grid(), 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.

316 {
317  GSERIALIZED *in_geom, *in_point;
318  LWGEOM *in_lwgeom;
319  LWPOINT *in_lwpoint;
320  GSERIALIZED *out_geom = NULL;
321  LWGEOM *out_lwgeom;
322  gridspec grid;
323  /* BOX3D box3d; */
324  POINT4D offsetpoint;
325 
326  in_geom = PG_GETARG_GSERIALIZED_P(0);
327 
328  /* Return input geometry if input geometry is empty */
329  if ( gserialized_is_empty(in_geom) )
330  {
331  PG_RETURN_POINTER(in_geom);
332  }
333 
334  in_point = PG_GETARG_GSERIALIZED_P(1);
335  in_lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(in_point));
336  if ( in_lwpoint == NULL )
337  {
338  lwpgerror("Offset geometry must be a point");
339  }
340 
341  grid.xsize = PG_GETARG_FLOAT8(2);
342  grid.ysize = PG_GETARG_FLOAT8(3);
343  grid.zsize = PG_GETARG_FLOAT8(4);
344  grid.msize = PG_GETARG_FLOAT8(5);
345 
346  /* Take offsets from point geometry */
347  getPoint4d_p(in_lwpoint->point, 0, &offsetpoint);
348  grid.ipx = offsetpoint.x;
349  grid.ipy = offsetpoint.y;
350  if (FLAGS_GET_Z(in_lwpoint->flags) ) grid.ipz = offsetpoint.z;
351  else grid.ipz=0;
352  if (FLAGS_GET_M(in_lwpoint->flags) ) grid.ipm = offsetpoint.m;
353  else grid.ipm=0;
354 
355 #if POSTGIS_DEBUG_LEVEL >= 4
356  grid_print(&grid);
357 #endif
358 
359  /* Return input geometry if input grid is meaningless */
360  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
361  {
362  PG_RETURN_POINTER(in_geom);
363  }
364 
365  in_lwgeom = lwgeom_from_gserialized(in_geom);
366 
367  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
368 
369  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
370  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
371 
372  /* COMPUTE_BBOX TAINTING */
373  if ( in_lwgeom->bbox ) lwgeom_add_bbox(out_lwgeom);
374 
375  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
376 
377  out_geom = geometry_serialize(out_lwgeom);
378 
379  PG_RETURN_POINTER(out_geom);
380 }
double x
Definition: liblwgeom.h:351
GBOX * bbox
Definition: liblwgeom.h:397
double m
Definition: liblwgeom.h:351
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.
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:160
POINTARRAY * point
Definition: liblwgeom.h:410
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
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
double z
Definition: liblwgeom.h:351
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:113
uint8_t flags
Definition: liblwgeom.h:407
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:679
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
uint8_t type
Definition: liblwgeom.h:395
double y
Definition: liblwgeom.h:351
Snap to grid.

Here is the call graph for this function: