PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lwgeom_homogenize()

LWGEOM* lwgeom_homogenize ( const LWGEOM geom)

Definition at line 208 of file lwhomogenize.c.

209 {
210  LWGEOM *hgeom;
211 
212  /* EMPTY Geometry */
213  if (lwgeom_is_empty(geom))
214  {
215  if( lwgeom_is_collection(geom) )
216  {
218  }
219 
220  return lwgeom_clone_deep(geom);
221  }
222 
223  switch (geom->type)
224  {
225 
226  /* Return simple geometries untouched */
227  case POINTTYPE:
228  case LINETYPE:
229  case CIRCSTRINGTYPE:
230  case COMPOUNDTYPE:
231  case TRIANGLETYPE:
232  case CURVEPOLYTYPE:
233  case POLYGONTYPE:
234  return lwgeom_clone_deep(geom);
235 
236  /* Process homogeneous geometries lightly */
237  case MULTIPOINTTYPE:
238  case MULTILINETYPE:
239  case MULTIPOLYGONTYPE:
240  case MULTICURVETYPE:
241  case MULTISURFACETYPE:
243  case TINTYPE:
244  {
245  LWCOLLECTION *col = (LWCOLLECTION*)geom;
246 
247  /* Strip single-entry multi-geometries down to singletons */
248  if ( col->ngeoms == 1 )
249  {
250  hgeom = lwgeom_clone_deep((LWGEOM *)(col->geoms[0]));
251  hgeom->srid = geom->srid;
252  if (geom->bbox)
253  hgeom->bbox = gbox_copy(geom->bbox);
254  return hgeom;
255  }
256 
257  /* Return proper multigeometry untouched */
258  return lwgeom_clone_deep(geom);
259  }
260 
261  /* Work on anonymous collections separately */
262  case COLLECTIONTYPE:
263  return lwcollection_homogenize((LWCOLLECTION *) geom);
264  }
265 
266  /* Unknown type */
267  lwerror("lwgeom_homogenize: Geometry Type not supported (%i)",
268  lwtype_name(geom->type));
269 
270  return NULL; /* Never get here! */
271 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: gbox.c:426
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:309
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
#define COMPOUNDTYPE
Definition: liblwgeom.h:110
#define CURVEPOLYTYPE
Definition: liblwgeom.h:111
#define MULTILINETYPE
Definition: liblwgeom.h:106
#define MULTISURFACETYPE
Definition: liblwgeom.h:113
#define LINETYPE
Definition: liblwgeom.h:103
#define MULTIPOINTTYPE
Definition: liblwgeom.h:105
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:529
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:934
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
#define TINTYPE
Definition: liblwgeom.h:116
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:107
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1097
#define POLYGONTYPE
Definition: liblwgeom.h:104
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:114
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:109
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwcollection.c:92
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
#define MULTICURVETYPE
Definition: liblwgeom.h:112
#define TRIANGLETYPE
Definition: liblwgeom.h:115
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:941
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static LWGEOM * lwcollection_homogenize(const LWCOLLECTION *col)
Definition: lwhomogenize.c:116
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:203
uint32_t ngeoms
Definition: liblwgeom.h:580
LWGEOM ** geoms
Definition: liblwgeom.h:575
uint8_t type
Definition: liblwgeom.h:462
GBOX * bbox
Definition: liblwgeom.h:458
int32_t srid
Definition: liblwgeom.h:460

References LWGEOM::bbox, CIRCSTRINGTYPE, COLLECTIONTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, gbox_copy(), LWCOLLECTION::geoms, LINETYPE, lwcollection_as_lwgeom(), lwcollection_construct_empty(), lwcollection_homogenize(), lwerror(), lwgeom_clone_deep(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_is_collection(), lwgeom_is_empty(), lwtype_name(), MULTICURVETYPE, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, MULTISURFACETYPE, LWCOLLECTION::ngeoms, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, LWGEOM::srid, TINTYPE, TRIANGLETYPE, and LWGEOM::type.

Referenced by do_geom_test(), geom_from_kml(), lwgeom_boundary(), and ST_CollectionHomogenize().

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