PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ ptarray_grid_in_place()

void ptarray_grid_in_place ( POINTARRAY pa,
const gridspec grid 
)

Snap to grid.

Definition at line 1986 of file ptarray.c.

1987{
1988 uint32_t i, j = 0;
1989 POINT4D *p, *p_out = NULL;
1990 int ndims = FLAGS_NDIMS(pa->flags);
1991 int has_z = FLAGS_GET_Z(pa->flags);
1992 int has_m = FLAGS_GET_M(pa->flags);
1993
1994 LWDEBUGF(2, "%s called on %p", __func__, pa);
1995
1996 for (i = 0; i < pa->npoints; i++)
1997 {
1998 /* Look straight into the abyss */
1999 p = (POINT4D*)(getPoint_internal(pa, i));
2000
2001 if (grid->xsize > 0)
2002 {
2003 p->x = rint((p->x - grid->ipx)/grid->xsize) * grid->xsize + grid->ipx;
2004 }
2005
2006 if (grid->ysize > 0)
2007 {
2008 p->y = rint((p->y - grid->ipy)/grid->ysize) * grid->ysize + grid->ipy;
2009 }
2010
2011 /* Read and round this point */
2012 /* Z is always in third position */
2013 if (has_z)
2014 {
2015 if (grid->zsize > 0)
2016 p->z = rint((p->z - grid->ipz)/grid->zsize) * grid->zsize + grid->ipz;
2017 }
2018 /* M might be in 3rd or 4th position */
2019 if (has_m)
2020 {
2021 /* In POINT M, M is in 3rd position */
2022 if (grid->msize > 0 && !has_z)
2023 p->z = rint((p->z - grid->ipm)/grid->msize) * grid->msize + grid->ipm;
2024 /* In POINT ZM, M is in 4th position */
2025 if (grid->msize > 0 && has_z)
2026 p->m = rint((p->m - grid->ipm)/grid->msize) * grid->msize + grid->ipm;
2027 }
2028
2029 /* Skip duplicates */
2030 if ( p_out && FP_EQUALS(p_out->x, p->x) && FP_EQUALS(p_out->y, p->y)
2031 && (ndims > 2 ? FP_EQUALS(p_out->z, p->z) : 1)
2032 && (ndims > 3 ? FP_EQUALS(p_out->m, p->m) : 1) )
2033 {
2034 continue;
2035 }
2036
2037 /* Write rounded values into the next available point */
2038 p_out = (POINT4D*)(getPoint_internal(pa, j++));
2039 p_out->x = p->x;
2040 p_out->y = p->y;
2041 if (ndims > 2)
2042 p_out->z = p->z;
2043 if (ndims > 3)
2044 p_out->m = p->m;
2045 }
2046
2047 /* Update output ptarray length */
2048 pa->npoints = j;
2049 return;
2050}
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:179
#define FLAGS_NDIMS(flags)
Definition liblwgeom.h:193
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:180
#define FP_EQUALS(A, B)
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:88
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition lwinline.h:67
double m
Definition liblwgeom.h:400
double x
Definition liblwgeom.h:400
double z
Definition liblwgeom.h:400
double y
Definition liblwgeom.h:400
lwflags_t flags
Definition liblwgeom.h:417
uint32_t npoints
Definition liblwgeom.h:413
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

References POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, FLAGS_NDIMS, FP_EQUALS, getPoint_internal(), gridspec_t::ipm, gridspec_t::ipx, gridspec_t::ipy, gridspec_t::ipz, LWDEBUGF, POINT4D::m, gridspec_t::msize, POINTARRAY::npoints, POINT4D::x, gridspec_t::xsize, POINT4D::y, gridspec_t::ysize, POINT4D::z, and gridspec_t::zsize.

Referenced by lwgeom_grid_in_place().

Here is the call graph for this function:
Here is the caller graph for this function: