PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwpoly_grid()

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

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

530 {
531  LWPOLY *opoly;
532  int ri;
533 
534 #if 0
535  /*
536  * TODO: control this assertion
537  * it is assumed that, since the grid size will be a pixel,
538  * a visible ring should show at least a white pixel inside,
539  * thus, for a square, that would be grid_xsize*grid_ysize
540  */
541  double minvisiblearea = grid->xsize * grid->ysize;
542 #endif
543 
544  LWDEBUGF(3, "lwpoly_grid: applying grid to polygon with %d rings", poly->nrings);
545 
546  opoly = lwpoly_construct_empty(poly->srid, lwgeom_has_z((LWGEOM*)poly), lwgeom_has_m((LWGEOM*)poly));
547 
548  for (ri=0; ri<poly->nrings; ri++)
549  {
550  POINTARRAY *ring = poly->rings[ri];
551  POINTARRAY *newring;
552 
553  newring = ptarray_grid(ring, grid);
554 
555  /* Skip ring if not composed by at least 4 pts (3 segments) */
556  if ( newring->npoints < 4 )
557  {
558  ptarray_free(newring);
559 
560  LWDEBUGF(3, "grid_polygon3d: ring%d skipped ( <4 pts )", ri);
561 
562  if ( ri ) continue;
563  else break; /* this is the external ring, no need to work on holes */
564  }
565 
566  if ( ! lwpoly_add_ring(opoly, newring) )
567  {
568  lwerror("lwpoly_grid, memory error");
569  return NULL;
570  }
571  }
572 
573  LWDEBUGF(3, "lwpoly_grid: simplified polygon with %d rings", opoly->nrings);
574 
575  if ( ! opoly->nrings )
576  {
577  lwpoly_free(opoly);
578  return NULL;
579  }
580 
581  return opoly;
582 }
int npoints
Definition: liblwgeom.h:355
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:154
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:836
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:66
int nrings
Definition: liblwgeom.h:439
int32_t srid
Definition: liblwgeom.h:438
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:79
POINTARRAY * ptarray_grid(const POINTARRAY *pa, const gridspec *grid)
Definition: ptarray.c:1843
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:843
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function:
Here is the caller graph for this function: