PostGIS  2.5.0dev-r@@SVN_REVISION@@
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 1280 of file lwgeom.c.

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

Referenced by LWGEOM_dimension(), and lwgeom_node().

1281 {
1282 
1283  /* Null? Zero. */
1284  if( ! geom ) return -1;
1285 
1286  LWDEBUGF(4, "lwgeom_dimension got type %s",
1287  lwtype_name(geom->type));
1288 
1289  /* Empty? Zero. */
1290  /* if( lwgeom_is_empty(geom) ) return 0; */
1291 
1292  switch (geom->type)
1293  {
1294  case POINTTYPE:
1295  case MULTIPOINTTYPE:
1296  return 0;
1297  case CIRCSTRINGTYPE:
1298  case LINETYPE:
1299  case COMPOUNDTYPE:
1300  case MULTICURVETYPE:
1301  case MULTILINETYPE:
1302  return 1;
1303  case TRIANGLETYPE:
1304  case POLYGONTYPE:
1305  case CURVEPOLYTYPE:
1306  case MULTISURFACETYPE:
1307  case MULTIPOLYGONTYPE:
1308  case TINTYPE:
1309  return 2;
1310  case POLYHEDRALSURFACETYPE:
1311  {
1312  /* A closed polyhedral surface contains a volume. */
1313  int closed = lwpsurface_is_closed((LWPSURFACE*)geom);
1314  return ( closed ? 3 : 2 );
1315  }
1316  case COLLECTIONTYPE:
1317  {
1318  int maxdim = 0;
1319  uint32_t i;
1320  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1321  for( i = 0; i < col->ngeoms; i++ )
1322  {
1323  int dim = lwgeom_dimension(col->geoms[i]);
1324  maxdim = ( dim > maxdim ? dim : maxdim );
1325  }
1326  return maxdim;
1327  }
1328  default:
1329  lwerror("%s: unsupported input geometry type: %s",
1330  __func__, lwtype_name(geom->type));
1331  }
1332  return -1;
1333 }
#define LINETYPE
Definition: liblwgeom.h:85
#define MULTICURVETYPE
Definition: liblwgeom.h:94
#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:506
unsigned int uint32_t
Definition: uthash.h:78
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
LWGEOM ** geoms
Definition: liblwgeom.h:508
#define TINTYPE
Definition: liblwgeom.h:98
int lwpsurface_is_closed(const LWPSURFACE *psurface)
Definition: lwpsurface.c:99
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
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:1280
#define MULTISURFACETYPE
Definition: liblwgeom.h:95
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
uint8_t type
Definition: liblwgeom.h:395
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91
#define MULTILINETYPE
Definition: liblwgeom.h:88
#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
#define COLLECTIONTYPE
Definition: liblwgeom.h:90

Here is the call graph for this function:

Here is the caller graph for this function: