PostGIS  2.2.7dev-r@@SVN_REVISION@@
LWCOLLECTION* lwcollection_add_lwgeom ( LWCOLLECTION col,
const LWGEOM geom 
)

Appends geom to the collection managed by col.

Does not copy or clone, simply takes a reference on the passed geom.

Definition at line 174 of file lwcollection.c.

References LWCOLLECTION::geoms, lwalloc(), lwcollection_allows_subtype(), lwcollection_reserve(), LWDEBUGF, lwerror(), lwtype_name(), LWCOLLECTION::maxgeoms, LWCOLLECTION::ngeoms, LWGEOM::type, and LWCOLLECTION::type.

Referenced by lwcollection_build_buffer(), lwcollection_from_twkb_state(), lwcollection_from_wkb_state(), lwcollection_grid(), lwcollection_homogenize(), lwcollection_set_effective_area(), lwcollection_simplify(), lwcompound_add_lwgeom(), lwgeom_clip_to_ordinate_range(), lwgeom_segmentize_sphere(), lwgeom_subdivide_recursive(), lwline_clip_to_ordinate_range(), lwmline_add_lwline(), lwmpoint_add_lwpoint(), lwmpoint_clip_to_ordinate_range(), lwmpoly_add_lwpoly(), lwmultiline_from_twkb_state(), lwmultipoint_from_twkb_state(), lwmultipoly_from_twkb_state(), lwpoint_clip_to_ordinate_range(), lwpsurface_add_lwpoly(), lwtin_add_lwtriangle(), parse_geojson_geometrycollection(), parse_gml_coll(), parse_kml_multi(), pta_unstroke(), TWKBFromLWGEOMArray(), and wkt_parser_collection_add_geom().

175 {
176  if ( col == NULL || geom == NULL ) return NULL;
177 
178  if ( col->geoms == NULL && (col->ngeoms || col->maxgeoms) ) {
179  lwerror("Collection is in inconsistent state. Null memory but non-zero collection counts.");
180  return NULL;
181  }
182 
183  /* Check type compatibility */
184  if ( ! lwcollection_allows_subtype(col->type, geom->type) ) {
185  lwerror("%s cannot contain %s element", lwtype_name(col->type), lwtype_name(geom->type));
186  return NULL;
187  }
188 
189  /* In case this is a truly empty, make some initial space */
190  if ( col->geoms == NULL )
191  {
192  col->maxgeoms = 2;
193  col->ngeoms = 0;
194  col->geoms = lwalloc(col->maxgeoms * sizeof(LWGEOM*));
195  }
196 
197  /* Allocate more space if we need it */
198  lwcollection_reserve(col, col->ngeoms + 1);
199 
200 #if PARANOIA_LEVEL > 1
201  /* See http://trac.osgeo.org/postgis/ticket/2933 */
202  /* Make sure we don't already have a reference to this geom */
203  {
204  int i = 0;
205  for ( i = 0; i < col->ngeoms; i++ )
206  {
207  if ( col->geoms[i] == geom )
208  {
209  LWDEBUGF(4, "Found duplicate geometry in collection %p == %p", col->geoms[i], geom);
210  return col;
211  }
212  }
213  }
214 #endif
215 
216  col->geoms[col->ngeoms] = (LWGEOM*)geom;
217  col->ngeoms++;
218  return col;
219 }
void lwcollection_reserve(LWCOLLECTION *col, int ngeoms)
Ensure the collection can hold up at least ngeoms.
Definition: lwcollection.c:161
uint8_t type
Definition: liblwgeom.h:487
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
LWGEOM ** geoms
Definition: liblwgeom.h:493
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
Definition: lwcollection.c:523
uint8_t type
Definition: liblwgeom.h:380
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: