PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwcollection_add_lwgeom()

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 187 of file lwcollection.c.

188 {
189  if (!col || !geom) return NULL;
190 
191  if (!col->geoms && (col->ngeoms || col->maxgeoms))
192  {
193  lwerror("Collection is in inconsistent state. Null memory but non-zero collection counts.");
194  return NULL;
195  }
196 
197  /* Check type compatibility */
198  if ( ! lwcollection_allows_subtype(col->type, geom->type) ) {
199  lwerror("%s cannot contain %s element", lwtype_name(col->type), lwtype_name(geom->type));
200  return NULL;
201  }
202 
203  /* In case this is a truly empty, make some initial space */
204  if (!col->geoms)
205  {
206  col->maxgeoms = 2;
207  col->ngeoms = 0;
208  col->geoms = lwalloc(col->maxgeoms * sizeof(LWGEOM*));
209  }
210 
211  /* Allocate more space if we need it */
212  lwcollection_reserve(col, col->ngeoms + 1);
213 
214 #if PARANOIA_LEVEL > 1
215  /* See http://trac.osgeo.org/postgis/ticket/2933 */
216  /* Make sure we don't already have a reference to this geom */
217  {
218  uint32_t i = 0;
219  for (i = 0; i < col->ngeoms; i++)
220  {
221  if (col->geoms[i] == geom)
222  {
223  lwerror("%s [%d] found duplicate geometry in collection %p == %p", __FILE__, __LINE__, col->geoms[i], geom);
224  return col;
225  }
226  }
227  }
228 #endif
229 
230  col->geoms[col->ngeoms] = (LWGEOM*)geom;
231  col->ngeoms++;
232  return col;
233 }
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
void * lwalloc(size_t size)
Definition: lwutil.c:229
void lwcollection_reserve(LWCOLLECTION *col, uint32_t ngeoms)
Ensure the collection can hold up at least ngeoms.
Definition: lwcollection.c:174
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
Definition: lwcollection.c:534
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
uint32_t ngeoms
Definition: liblwgeom.h:510
uint32_t maxgeoms
Definition: liblwgeom.h:511
uint8_t type
Definition: liblwgeom.h:506
LWGEOM ** geoms
Definition: liblwgeom.h:512
uint8_t type
Definition: liblwgeom.h:399
unsigned int uint32_t
Definition: uthash.h:78

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

Referenced by lwcollection_build_buffer(), lwcollection_chaikin(), lwcollection_concat_in_place(), lwcollection_filterm(), lwcollection_from_twkb_state(), lwcollection_from_wkb_state(), lwcollection_homogenize(), lwcollection_offsetcurve(), lwcollection_set_effective_area(), 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(), mvt_iterate_clip_by_box_geos(), parse_geojson_geometrycollection(), parse_gml_coll(), parse_kml_multi(), pta_unstroke(), rect_tree_to_lwgeom(), TWKBFromLWGEOMArray(), and wkt_parser_collection_add_geom().

Here is the call graph for this function:
Here is the caller graph for this function: