PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ lwpoly_grid()

LWPOLY* lwpoly_grid ( const LWPOLY poly,
const gridspec grid 
)

Definition at line 602 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::srid, gridspec_t::xsize, and gridspec_t::ysize.

Referenced by lwgeom_grid().

603 {
604  LWPOLY *opoly;
605  int ri;
606 
607 #if 0
608  /*
609  * TODO: control this assertion
610  * it is assumed that, since the grid size will be a pixel,
611  * a visible ring should show at least a white pixel inside,
612  * thus, for a square, that would be grid_xsize*grid_ysize
613  */
614  double minvisiblearea = grid->xsize * grid->ysize;
615 #endif
616 
617  LWDEBUGF(3, "lwpoly_grid: applying grid to polygon with %d rings", poly->nrings);
618 
619  opoly = lwpoly_construct_empty(poly->srid, lwgeom_has_z((LWGEOM*)poly), lwgeom_has_m((LWGEOM*)poly));
620 
621  for (ri=0; ri<poly->nrings; ri++)
622  {
623  POINTARRAY *ring = poly->rings[ri];
624  POINTARRAY *newring;
625 
626  newring = ptarray_grid(ring, grid);
627 
628  /* Skip ring if not composed by at least 4 pts (3 segments) */
629  if ( newring->npoints < 4 )
630  {
631  ptarray_free(newring);
632 
633  LWDEBUGF(3, "grid_polygon3d: ring%d skipped ( <4 pts )", ri);
634 
635  if ( ri ) continue;
636  else break; /* this is the external ring, no need to work on holes */
637  }
638 
639  if ( ! lwpoly_add_ring(opoly, newring) )
640  {
641  lwerror("lwpoly_grid, memory error");
642  return NULL;
643  }
644  }
645 
646  LWDEBUGF(3, "lwpoly_grid: simplified polygon with %d rings", opoly->nrings);
647 
648  if ( ! opoly->nrings )
649  {
650  lwpoly_free(opoly);
651  return NULL;
652  }
653 
654  return opoly;
655 }
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:227
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:139
int nrings
Definition: liblwgeom.h:454
int32_t srid
Definition: liblwgeom.h:453
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:152
POINTARRAY * ptarray_grid(const POINTARRAY *pa, const gridspec *grid)
Definition: ptarray.c:1850
#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: