PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwgeom_homogenize()

LWGEOM* lwgeom_homogenize ( const LWGEOM geom)

Definition at line 195 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().

196 {
197  LWGEOM *hgeom;
198 
199  /* EMPTY Geometry */
200  if (lwgeom_is_empty(geom))
201  {
202  if( lwgeom_is_collection(geom) )
203  {
205  }
206 
207  return lwgeom_clone(geom);
208  }
209 
210  switch (geom->type)
211  {
212 
213  /* Return simple geometries untouched */
214  case POINTTYPE:
215  case LINETYPE:
216  case CIRCSTRINGTYPE:
217  case COMPOUNDTYPE:
218  case TRIANGLETYPE:
219  case CURVEPOLYTYPE:
220  case POLYGONTYPE:
221  return lwgeom_clone(geom);
222 
223  /* Process homogeneous geometries lightly */
224  case MULTIPOINTTYPE:
225  case MULTILINETYPE:
226  case MULTIPOLYGONTYPE:
227  case MULTICURVETYPE:
228  case MULTISURFACETYPE:
230  case TINTYPE:
231  {
232  LWCOLLECTION *col = (LWCOLLECTION*)geom;
233 
234  /* Strip single-entry multi-geometries down to singletons */
235  if ( col->ngeoms == 1 )
236  {
237  hgeom = lwgeom_clone((LWGEOM*)(col->geoms[0]));
238  hgeom->srid = geom->srid;
239  if (geom->bbox)
240  hgeom->bbox = gbox_copy(geom->bbox);
241  return hgeom;
242  }
243 
244  /* Return proper multigeometry untouched */
245  return lwgeom_clone(geom);
246  }
247 
248  /* Work on anonymous collections separately */
249  case COLLECTIONTYPE:
250  return lwcollection_homogenize((LWCOLLECTION *) geom);
251  }
252 
253  /* Unknown type */
254  lwerror("lwgeom_homogenize: Geometry Type not supported (%i)",
255  lwtype_name(geom->type));
256 
257  return NULL; /* Never get here! */
258 }
#define LINETYPE
Definition: liblwgeom.h:71
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:403
GBOX * bbox
Definition: liblwgeom.h:382
#define MULTICURVETYPE
Definition: liblwgeom.h:80
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:991
#define POLYGONTYPE
Definition: liblwgeom.h:72
#define CURVEPOLYTYPE
Definition: liblwgeom.h:79
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
#define TRIANGLETYPE
Definition: liblwgeom.h:83
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:82
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:836
int32_t srid
Definition: liblwgeom.h:383
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
static LWGEOM * lwcollection_homogenize(const LWCOLLECTION *col)
Definition: lwhomogenize.c:103
LWGEOM ** geoms
Definition: liblwgeom.h:493
#define TINTYPE
Definition: liblwgeom.h:84
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:395
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:75
#define MULTISURFACETYPE
Definition: liblwgeom.h:81
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
uint8_t type
Definition: liblwgeom.h:380
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:77
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:1297
#define MULTILINETYPE
Definition: liblwgeom.h:74
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:843
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:219
Here is the call graph for this function:
Here is the caller graph for this function: