PostGIS  2.4.9dev-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.

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().

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