PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwcollection_add_lwgeom()

LWCOLLECTION * lwcollection_add_lwgeom ( LWCOLLECTION col,
const LWGEOM geom 
)
extern

Appends geom to the collection managed by col.

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

Definition at line 188 of file lwcollection.c.

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

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(), lwpoly_clip_to_ordinate_range(), lwpsurface_add_lwpoly(), lwtin_add_lwtriangle(), lwtriangle_clip_to_ordinate_range(), 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: