PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid_pointoff()

Datum LWGEOM_snaptogrid_pointoff ( PG_FUNCTION_ARGS  )

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

357 {
358  GSERIALIZED *in_geom, *in_point;
359  LWGEOM *in_lwgeom;
360  LWPOINT *in_lwpoint;
361  GSERIALIZED *out_geom = NULL;
362  LWGEOM *out_lwgeom;
363  gridspec grid;
364  /* BOX3D box3d; */
365  POINT4D offsetpoint;
366 
367  in_geom = PG_GETARG_GSERIALIZED_P(0);
368 
369  /* Return input geometry if input geometry is empty */
370  if ( gserialized_is_empty(in_geom) )
371  {
372  PG_RETURN_POINTER(in_geom);
373  }
374 
375  in_point = PG_GETARG_GSERIALIZED_P(1);
376  in_lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(in_point));
377  if ( in_lwpoint == NULL )
378  {
379  lwpgerror("Offset geometry must be a point");
380  }
381 
382  grid.xsize = PG_GETARG_FLOAT8(2);
383  grid.ysize = PG_GETARG_FLOAT8(3);
384  grid.zsize = PG_GETARG_FLOAT8(4);
385  grid.msize = PG_GETARG_FLOAT8(5);
386 
387  /* Take offsets from point geometry */
388  getPoint4d_p(in_lwpoint->point, 0, &offsetpoint);
389  grid.ipx = offsetpoint.x;
390  grid.ipy = offsetpoint.y;
391  if (FLAGS_GET_Z(in_lwpoint->flags) ) grid.ipz = offsetpoint.z;
392  else grid.ipz=0;
393  if (FLAGS_GET_M(in_lwpoint->flags) ) grid.ipm = offsetpoint.m;
394  else grid.ipm=0;
395 
396 #if POSTGIS_DEBUG_LEVEL >= 4
397  grid_print(&grid);
398 #endif
399 
400  /* Return input geometry if input grid is meaningless */
401  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
402  {
403  PG_RETURN_POINTER(in_geom);
404  }
405 
406  in_lwgeom = lwgeom_from_gserialized(in_geom);
407 
408  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
409 
410  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
411  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
412 
413  /* COMPUTE_BBOX TAINTING */
414  if ( in_lwgeom->bbox ) lwgeom_add_bbox(out_lwgeom);
415 
416  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
417 
418  out_geom = geometry_serialize(out_lwgeom);
419 
420  PG_RETURN_POINTER(out_geom);
421 }
double x
Definition: liblwgeom.h:336
GBOX * bbox
Definition: liblwgeom.h:382
double m
Definition: liblwgeom.h:336
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:1868
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
POINTARRAY * point
Definition: liblwgeom.h:395
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:139
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
double z
Definition: liblwgeom.h:336
uint8_t flags
Definition: liblwgeom.h:392
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:125
uint8_t type
Definition: liblwgeom.h:380
double y
Definition: liblwgeom.h:336
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231
Snap to grid.
Here is the call graph for this function:
Here is the caller graph for this function: