PostGIS  2.3.7dev-r@@SVN_REVISION@@
LWPOLY* lwpoly_grid ( const LWPOLY poly,
const gridspec grid 
)

Definition at line 600 of file lwpoly.c.

References LWDEBUGF, lwerror(), lwgeom_has_m(), lwgeom_has_z(), lwpoly_add_ring(), lwpoly_construct_empty(), lwpoly_free(), POINTARRAY::npoints, LWPOLY::nrings, ptarray_free(), ptarray_grid(), LWPOLY::rings, LWPOLY::srid, gridspec_t::xsize, and gridspec_t::ysize.

Referenced by lwgeom_grid().

601 {
602  LWPOLY *opoly;
603  int ri;
604 
605 #if 0
606  /*
607  * TODO: control this assertion
608  * it is assumed that, since the grid size will be a pixel,
609  * a visible ring should show at least a white pixel inside,
610  * thus, for a square, that would be grid_xsize*grid_ysize
611  */
612  double minvisiblearea = grid->xsize * grid->ysize;
613 #endif
614 
615  LWDEBUGF(3, "lwpoly_grid: applying grid to polygon with %d rings", poly->nrings);
616 
617  opoly = lwpoly_construct_empty(poly->srid, lwgeom_has_z((LWGEOM*)poly), lwgeom_has_m((LWGEOM*)poly));
618 
619  for (ri=0; ri<poly->nrings; ri++)
620  {
621  POINTARRAY *ring = poly->rings[ri];
622  POINTARRAY *newring;
623 
624  newring = ptarray_grid(ring, grid);
625 
626  /* Skip ring if not composed by at least 4 pts (3 segments) */
627  if ( newring->npoints < 4 )
628  {
629  ptarray_free(newring);
630 
631  LWDEBUGF(3, "grid_polygon3d: ring%d skipped ( <4 pts )", ri);
632 
633  if ( ri ) continue;
634  else break; /* this is the external ring, no need to work on holes */
635  }
636 
637  if ( ! lwpoly_add_ring(opoly, newring) )
638  {
639  lwerror("lwpoly_grid, memory error");
640  return NULL;
641  }
642  }
643 
644  LWDEBUGF(3, "lwpoly_grid: simplified polygon with %d rings", opoly->nrings);
645 
646  if ( ! opoly->nrings )
647  {
648  lwpoly_free(opoly);
649  return NULL;
650  }
651 
652  return opoly;
653 }
int npoints
Definition: liblwgeom.h:370
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring to a polygon.
Definition: lwpoly.c:225
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:849
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:137
POINTARRAY ** rings
Definition: liblwgeom.h:456
int nrings
Definition: liblwgeom.h:454
int32_t srid
Definition: liblwgeom.h:453
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:150
POINTARRAY * ptarray_grid(const POINTARRAY *pa, const gridspec *grid)
Definition: ptarray.c:1843
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:856
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102

Here is the call graph for this function:

Here is the caller graph for this function: