PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ lwgeom_homogenize()

LWGEOM* lwgeom_homogenize ( const LWGEOM geom)

Definition at line 211 of file lwhomogenize.c.

References LWGEOM::bbox, CIRCSTRINGTYPE, COLLECTIONTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, gbox_copy(), LWCOLLECTION::geoms, LINETYPE, lwcollection_as_lwgeom(), lwcollection_construct_empty(), lwcollection_homogenize(), lwerror(), lwgeom_clone(), 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(), and ST_CollectionHomogenize().

212 {
213  LWGEOM *hgeom;
214 
215  /* EMPTY Geometry */
216  if (lwgeom_is_empty(geom))
217  {
218  if( lwgeom_is_collection(geom) )
219  {
221  }
222 
223  return lwgeom_clone(geom);
224  }
225 
226  switch (geom->type)
227  {
228 
229  /* Return simple geometries untouched */
230  case POINTTYPE:
231  case LINETYPE:
232  case CIRCSTRINGTYPE:
233  case COMPOUNDTYPE:
234  case TRIANGLETYPE:
235  case CURVEPOLYTYPE:
236  case POLYGONTYPE:
237  return lwgeom_clone(geom);
238 
239  /* Process homogeneous geometries lightly */
240  case MULTIPOINTTYPE:
241  case MULTILINETYPE:
242  case MULTIPOLYGONTYPE:
243  case MULTICURVETYPE:
244  case MULTISURFACETYPE:
246  case TINTYPE:
247  {
248  LWCOLLECTION *col = (LWCOLLECTION*)geom;
249 
250  /* Strip single-entry multi-geometries down to singletons */
251  if ( col->ngeoms == 1 )
252  {
253  hgeom = lwgeom_clone((LWGEOM*)(col->geoms[0]));
254  hgeom->srid = geom->srid;
255  if (geom->bbox)
256  hgeom->bbox = gbox_copy(geom->bbox);
257  return hgeom;
258  }
259 
260  /* Return proper multigeometry untouched */
261  return lwgeom_clone(geom);
262  }
263 
264  /* Work on anonymous collections separately */
265  case COLLECTIONTYPE:
266  return lwcollection_homogenize((LWCOLLECTION *) geom);
267  }
268 
269  /* Unknown type */
270  lwerror("lwgeom_homogenize: Geometry Type not supported (%i)",
271  lwtype_name(geom->type));
272 
273  return NULL; /* Never get here! */
274 }
#define LINETYPE
Definition: liblwgeom.h:85
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:433
GBOX * bbox
Definition: liblwgeom.h:400
#define MULTICURVETYPE
Definition: liblwgeom.h:94
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1085
#define POLYGONTYPE
Definition: liblwgeom.h:86
#define CURVEPOLYTYPE
Definition: liblwgeom.h:93
#define COMPOUNDTYPE
Definition: liblwgeom.h:92
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
#define TRIANGLETYPE
Definition: liblwgeom.h:97
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:96
uint32_t ngeoms
Definition: liblwgeom.h:509
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:930
int32_t srid
Definition: liblwgeom.h:401
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
static LWGEOM * lwcollection_homogenize(const LWCOLLECTION *col)
Definition: lwhomogenize.c:119
LWGEOM ** geoms
Definition: liblwgeom.h:511
#define TINTYPE
Definition: liblwgeom.h:98
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:482
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
#define MULTISURFACETYPE
Definition: liblwgeom.h:95
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
uint8_t type
Definition: liblwgeom.h:398
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1393
#define MULTILINETYPE
Definition: liblwgeom.h:88
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:937
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:300
Here is the call graph for this function:
Here is the caller graph for this function: