PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_snaptogrid_pointoff()

Datum LWGEOM_snaptogrid_pointoff ( PG_FUNCTION_ARGS  )

Definition at line 393 of file lwgeom_functions_analytic.c.

394 {
395  GSERIALIZED *in_geom, *in_point;
396  LWGEOM *in_lwgeom;
397  LWPOINT *in_lwpoint;
398  GSERIALIZED *out_geom = NULL;
399  LWGEOM *out_lwgeom;
400  gridspec grid;
401  /* BOX3D box3d; */
402  POINT4D offsetpoint;
403 
404  in_geom = PG_GETARG_GSERIALIZED_P(0);
405 
406  /* Return input geometry if input geometry is empty */
407  if ( gserialized_is_empty(in_geom) )
408  {
409  PG_RETURN_POINTER(in_geom);
410  }
411 
412  in_point = PG_GETARG_GSERIALIZED_P(1);
413  in_lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(in_point));
414  if ( in_lwpoint == NULL )
415  {
416  lwpgerror("Offset geometry must be a point");
417  }
418 
419  grid.xsize = PG_GETARG_FLOAT8(2);
420  grid.ysize = PG_GETARG_FLOAT8(3);
421  grid.zsize = PG_GETARG_FLOAT8(4);
422  grid.msize = PG_GETARG_FLOAT8(5);
423 
424  /* Take offsets from point geometry */
425  getPoint4d_p(in_lwpoint->point, 0, &offsetpoint);
426  grid.ipx = offsetpoint.x;
427  grid.ipy = offsetpoint.y;
428  grid.ipz = lwgeom_has_z((LWGEOM*)in_lwpoint) ? offsetpoint.z : 0;
429  grid.ipm = lwgeom_has_m((LWGEOM*)in_lwpoint) ? offsetpoint.m : 0;
430 
431 #if POSTGIS_DEBUG_LEVEL >= 4
432  grid_print(&grid);
433 #endif
434 
435  /* Return input geometry if input grid is meaningless */
436  if ( grid.xsize==0 && grid.ysize==0 && grid.zsize==0 && grid.msize==0 )
437  {
438  PG_RETURN_POINTER(in_geom);
439  }
440 
441  in_lwgeom = lwgeom_from_gserialized(in_geom);
442 
443  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
444 
445  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
446  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
447 
448  /* COMPUTE_BBOX TAINTING */
449  if (in_lwgeom->bbox)
450  {
451  lwgeom_refresh_bbox(out_lwgeom);
452  }
453 
454  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
455 
456  out_geom = geometry_serialize(out_lwgeom);
457 
458  PG_RETURN_POINTER(out_geom);
459 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:181
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:707
LWGEOM * lwgeom_grid(const LWGEOM *lwgeom, gridspec *grid)
Definition: lwgeom.c:2393
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:934
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:941
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwinline.h:127
uint8_t type
Definition: liblwgeom.h:462
GBOX * bbox
Definition: liblwgeom.h:458
POINTARRAY * point
Definition: liblwgeom.h:471
double m
Definition: liblwgeom.h:414
double x
Definition: liblwgeom.h:414
double z
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414
double ipm
Definition: liblwgeom.h:1402
double zsize
Definition: liblwgeom.h:1405
double ysize
Definition: liblwgeom.h:1404
double xsize
Definition: liblwgeom.h:1403
double ipx
Definition: liblwgeom.h:1399
double msize
Definition: liblwgeom.h:1406
double ipy
Definition: liblwgeom.h:1400
double ipz
Definition: liblwgeom.h:1401
Snap-to-grid.
Definition: liblwgeom.h:1398

References LWGEOM::bbox, 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: