PostGIS  2.3.7dev-r@@SVN_REVISION@@
static LWPOLY* lwpoly_from_wkb_state ( wkb_parse_state s)
static

POLYGON Read a WKB polygon, starting just after the endian byte, type number and optional srid number.

Advance the parse state forward appropriately. First read the number of rings, then read each ring (which are structured as point arrays)

Definition at line 502 of file lwin_wkb.c.

References wkb_parse_state::check, wkb_parse_state::has_m, wkb_parse_state::has_z, integer_from_wkb_state(), LW_FAILURE, LW_PARSER_CHECK_CLOSURE, LW_PARSER_CHECK_MINPOINTS, LWDEBUG, LWDEBUGF, lwerror(), lwpoly_add_ring(), lwpoly_construct_empty(), wkb_parse_state::lwtype, lwtype_name(), POINTARRAY::npoints, ptarray_from_wkb_state(), ptarray_is_closed_2d(), and wkb_parse_state::srid.

Referenced by lwgeom_from_wkb_state().

503 {
504  uint32_t nrings = integer_from_wkb_state(s);
505  int i = 0;
506  LWPOLY *poly = lwpoly_construct_empty(s->srid, s->has_z, s->has_m);
507 
508  LWDEBUGF(4,"Polygon has %d rings", nrings);
509 
510  /* Empty polygon? */
511  if( nrings == 0 )
512  return poly;
513 
514  for( i = 0; i < nrings; i++ )
515  {
517  if( pa == NULL )
518  continue;
519 
520  /* Check for at least four points. */
521  if( s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4 )
522  {
523  LWDEBUGF(2, "%s must have at least four points in each ring", lwtype_name(s->lwtype));
524  lwerror("%s must have at least four points in each ring", lwtype_name(s->lwtype));
525  return NULL;
526  }
527 
528  /* Check that first and last points are the same. */
530  {
531  LWDEBUGF(2, "%s must have closed rings", lwtype_name(s->lwtype));
532  lwerror("%s must have closed rings", lwtype_name(s->lwtype));
533  return NULL;
534  }
535 
536  /* Add ring to polygon */
537  if ( lwpoly_add_ring(poly, pa) == LW_FAILURE )
538  {
539  LWDEBUG(2, "Unable to add ring to polygon");
540  lwerror("Unable to add ring to polygon");
541  }
542 
543  }
544  return poly;
545 }
static POINTARRAY * ptarray_from_wkb_state(wkb_parse_state *s)
POINTARRAY Read a dynamically sized point array and advance the parse state forward.
Definition: lwin_wkb.c:329
int npoints
Definition: liblwgeom.h:370
static uint32_t integer_from_wkb_state(wkb_parse_state *s)
Int32 Read 4-byte integer and advance the parse state forward.
Definition: lwin_wkb.c:267
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:1980
uint32_t lwtype
Definition: lwin_wkb.c:41
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:694
#define LW_FAILURE
Definition: liblwgeom.h:78
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
uint32_t srid
Definition: lwin_wkb.c:42
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:137
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:225
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
#define LW_PARSER_CHECK_CLOSURE
Definition: liblwgeom.h:1982

Here is the call graph for this function:

Here is the caller graph for this function: