PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ lwcurvepoly_add_ring()

int lwcurvepoly_add_ring ( LWCURVEPOLY poly,
LWGEOM ring 
)

Add a ring, allocating extra space if necessary.

The curvepolygon takes ownership of the passed point array.

Definition at line 72 of file lwcurvepoly.c.

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().

73 {
74  uint32_t i;
75 
76  /* Can't do anything with NULLs */
77  if( ! poly || ! ring )
78  {
79  LWDEBUG(4,"NULL inputs!!! quitting");
80  return LW_FAILURE;
81  }
82 
83  /* Check that we're not working with garbage */
84  if ( poly->rings == NULL && (poly->nrings || poly->maxrings) )
85  {
86  LWDEBUG(4,"mismatched nrings/maxrings");
87  lwerror("Curvepolygon is in inconsistent state. Null memory but non-zero collection counts.");
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 }
#define LINETYPE
Definition: liblwgeom.h:85
LWGEOM ** rings
Definition: liblwgeom.h:537
#define COMPOUNDTYPE
Definition: liblwgeom.h:92
#define LW_SUCCESS
Definition: liblwgeom.h:79
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#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
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
uint8_t type
Definition: liblwgeom.h:398
uint32_t nrings
Definition: liblwgeom.h:535
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91
void * lwalloc(size_t size)
Definition: lwutil.c:229
#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 maxrings
Definition: liblwgeom.h:536
Here is the call graph for this function:
Here is the caller graph for this function: