PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid_pointoff()

Datum LWGEOM_snaptogrid_pointoff ( PG_FUNCTION_ARGS  )

Definition at line 383 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_drop_bbox(), 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().

384 {
385  GSERIALIZED *in_geom, *in_point;
386  LWGEOM *in_lwgeom;
387  LWPOINT *in_lwpoint;
388  GSERIALIZED *out_geom = NULL;
389  LWGEOM *out_lwgeom;
390  gridspec grid;
391  /* BOX3D box3d; */
392  POINT4D offsetpoint;
393 
394  in_geom = PG_GETARG_GSERIALIZED_P(0);
395 
396  /* Return input geometry if input geometry is empty */
397  if ( gserialized_is_empty(in_geom) )
398  {
399  PG_RETURN_POINTER(in_geom);
400  }
401 
402  in_point = PG_GETARG_GSERIALIZED_P(1);
403  in_lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(in_point));
404  if ( in_lwpoint == NULL )
405  {
406  lwpgerror("Offset geometry must be a point");
407  }
408 
409  grid.xsize = PG_GETARG_FLOAT8(2);
410  grid.ysize = PG_GETARG_FLOAT8(3);
411  grid.zsize = PG_GETARG_FLOAT8(4);
412  grid.msize = PG_GETARG_FLOAT8(5);
413 
414  /* Take offsets from point geometry */
415  getPoint4d_p(in_lwpoint->point, 0, &offsetpoint);
416  grid.ipx = offsetpoint.x;
417  grid.ipy = offsetpoint.y;
418  if (FLAGS_GET_Z(in_lwpoint->flags) ) grid.ipz = offsetpoint.z;
419  else grid.ipz=0;
420  if (FLAGS_GET_M(in_lwpoint->flags) ) grid.ipm = offsetpoint.m;
421  else grid.ipm=0;
422 
423 #if POSTGIS_DEBUG_LEVEL >= 4
424  grid_print(&grid);
425 #endif
426 
427  /* Return input geometry if input grid is meaningless */
428  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
429  {
430  PG_RETURN_POINTER(in_geom);
431  }
432 
433  in_lwgeom = lwgeom_from_gserialized(in_geom);
434 
435  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
436 
437  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
438  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
439 
440  /* COMPUTE_BBOX TAINTING */
441  if (in_lwgeom->bbox)
442  {
443  lwgeom_drop_bbox(out_lwgeom);
444  lwgeom_add_bbox(out_lwgeom);
445  }
446 
447  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
448 
449  out_geom = geometry_serialize(out_lwgeom);
450 
451  PG_RETURN_POINTER(out_geom);
452 }
double x
Definition: liblwgeom.h:352
GBOX * bbox
Definition: liblwgeom.h:398
double m
Definition: liblwgeom.h:352
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:1912
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:129
POINTARRAY * point
Definition: liblwgeom.h:411
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:635
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
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:140
double z
Definition: liblwgeom.h:352
uint8_t flags
Definition: liblwgeom.h:408
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:648
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
uint8_t type
Definition: liblwgeom.h:396
double y
Definition: liblwgeom.h:352
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
Snap to grid.
Here is the call graph for this function:
Here is the caller graph for this function: