PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_homogenize()

LWGEOM* lwgeom_homogenize ( const LWGEOM geom)

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

210 {
211  LWGEOM *hgeom;
212 
213  /* EMPTY Geometry */
214  if (lwgeom_is_empty(geom))
215  {
216  if( lwgeom_is_collection(geom) )
217  {
219  }
220 
221  return lwgeom_clone(geom);
222  }
223 
224  switch (geom->type)
225  {
226 
227  /* Return simple geometries untouched */
228  case POINTTYPE:
229  case LINETYPE:
230  case CIRCSTRINGTYPE:
231  case COMPOUNDTYPE:
232  case TRIANGLETYPE:
233  case CURVEPOLYTYPE:
234  case POLYGONTYPE:
235  return lwgeom_clone(geom);
236 
237  /* Process homogeneous geometries lightly */
238  case MULTIPOINTTYPE:
239  case MULTILINETYPE:
240  case MULTIPOLYGONTYPE:
241  case MULTICURVETYPE:
242  case MULTISURFACETYPE:
244  case TINTYPE:
245  {
246  LWCOLLECTION *col = (LWCOLLECTION*)geom;
247 
248  /* Strip single-entry multi-geometries down to singletons */
249  if ( col->ngeoms == 1 )
250  {
251  hgeom = lwgeom_clone((LWGEOM*)(col->geoms[0]));
252  hgeom->srid = geom->srid;
253  if (geom->bbox)
254  hgeom->bbox = gbox_copy(geom->bbox);
255  return hgeom;
256  }
257 
258  /* Return proper multigeometry untouched */
259  return lwgeom_clone(geom);
260  }
261 
262  /* Work on anonymous collections separately */
263  case COLLECTIONTYPE:
264  return lwcollection_homogenize((LWCOLLECTION *) geom);
265  }
266 
267  /* Unknown type */
268  lwerror("lwgeom_homogenize: Geometry Type not supported (%i)",
269  lwtype_name(geom->type));
270 
271  return NULL; /* Never get here! */
272 }
#define LINETYPE
Definition: liblwgeom.h:86
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:438
GBOX * bbox
Definition: liblwgeom.h:398
#define MULTICURVETYPE
Definition: liblwgeom.h:95
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1040
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define TRIANGLETYPE
Definition: liblwgeom.h:98
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:885
int32_t srid
Definition: liblwgeom.h:399
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:117
LWGEOM ** geoms
Definition: liblwgeom.h:509
#define TINTYPE
Definition: liblwgeom.h:99
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:444
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define MULTISURFACETYPE
Definition: liblwgeom.h:96
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
uint8_t type
Definition: liblwgeom.h:396
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
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:1346
#define MULTILINETYPE
Definition: liblwgeom.h:89
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:892
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:268
Here is the call graph for this function:
Here is the caller graph for this function: