PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum LWGEOM_snaptogrid_pointoff ( PG_FUNCTION_ARGS  )

Definition at line 580 of file lwgeom_functions_analytic.c.

References LWGEOM::bbox, LWPOINT::flags, FLAGS_GET_M, FLAGS_GET_Z, geometry_serialize(), getPoint4d_p(), grid_isNull(), gridspec_t::ipm, gridspec_t::ipx, gridspec_t::ipy, gridspec_t::ipz, lwerror(), lwgeom_add_bbox(), lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwgeom_grid(), 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.

581 {
582  Datum datum;
583  GSERIALIZED *in_geom, *in_point;
584  LWGEOM *in_lwgeom;
585  LWPOINT *in_lwpoint;
586  GSERIALIZED *out_geom = NULL;
587  LWGEOM *out_lwgeom;
588  gridspec grid;
589  /* BOX3D box3d; */
590  POINT4D offsetpoint;
591 
592  if ( PG_ARGISNULL(0) ) PG_RETURN_NULL();
593  datum = PG_GETARG_DATUM(0);
594  in_geom = (GSERIALIZED *)PG_DETOAST_DATUM(datum);
595 
596  if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
597  datum = PG_GETARG_DATUM(1);
598  in_point = (GSERIALIZED *)PG_DETOAST_DATUM(datum);
599  in_lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(in_point));
600  if ( in_lwpoint == NULL )
601  {
602  lwerror("Offset geometry must be a point");
603  }
604 
605  if ( PG_ARGISNULL(2) ) PG_RETURN_NULL();
606  grid.xsize = PG_GETARG_FLOAT8(2);
607 
608  if ( PG_ARGISNULL(3) ) PG_RETURN_NULL();
609  grid.ysize = PG_GETARG_FLOAT8(3);
610 
611  if ( PG_ARGISNULL(4) ) PG_RETURN_NULL();
612  grid.zsize = PG_GETARG_FLOAT8(4);
613 
614  if ( PG_ARGISNULL(5) ) PG_RETURN_NULL();
615  grid.msize = PG_GETARG_FLOAT8(5);
616 
617  /* Take offsets from point geometry */
618  getPoint4d_p(in_lwpoint->point, 0, &offsetpoint);
619  grid.ipx = offsetpoint.x;
620  grid.ipy = offsetpoint.y;
621  if (FLAGS_GET_Z(in_lwpoint->flags) ) grid.ipz = offsetpoint.z;
622  else grid.ipz=0;
623  if (FLAGS_GET_M(in_lwpoint->flags) ) grid.ipm = offsetpoint.m;
624  else grid.ipm=0;
625 
626 #if POSTGIS_DEBUG_LEVEL >= 4
627  grid_print(&grid);
628 #endif
629 
630  /* Return input geometry if grid is null */
631  if ( grid_isNull(&grid) )
632  {
633  PG_RETURN_POINTER(in_geom);
634  }
635 
636  in_lwgeom = lwgeom_from_gserialized(in_geom);
637 
638  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
639 
640  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
641  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
642 
643  /* COMPUTE_BBOX TAINTING */
644  if ( in_lwgeom->bbox ) lwgeom_add_bbox(out_lwgeom);
645 
646  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
647 
648  out_geom = geometry_serialize(out_lwgeom);
649 
650  PG_RETURN_POINTER(out_geom);
651 }
double x
Definition: liblwgeom.h:308
GBOX * bbox
Definition: liblwgeom.h:354
double m
Definition: liblwgeom.h:308
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:367
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
double z
Definition: liblwgeom.h:308
static int grid_isNull(const gridspec *grid)
uint8_t flags
Definition: liblwgeom.h:364
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwgeom_grid(LWGEOM *lwgeom, gridspec *grid)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:555
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
uint8_t type
Definition: liblwgeom.h:352
double y
Definition: liblwgeom.h:308
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:217

Here is the call graph for this function: