PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid_pointoff()

Datum LWGEOM_snaptogrid_pointoff ( PG_FUNCTION_ARGS  )

Definition at line 378 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().

379 {
380  GSERIALIZED *in_geom, *in_point;
381  LWGEOM *in_lwgeom;
382  LWPOINT *in_lwpoint;
383  GSERIALIZED *out_geom = NULL;
384  LWGEOM *out_lwgeom;
385  gridspec grid;
386  /* BOX3D box3d; */
387  POINT4D offsetpoint;
388 
389  in_geom = PG_GETARG_GSERIALIZED_P(0);
390 
391  /* Return input geometry if input geometry is empty */
392  if ( gserialized_is_empty(in_geom) )
393  {
394  PG_RETURN_POINTER(in_geom);
395  }
396 
397  in_point = PG_GETARG_GSERIALIZED_P(1);
398  in_lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(in_point));
399  if ( in_lwpoint == NULL )
400  {
401  lwpgerror("Offset geometry must be a point");
402  }
403 
404  grid.xsize = PG_GETARG_FLOAT8(2);
405  grid.ysize = PG_GETARG_FLOAT8(3);
406  grid.zsize = PG_GETARG_FLOAT8(4);
407  grid.msize = PG_GETARG_FLOAT8(5);
408 
409  /* Take offsets from point geometry */
410  getPoint4d_p(in_lwpoint->point, 0, &offsetpoint);
411  grid.ipx = offsetpoint.x;
412  grid.ipy = offsetpoint.y;
413  if (FLAGS_GET_Z(in_lwpoint->flags) ) grid.ipz = offsetpoint.z;
414  else grid.ipz=0;
415  if (FLAGS_GET_M(in_lwpoint->flags) ) grid.ipm = offsetpoint.m;
416  else grid.ipm=0;
417 
418 #if POSTGIS_DEBUG_LEVEL >= 4
419  grid_print(&grid);
420 #endif
421 
422  /* Return input geometry if input grid is meaningless */
423  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
424  {
425  PG_RETURN_POINTER(in_geom);
426  }
427 
428  in_lwgeom = lwgeom_from_gserialized(in_geom);
429 
430  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
431 
432  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
433  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
434 
435  /* COMPUTE_BBOX TAINTING */
436  if ( in_lwgeom->bbox ) lwgeom_add_bbox(out_lwgeom);
437 
438  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
439 
440  out_geom = geometry_serialize(out_lwgeom);
441 
442  PG_RETURN_POINTER(out_geom);
443 }
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:1881
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:93
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:153
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
double z
Definition: liblwgeom.h:351
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:612
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
uint8_t type
Definition: liblwgeom.h:395
double y
Definition: liblwgeom.h:351
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:244
Snap to grid.
Here is the call graph for this function:
Here is the caller graph for this function: