PostGIS  2.2.7dev-r@@SVN_REVISION@@
static LWPOLY* lwpoly_from_twkb_state ( twkb_parse_state s)
static

POLYGON.

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

259 {
260  uint32_t nrings;
261  int i;
262  LWPOLY *poly;
263 
264  LWDEBUG(2,"Entering lwpoly_from_twkb_state");
265 
266  if ( s->is_empty )
268 
269  /* Read number of rings */
270  nrings = twkb_parse_state_uvarint(s);
271 
272  /* Start w/ empty polygon */
274 
275  LWDEBUGF(4,"Polygon has %d rings", nrings);
276 
277  /* Empty polygon? */
278  if( nrings == 0 )
279  return poly;
280 
281  for( i = 0; i < nrings; i++ )
282  {
283  /* Ret number of points */
284  uint32_t npoints = twkb_parse_state_uvarint(s);
285  POINTARRAY *pa = ptarray_from_twkb_state(s, npoints);
286 
287  /* Skip empty rings */
288  if( pa == NULL )
289  continue;
290 
291  /* Force first and last points to be the same. */
292  if( ! ptarray_is_closed_2d(pa) )
293  {
294  POINT4D pt;
295  getPoint4d_p(pa, 0, &pt);
296  ptarray_append_point(pa, &pt, LW_FALSE);
297  }
298 
299  /* Check for at least four points. */
300  if( s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4 )
301  {
302  LWDEBUGF(2, "%s must have at least four points in each ring", lwtype_name(s->lwtype));
303  lwerror("%s must have at least four points in each ring", lwtype_name(s->lwtype));
304  return NULL;
305  }
306 
307  /* Add ring to polygon */
308  if ( lwpoly_add_ring(poly, pa) == LW_FAILURE )
309  {
310  LWDEBUG(2, "Unable to add ring to polygon");
311  lwerror("Unable to add ring to polygon");
312  }
313 
314  }
315  return poly;
316 }
uint8_t has_z
Definition: lwin_twkb.c:35
uint8_t is_empty
Definition: lwin_twkb.c:37
int npoints
Definition: liblwgeom.h:355
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:1864
uint8_t has_m
Definition: lwin_twkb.c:36
uint32_t check
Definition: lwin_twkb.c:29
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
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:158
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:694
#define LW_FAILURE
Definition: liblwgeom.h:64
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
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_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:62
uint32_t lwtype
Definition: lwin_twkb.c:30
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
static uint64_t twkb_parse_state_uvarint(twkb_parse_state *s)
Definition: lwin_twkb.c:87
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:66
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:154
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231

Here is the call graph for this function:

Here is the caller graph for this function: