PostGIS  2.4.9dev-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  int 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  return LW_FAILURE;
89  }
90 
91  /* Check that we're adding an allowed ring type */
92  if ( ! ( ring->type == LINETYPE || ring->type == CIRCSTRINGTYPE || ring->type == COMPOUNDTYPE ) )
93  {
94  LWDEBUGF(4,"got incorrect ring type: %s",lwtype_name(ring->type));
95  return LW_FAILURE;
96  }
97 
98 
99  /* In case this is a truly empty, make some initial space */
100  if ( poly->rings == NULL )
101  {
102  poly->maxrings = 2;
103  poly->nrings = 0;
104  poly->rings = lwalloc(poly->maxrings * sizeof(LWGEOM*));
105  }
106 
107  /* Allocate more space if we need it */
108  if ( poly->nrings == poly->maxrings )
109  {
110  poly->maxrings *= 2;
111  poly->rings = lwrealloc(poly->rings, sizeof(LWGEOM*) * poly->maxrings);
112  }
113 
114  /* Make sure we don't already have a reference to this geom */
115  for ( i = 0; i < poly->nrings; i++ )
116  {
117  if ( poly->rings[i] == ring )
118  {
119  LWDEBUGF(4, "Found duplicate geometry in collection %p == %p", poly->rings[i], ring);
120  return LW_SUCCESS;
121  }
122  }
123 
124  /* Add the ring and increment the ring count */
125  poly->rings[poly->nrings] = (LWGEOM*)ring;
126  poly->nrings++;
127  return LW_SUCCESS;
128 }
#define LINETYPE
Definition: liblwgeom.h:86
LWGEOM ** rings
Definition: liblwgeom.h:535
int maxrings
Definition: liblwgeom.h:534
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#define LW_FAILURE
Definition: liblwgeom.h:79
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:396
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
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
Here is the call graph for this function:
Here is the caller graph for this function: