PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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.

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 )
281 return lwpoly_construct_empty(SRID_UNKNOWN, s->has_z, s->has_m);
282
283 /* Read number of rings */
284 nrings = twkb_parse_state_uvarint(s);
285
286 /* Start w/ empty polygon */
287 poly = lwpoly_construct_empty(SRID_UNKNOWN, s->has_z, s->has_m);
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);
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}
char * s
Definition cu_in_wkt.c:23
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
#define LW_FALSE
Definition liblwgeom.h:94
#define LW_FAILURE
Definition liblwgeom.h:96
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition lwpoly.c:247
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition lwgeom_api.c:125
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition liblwgeom.h:2144
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,...
Definition ptarray.c:147
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition ptarray.c:710
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoly.c:161
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215
#define LWDEBUG(level, msg)
Definition lwgeom_log.h:101
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
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
static uint64_t twkb_parse_state_uvarint(twkb_parse_state *s)
Definition lwin_twkb.c:101
uint32_t npoints
Definition liblwgeom.h:427

References getPoint4d_p(), LW_FAILURE, LW_FALSE, LW_PARSER_CHECK_MINPOINTS, LWDEBUG, LWDEBUGF, lwerror(), lwpoly_add_ring(), lwpoly_construct_empty(), lwtype_name(), POINTARRAY::npoints, ptarray_append_point(), ptarray_from_twkb_state(), ptarray_is_closed_2d(), s, SRID_UNKNOWN, and twkb_parse_state_uvarint().

Referenced by lwgeom_from_twkb_state(), and lwmultipoly_from_twkb_state().

Here is the call graph for this function:
Here is the caller graph for this function: