PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ lwpoly_from_twkb_state()

static LWPOLY* lwpoly_from_twkb_state ( twkb_parse_state s)
static

POLYGON.

Definition at line 272 of file lwin_twkb.c.

References twkb_parse_state::check, getPoint4d_p(), twkb_parse_state::has_m, twkb_parse_state::has_z, twkb_parse_state::is_empty, LW_FAILURE, LW_FALSE, LW_PARSER_CHECK_MINPOINTS, LWDEBUG, LWDEBUGF, lwerror(), lwpoly_add_ring(), lwpoly_construct_empty(), twkb_parse_state::lwtype, lwtype_name(), POINTARRAY::npoints, ptarray_append_point(), ptarray_from_twkb_state(), ptarray_is_closed_2d(), SRID_UNKNOWN, and twkb_parse_state_uvarint().

Referenced by lwgeom_from_twkb_state(), and lwmultipoly_from_twkb_state().

273 {
274  uint32_t nrings;
275  uint32_t i;
276  LWPOLY *poly;
277 
278  LWDEBUG(2,"Entering lwpoly_from_twkb_state");
279 
280  if ( s->is_empty )
282 
283  /* Read number of rings */
284  nrings = twkb_parse_state_uvarint(s);
285 
286  /* Start w/ empty polygon */
288 
289  LWDEBUGF(4,"Polygon has %d rings", nrings);
290 
291  /* Empty polygon? */
292  if( nrings == 0 )
293  return poly;
294 
295  for( i = 0; i < nrings; i++ )
296  {
297  /* Ret number of points */
298  uint32_t npoints = twkb_parse_state_uvarint(s);
299  POINTARRAY *pa = ptarray_from_twkb_state(s, npoints);
300 
301  /* Skip empty rings */
302  if( pa == NULL )
303  continue;
304 
305  /* Force first and last points to be the same. */
306  if( ! ptarray_is_closed_2d(pa) )
307  {
308  POINT4D pt;
309  getPoint4d_p(pa, 0, &pt);
310  ptarray_append_point(pa, &pt, LW_FALSE);
311  }
312 
313  /* Check for at least four points. */
314  if( s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4 )
315  {
316  LWDEBUGF(2, "%s must have at least four points in each ring", lwtype_name(s->lwtype));
317  lwerror("%s must have at least four points in each ring", lwtype_name(s->lwtype));
318  return NULL;
319  }
320 
321  /* Add ring to polygon */
322  if ( lwpoly_add_ring(poly, pa) == LW_FAILURE )
323  {
324  LWDEBUG(2, "Unable to add ring to polygon");
325  lwerror("Unable to add ring to polygon");
326  }
327 
328  }
329  return poly;
330 }
uint8_t has_z
Definition: lwin_twkb.c:49
uint8_t is_empty
Definition: lwin_twkb.c:51
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:1999
uint8_t has_m
Definition: lwin_twkb.c:50
uint32_t check
Definition: lwin_twkb.c:43
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
static POINTARRAY * ptarray_from_twkb_state(twkb_parse_state *s, uint32_t npoints)
POINTARRAY Read a dynamically sized point array and advance the parse state forward.
Definition: lwin_twkb.c:172
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:688
#define LW_FAILURE
Definition: liblwgeom.h:78
unsigned int uint32_t
Definition: uthash.h:78
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:76
uint32_t lwtype
Definition: lwin_twkb.c:44
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
static uint64_t twkb_parse_state_uvarint(twkb_parse_state *s)
Definition: lwin_twkb.c:101
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:113
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:161
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:247
#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:190
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: