PostGIS  2.2.7dev-r@@SVN_REVISION@@
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 59 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().

60 {
61  int i;
62 
63  /* Can't do anything with NULLs */
64  if( ! poly || ! ring )
65  {
66  LWDEBUG(4,"NULL inputs!!! quitting");
67  return LW_FAILURE;
68  }
69 
70  /* Check that we're not working with garbage */
71  if ( poly->rings == NULL && (poly->nrings || poly->maxrings) )
72  {
73  LWDEBUG(4,"mismatched nrings/maxrings");
74  lwerror("Curvepolygon is in inconsistent state. Null memory but non-zero collection counts.");
75  }
76 
77  /* Check that we're adding an allowed ring type */
78  if ( ! ( ring->type == LINETYPE || ring->type == CIRCSTRINGTYPE || ring->type == COMPOUNDTYPE ) )
79  {
80  LWDEBUGF(4,"got incorrect ring type: %s",lwtype_name(ring->type));
81  return LW_FAILURE;
82  }
83 
84 
85  /* In case this is a truly empty, make some initial space */
86  if ( poly->rings == NULL )
87  {
88  poly->maxrings = 2;
89  poly->nrings = 0;
90  poly->rings = lwalloc(poly->maxrings * sizeof(LWGEOM*));
91  }
92 
93  /* Allocate more space if we need it */
94  if ( poly->nrings == poly->maxrings )
95  {
96  poly->maxrings *= 2;
97  poly->rings = lwrealloc(poly->rings, sizeof(LWGEOM*) * poly->maxrings);
98  }
99 
100  /* Make sure we don't already have a reference to this geom */
101  for ( i = 0; i < poly->nrings; i++ )
102  {
103  if ( poly->rings[i] == ring )
104  {
105  LWDEBUGF(4, "Found duplicate geometry in collection %p == %p", poly->rings[i], ring);
106  return LW_SUCCESS;
107  }
108  }
109 
110  /* Add the ring and increment the ring count */
111  poly->rings[poly->nrings] = (LWGEOM*)ring;
112  poly->nrings++;
113  return LW_SUCCESS;
114 }
#define LINETYPE
Definition: liblwgeom.h:71
LWGEOM ** rings
Definition: liblwgeom.h:519
int maxrings
Definition: liblwgeom.h:518
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
#define LW_SUCCESS
Definition: liblwgeom.h:65
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
#define LW_FAILURE
Definition: liblwgeom.h:64
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:207
uint8_t type
Definition: liblwgeom.h:380
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:77
void * lwalloc(size_t size)
Definition: lwutil.c:199
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74

Here is the call graph for this function:

Here is the caller graph for this function: