PostGIS  2.5.0dev-r@@SVN_REVISION@@
void ptarray_grid_in_place ( POINTARRAY pa,
const gridspec grid 
)

Definition at line 1873 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().

1874 {
1875  uint32_t i, j = 0;
1876  POINT4D *p, *p_out = NULL;
1877  int ndims = FLAGS_NDIMS(pa->flags);
1878  int has_z = FLAGS_GET_Z(pa->flags);
1879  int has_m = FLAGS_GET_M(pa->flags);
1880 
1881  LWDEBUGF(2, "%s called on %p", __func__, pa);
1882 
1883  for (i = 0; i < pa->npoints; i++)
1884  {
1885  /* Look straight into the abyss */
1886  p = (POINT4D*)(getPoint_internal(pa, i));
1887 
1888  if (grid->xsize > 0)
1889  {
1890  p->x = rint((p->x - grid->ipx)/grid->xsize) * grid->xsize + grid->ipx;
1891  }
1892 
1893  if (grid->ysize > 0)
1894  {
1895  p->y = rint((p->y - grid->ipy)/grid->ysize) * grid->ysize + grid->ipy;
1896  }
1897 
1898  /* Read and round this point */
1899  /* Z is always in third position */
1900  if (has_z)
1901  {
1902  if (grid->zsize > 0)
1903  p->z = rint((p->z - grid->ipz)/grid->zsize) * grid->zsize + grid->ipz;
1904  }
1905  /* M might be in 3rd or 4th position */
1906  if (has_m)
1907  {
1908  /* In POINT M, M is in 3rd position */
1909  if (grid->msize > 0 && !has_z)
1910  p->z = rint((p->z - grid->ipm)/grid->msize) * grid->msize + grid->ipm;
1911  /* In POINT ZM, M is in 4th position */
1912  if (grid->msize > 0 && has_z)
1913  p->m = rint((p->m - grid->ipm)/grid->msize) * grid->msize + grid->ipm;
1914  }
1915 
1916  /* Skip duplicates */
1917  if ( p_out && FP_EQUALS(p_out->x, p->x) && FP_EQUALS(p_out->y, p->y)
1918  && (ndims > 2 ? FP_EQUALS(p_out->z, p->z) : 1)
1919  && (ndims > 3 ? FP_EQUALS(p_out->m, p->m) : 1) )
1920  {
1921  continue;
1922  }
1923 
1924  /* Write rounded values into the next available point */
1925  p_out = (POINT4D*)(getPoint_internal(pa, j++));
1926  p_out->x = p->x;
1927  p_out->y = p->y;
1928  if (ndims > 2)
1929  p_out->z = p->z;
1930  if (ndims > 3)
1931  p_out->m = p->m;
1932  }
1933 
1934  /* Update output ptarray length */
1935  pa->npoints = j;
1936  return;
1937 }
double x
Definition: liblwgeom.h:351
double m
Definition: liblwgeom.h:351
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:368
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
double z
Definition: liblwgeom.h:351
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
#define FP_EQUALS(A, B)
double y
Definition: liblwgeom.h:351
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:151
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function:

Here is the caller graph for this function: