PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwpoly_grid()

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

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

643 {
644  LWPOLY *opoly;
645  int ri;
646 
647 #if 0
648  /*
649  * TODO: control this assertion
650  * it is assumed that, since the grid size will be a pixel,
651  * a visible ring should show at least a white pixel inside,
652  * thus, for a square, that would be grid_xsize*grid_ysize
653  */
654  double minvisiblearea = grid->xsize * grid->ysize;
655 #endif
656 
657  LWDEBUGF(3, "lwpoly_grid: applying grid to polygon with %d rings", poly->nrings);
658 
659  opoly = lwpoly_construct_empty(poly->srid, lwgeom_has_z((LWGEOM*)poly), lwgeom_has_m((LWGEOM*)poly));
660 
661  for (ri=0; ri<poly->nrings; ri++)
662  {
663  POINTARRAY *ring = poly->rings[ri];
664  POINTARRAY *newring;
665 
666  newring = ptarray_grid(ring, grid);
667 
668  /* Skip ring if not composed by at least 4 pts (3 segments) */
669  if ( newring->npoints < 4 )
670  {
671  ptarray_free(newring);
672 
673  LWDEBUGF(3, "grid_polygon3d: ring%d skipped ( <4 pts )", ri);
674 
675  if ( ri ) continue;
676  else break; /* this is the external ring, no need to work on holes */
677  }
678 
679  if ( ! lwpoly_add_ring(opoly, newring) )
680  {
681  lwerror("lwpoly_grid, memory error");
682  return NULL;
683  }
684  }
685 
686  LWDEBUGF(3, "lwpoly_grid: simplified polygon with %d rings", opoly->nrings);
687 
688  if ( ! opoly->nrings )
689  {
690  lwpoly_free(opoly);
691  return NULL;
692  }
693 
694  return opoly;
695 }
int npoints
Definition: liblwgeom.h:371
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:249
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:885
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:161
int nrings
Definition: liblwgeom.h:455
int32_t srid
Definition: liblwgeom.h:454
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:174
POINTARRAY * ptarray_grid(const POINTARRAY *pa, const gridspec *grid)
Definition: ptarray.c:1890
#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:892
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: