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

◆ lwcurvepoly_add_ring()

int lwcurvepoly_add_ring ( LWCURVEPOLY poly,
LWGEOM ring 
)
extern

Add a ring, allocating extra space if necessary.

The curvepolygon takes ownership of the passed point array.

Definition at line 71 of file lwcurvepoly.c.

72{
73 uint32_t i;
74
75 /* Can't do anything with NULLs */
76 if( ! poly || ! ring )
77 {
78 LWDEBUG(4,"NULL inputs!!! quitting");
79 return LW_FAILURE;
80 }
81
82 /* Check that we're not working with garbage */
83 if ( poly->rings == NULL && (poly->nrings || poly->maxrings) )
84 {
85 LWDEBUG(4,"mismatched nrings/maxrings");
86 lwerror("Curvepolygon is in inconsistent state. Null memory but non-zero collection counts.");
87 return LW_FAILURE;
88 }
89
90 /* Check that we're adding an allowed ring type */
91 if ( ! ( ring->type == LINETYPE || ring->type == CIRCSTRINGTYPE || ring->type == COMPOUNDTYPE ) )
92 {
93 LWDEBUGF(4,"got incorrect ring type: %s",lwtype_name(ring->type));
94 return LW_FAILURE;
95 }
96
97
98 /* In case this is a truly empty, make some initial space */
99 if ( poly->rings == NULL )
100 {
101 poly->maxrings = 2;
102 poly->nrings = 0;
103 poly->rings = lwalloc(poly->maxrings * sizeof(LWGEOM*));
104 }
105
106 /* Allocate more space if we need it */
107 if ( poly->nrings == poly->maxrings )
108 {
109 poly->maxrings *= 2;
110 poly->rings = lwrealloc(poly->rings, sizeof(LWGEOM*) * poly->maxrings);
111 }
112
113 /* Make sure we don't already have a reference to this geom */
114 for ( i = 0; i < poly->nrings; i++ )
115 {
116 if ( poly->rings[i] == ring )
117 {
118 LWDEBUGF(4, "Found duplicate geometry in collection %p == %p", poly->rings[i], ring);
119 return LW_SUCCESS;
120 }
121 }
122
123 /* Add the ring and increment the ring count */
124 poly->rings[poly->nrings] = (LWGEOM*)ring;
125 poly->nrings++;
126 return LW_SUCCESS;
127}
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
#define COMPOUNDTYPE
Definition liblwgeom.h:110
void * lwrealloc(void *mem, size_t size)
Definition lwutil.c:242
#define LW_FAILURE
Definition liblwgeom.h:96
#define LINETYPE
Definition liblwgeom.h:103
#define LW_SUCCESS
Definition liblwgeom.h:97
void * lwalloc(size_t size)
Definition lwutil.c:227
#define CIRCSTRINGTYPE
Definition liblwgeom.h:109
#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.
LWGEOM ** rings
Definition liblwgeom.h:603
uint32_t nrings
Definition liblwgeom.h:608
uint32_t maxrings
Definition liblwgeom.h:609
uint8_t type
Definition liblwgeom.h:462

References CIRCSTRINGTYPE, COMPOUNDTYPE, LINETYPE, LW_FAILURE, LW_SUCCESS, lwalloc(), LWDEBUG, LWDEBUGF, lwerror(), lwrealloc(), lwtype_name(), LWCURVEPOLY::maxrings, LWCURVEPOLY::nrings, LWCURVEPOLY::rings, and LWGEOM::type.

Referenced by lwcurvepoly_from_wkb_state(), and wkt_parser_curvepolygon_add_ring().

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