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

Definition at line 526 of file lwgeom_functions_analytic.c.

References LWGEOM::bbox, geometry_serialize(), grid_isNull(), gserialized_is_empty(), gridspec_t::ipm, gridspec_t::ipx, gridspec_t::ipy, gridspec_t::ipz, lwgeom_add_bbox(), lwgeom_from_gserialized(), lwgeom_grid(), lwtype_name(), gridspec_t::msize, LWGEOM::type, gridspec_t::xsize, gridspec_t::ysize, and gridspec_t::zsize.

527 {
528  Datum datum;
529  GSERIALIZED *in_geom;
530  LWGEOM *in_lwgeom;
531  GSERIALIZED *out_geom = NULL;
532  LWGEOM *out_lwgeom;
533  gridspec grid;
534  /* BOX3D box3d; */
535 
536  if ( PG_ARGISNULL(0) ) PG_RETURN_NULL();
537  datum = PG_GETARG_DATUM(0);
538  in_geom = (GSERIALIZED *)PG_DETOAST_DATUM(datum);
539 
540  if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
541  grid.ipx = PG_GETARG_FLOAT8(1);
542 
543  if ( PG_ARGISNULL(2) ) PG_RETURN_NULL();
544  grid.ipy = PG_GETARG_FLOAT8(2);
545 
546  if ( PG_ARGISNULL(3) ) PG_RETURN_NULL();
547  grid.xsize = PG_GETARG_FLOAT8(3);
548 
549  if ( PG_ARGISNULL(4) ) PG_RETURN_NULL();
550  grid.ysize = PG_GETARG_FLOAT8(4);
551 
552  /* Do not support gridding Z and M values for now */
553  grid.ipz=grid.ipm=grid.zsize=grid.msize=0;
554 
555  /* Return input geometry if grid is null or input geometry is empty */
556  if ( grid_isNull(&grid) || gserialized_is_empty(in_geom) )
557  {
558  PG_RETURN_POINTER(in_geom);
559  }
560 
561  in_lwgeom = lwgeom_from_gserialized(in_geom);
562 
563  POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwtype_name(in_lwgeom->type));
564 
565  out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
566  if ( out_lwgeom == NULL ) PG_RETURN_NULL();
567 
568  /* COMPUTE_BBOX TAINTING */
569  if ( in_lwgeom->bbox ) lwgeom_add_bbox(out_lwgeom);
570 
571 
572  POSTGIS_DEBUGF(3, "SnapToGrid made a %s", lwtype_name(out_lwgeom->type));
573 
574  out_geom = geometry_serialize(out_lwgeom);
575 
576  PG_RETURN_POINTER(out_geom);
577 }
GBOX * bbox
Definition: liblwgeom.h:354
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
static int grid_isNull(const gridspec *grid)
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
uint8_t type
Definition: liblwgeom.h:352

Here is the call graph for this function: