PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid_pointoff()

Datum LWGEOM_snaptogrid_pointoff ( PG_FUNCTION_ARGS  )

Definition at line 399 of file lwgeom_functions_analytic.c.

400 {
401  GSERIALIZED *in_geom, *in_point;
402  LWGEOM *in_lwgeom;
403  LWPOINT *in_lwpoint;
404  GSERIALIZED *out_geom = NULL;
405  LWGEOM *out_lwgeom;
406  gridspec grid;
407  /* BOX3D box3d; */
408  POINT4D offsetpoint;
409 
410  in_geom = PG_GETARG_GSERIALIZED_P(0);
411 
412  /* Return input geometry if input geometry is empty */
413  if ( gserialized_is_empty(in_geom) )
414  {
415  PG_RETURN_POINTER(in_geom);
416  }
417 
418  in_point = PG_GETARG_GSERIALIZED_P(1);
419  in_lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(in_point));
420  if ( in_lwpoint == NULL )
421  {
422  lwpgerror("Offset geometry must be a point");
423  }
424 
425  grid.xsize = PG_GETARG_FLOAT8(2);
426  grid.ysize = PG_GETARG_FLOAT8(3);
427  grid.zsize = PG_GETARG_FLOAT8(4);
428  grid.msize = PG_GETARG_FLOAT8(5);
429 
430  /* Take offsets from point geometry */
431  getPoint4d_p(in_lwpoint->point, 0, &offsetpoint);
432  grid.ipx = offsetpoint.x;
433  grid.ipy = offsetpoint.y;
434  grid.ipz = lwgeom_has_z((LWGEOM*)in_lwpoint) ? offsetpoint.z : 0;
435  grid.ipm = lwgeom_has_m((LWGEOM*)in_lwpoint) ? offsetpoint.m : 0;
436 
437 #if POSTGIS_DEBUG_LEVEL >= 4
438  grid_print(&grid);
439 #endif
440 
441  /* Return input geometry if input grid is meaningless */
442  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
443  {
444  PG_RETURN_POINTER(in_geom);
445  }
446 
447  in_lwgeom = lwgeom_from_gserialized(in_geom);
448 
449  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
450 
451  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
452  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
453 
454  /* COMPUTE_BBOX TAINTING */
455  if (in_lwgeom->bbox)
456  {
457  lwgeom_refresh_bbox(out_lwgeom);
458  }
459 
460  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
461 
462  out_geom = geometry_serialize(out_lwgeom);
463 
464  PG_RETURN_POINTER(out_geom);
465 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:689
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:916
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:125
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:923
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2245
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwinline.h:121
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:448
GBOX * bbox
Definition: liblwgeom.h:444
POINTARRAY * point
Definition: liblwgeom.h:457
double m
Definition: liblwgeom.h:400
double x
Definition: liblwgeom.h:400
double z
Definition: liblwgeom.h:400
double y
Definition: liblwgeom.h:400
double ipm
Definition: liblwgeom.h:1345
double zsize
Definition: liblwgeom.h:1348
double ysize
Definition: liblwgeom.h:1347
double xsize
Definition: liblwgeom.h:1346
double ipx
Definition: liblwgeom.h:1342
double msize
Definition: liblwgeom.h:1349
double ipy
Definition: liblwgeom.h:1343
double ipz
Definition: liblwgeom.h:1344
Snap-to-grid.
Definition: liblwgeom.h:1341

References LWGEOM::bbox, geometry_serialize(), getPoint4d_p(), gserialized_is_empty(), gridspec_t::ipm, gridspec_t::ipx, gridspec_t::ipy, gridspec_t::ipz, lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwgeom_grid(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_refresh_bbox(), 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.

Here is the call graph for this function: