PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ lwgeom_homogenize()

LWGEOM* lwgeom_homogenize ( const LWGEOM geom)

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

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(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(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((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(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 }
#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:1069
#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:914
int32_t srid
Definition: liblwgeom.h:401
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:172
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
static LWGEOM * lwcollection_homogenize(const LWCOLLECTION *col)
Definition: lwhomogenize.c:116
LWGEOM ** geoms
Definition: liblwgeom.h:511
#define TINTYPE
Definition: liblwgeom.h:98
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:473
#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
#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:921
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:291
Here is the call graph for this function:
Here is the caller graph for this function: