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

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

190{
191 if (!col || !geom) return NULL;
192
193 if (!col->geoms && (col->ngeoms || col->maxgeoms))
194 {
195 lwerror("Collection is in inconsistent state. Null memory but non-zero collection counts.");
196 return NULL;
197 }
198
199 /* Check type compatibility */
200 if ( ! lwcollection_allows_subtype(col->type, geom->type) ) {
201 lwerror("%s cannot contain %s element", lwtype_name(col->type), lwtype_name(geom->type));
202 return NULL;
203 }
204
205 /* In case this is a truly empty, make some initial space */
206 if (!col->geoms)
207 {
208 col->maxgeoms = 2;
209 col->ngeoms = 0;
210 col->geoms = lwalloc(col->maxgeoms * sizeof(LWGEOM*));
211 }
212
213 /* Allocate more space if we need it */
214 lwcollection_reserve(col, col->ngeoms + 1);
215
216#ifndef NDEBUG
217 /* See http://trac.osgeo.org/postgis/ticket/2933 */
218 /* Make sure we don't already have a reference to this geom */
219 {
220 for (uint32_t 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 void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
uint32_t ngeoms
Definition liblwgeom.h:580
uint32_t maxgeoms
Definition liblwgeom.h:581
uint8_t type
Definition liblwgeom.h:578
LWGEOM ** geoms
Definition liblwgeom.h:575
uint8_t type
Definition liblwgeom.h:462

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_extract_recursive(), lwcollection_filterm(), lwcollection_from_twkb_state(), lwcollection_from_wkb_state(), lwcollection_homogenize(), lwcollection_offsetcurve(), lwcollection_set_effective_area(), lwcompound_add_lwgeom(), lwgeom_boundary(), 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(), parse_geojson_geometrycollection(), parse_gml_coll(), parse_kml_multi(), parse_marc21(), 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: