PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ptarray_grid_in_place()

void ptarray_grid_in_place ( POINTARRAY pa,
const gridspec grid 
)

Definition at line 2016 of file ptarray.c.

2017 {
2018  uint32_t i, j = 0;
2019  POINT4D *p, *p_out = NULL;
2020  int ndims = FLAGS_NDIMS(pa->flags);
2021  int has_z = FLAGS_GET_Z(pa->flags);
2022  int has_m = FLAGS_GET_M(pa->flags);
2023 
2024  LWDEBUGF(2, "%s called on %p", __func__, pa);
2025 
2026  for (i = 0; i < pa->npoints; i++)
2027  {
2028  /* Look straight into the abyss */
2029  p = (POINT4D*)(getPoint_internal(pa, i));
2030 
2031  if (grid->xsize > 0)
2032  {
2033  p->x = rint((p->x - grid->ipx)/grid->xsize) * grid->xsize + grid->ipx;
2034  }
2035 
2036  if (grid->ysize > 0)
2037  {
2038  p->y = rint((p->y - grid->ipy)/grid->ysize) * grid->ysize + grid->ipy;
2039  }
2040 
2041  /* Read and round this point */
2042  /* Z is always in third position */
2043  if (has_z)
2044  {
2045  if (grid->zsize > 0)
2046  p->z = rint((p->z - grid->ipz)/grid->zsize) * grid->zsize + grid->ipz;
2047  }
2048  /* M might be in 3rd or 4th position */
2049  if (has_m)
2050  {
2051  /* In POINT M, M is in 3rd position */
2052  if (grid->msize > 0 && !has_z)
2053  p->z = rint((p->z - grid->ipm)/grid->msize) * grid->msize + grid->ipm;
2054  /* In POINT ZM, M is in 4th position */
2055  if (grid->msize > 0 && has_z)
2056  p->m = rint((p->m - grid->ipm)/grid->msize) * grid->msize + grid->ipm;
2057  }
2058 
2059  /* Skip duplicates */
2060  if ( p_out && FP_EQUALS(p_out->x, p->x) && FP_EQUALS(p_out->y, p->y)
2061  && (ndims > 2 ? FP_EQUALS(p_out->z, p->z) : 1)
2062  && (ndims > 3 ? FP_EQUALS(p_out->m, p->m) : 1) )
2063  {
2064  continue;
2065  }
2066 
2067  /* Write rounded values into the next available point */
2068  p_out = (POINT4D*)(getPoint_internal(pa, j++));
2069  p_out->x = p->x;
2070  p_out->y = p->y;
2071  if (ndims > 2)
2072  p_out->z = p->z;
2073  if (ndims > 3)
2074  p_out->m = p->m;
2075  }
2076 
2077  /* Update output ptarray length */
2078  pa->npoints = j;
2079  return;
2080 }
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:152
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
#define FP_EQUALS(A, B)
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: ptarray.c:1750
double m
Definition: liblwgeom.h:355
double x
Definition: liblwgeom.h:355
double z
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355
uint32_t npoints
Definition: liblwgeom.h:374
uint8_t flags
Definition: liblwgeom.h:372
unsigned int uint32_t
Definition: uthash.h:78

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: