PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid_pointoff()

Datum LWGEOM_snaptogrid_pointoff ( PG_FUNCTION_ARGS  )

Definition at line 357 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, PG_FUNCTION_INFO_V1(), LWPOINT::point, ST_LineCrossingDirection(), LWGEOM::type, POINT4D::x, gridspec_t::xsize, POINT4D::y, gridspec_t::ysize, POINT4D::z, and gridspec_t::zsize.

Referenced by LWGEOM_snaptogrid().

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 ) lwgeom_add_bbox(out_lwgeom);
416 
417  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
418 
419  out_geom = geometry_serialize(out_lwgeom);
420 
421  PG_RETURN_POINTER(out_geom);
422 }
double x
Definition: liblwgeom.h:354
GBOX * bbox
Definition: liblwgeom.h:400
double m
Definition: liblwgeom.h:354
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2243
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
POINTARRAY * point
Definition: liblwgeom.h:413
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:354
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:113
uint8_t flags
Definition: liblwgeom.h:410
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:686
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
uint8_t type
Definition: liblwgeom.h:398
double y
Definition: liblwgeom.h:354
Snap to grid.
Here is the call graph for this function:
Here is the caller graph for this function: