PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwgeom_dimension()

int lwgeom_dimension ( const LWGEOM geom)

For an LWGEOM, returns 0 for points, 1 for lines, 2 for polygons, 3 for volume, and the max dimension of a collection.

Definition at line 1287 of file lwgeom.c.

1288 {
1289 
1290  /* Null? Zero. */
1291  if( ! geom ) return -1;
1292 
1293  LWDEBUGF(4, "lwgeom_dimension got type %s",
1294  lwtype_name(geom->type));
1295 
1296  /* Empty? Zero. */
1297  /* if( lwgeom_is_empty(geom) ) return 0; */
1298 
1299  switch (geom->type)
1300  {
1301  case POINTTYPE:
1302  case MULTIPOINTTYPE:
1303  return 0;
1304  case CIRCSTRINGTYPE:
1305  case LINETYPE:
1306  case COMPOUNDTYPE:
1307  case MULTICURVETYPE:
1308  case MULTILINETYPE:
1309  return 1;
1310  case TRIANGLETYPE:
1311  case POLYGONTYPE:
1312  case CURVEPOLYTYPE:
1313  case MULTISURFACETYPE:
1314  case MULTIPOLYGONTYPE:
1315  case TINTYPE:
1316  return 2;
1317  case POLYHEDRALSURFACETYPE:
1318  {
1319  /* A closed polyhedral surface contains a volume. */
1320  int closed = lwpsurface_is_closed((LWPSURFACE*)geom);
1321  return ( closed ? 3 : 2 );
1322  }
1323  case COLLECTIONTYPE:
1324  {
1325  int maxdim = 0;
1326  uint32_t i;
1327  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1328  for( i = 0; i < col->ngeoms; i++ )
1329  {
1330  int dim = lwgeom_dimension(col->geoms[i]);
1331  maxdim = ( dim > maxdim ? dim : maxdim );
1332  }
1333  return maxdim;
1334  }
1335  default:
1336  lwerror("%s: unsupported input geometry type: %s",
1337  __func__, lwtype_name(geom->type));
1338  }
1339  return -1;
1340 }
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
#define MULTILINETYPE
Definition: liblwgeom.h:89
#define MULTISURFACETYPE
Definition: liblwgeom.h:96
#define LINETYPE
Definition: liblwgeom.h:86
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define TINTYPE
Definition: liblwgeom.h:99
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
#define MULTICURVETYPE
Definition: liblwgeom.h:95
#define TRIANGLETYPE
Definition: liblwgeom.h:98
int lwpsurface_is_closed(const LWPSURFACE *psurface)
Definition: lwpsurface.c:99
int lwgeom_dimension(const LWGEOM *geom)
For an LWGEOM, returns 0 for points, 1 for lines, 2 for polygons, 3 for volume, and the max dimension...
Definition: lwgeom.c:1287
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
uint32_t ngeoms
Definition: liblwgeom.h:510
LWGEOM ** geoms
Definition: liblwgeom.h:512
uint8_t type
Definition: liblwgeom.h:399
unsigned int uint32_t
Definition: uthash.h:78

References CIRCSTRINGTYPE, COLLECTIONTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, LWCOLLECTION::geoms, LINETYPE, LWDEBUGF, lwerror(), lwgeom_dimension(), lwpsurface_is_closed(), lwtype_name(), MULTICURVETYPE, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, MULTISURFACETYPE, LWCOLLECTION::ngeoms, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, TINTYPE, TRIANGLETYPE, and LWGEOM::type.

Referenced by lwgeom_dimension(), LWGEOM_dimension(), lwgeom_node(), lwgeom_offsetcurve(), lwgeom_subdivide(), and lwgeom_subdivide_recursive().

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