PostGIS  3.0.6dev-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 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 }
#define COMPOUNDTYPE
Definition: liblwgeom.h:124
#define LW_FAILURE
Definition: liblwgeom.h:110
#define LINETYPE
Definition: liblwgeom.h:117
#define LW_SUCCESS
Definition: liblwgeom.h:111
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:235
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:123
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#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
LWGEOM ** rings
Definition: liblwgeom.h:589
uint32_t nrings
Definition: liblwgeom.h:594
uint32_t maxrings
Definition: liblwgeom.h:595
uint8_t type
Definition: liblwgeom.h:448

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: