PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ ptarray_grid_in_place()

void ptarray_grid_in_place ( POINTARRAY pa,
const gridspec grid 
)

Definition at line 2009 of file ptarray.c.

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().

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