PostGIS  3.0.0dev-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 1271 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(), lwgeom_node(), lwgeom_offsetcurve(), lwgeom_subdivide(), and lwgeom_subdivide_recursive().

1272 {
1273 
1274  /* Null? Zero. */
1275  if( ! geom ) return -1;
1276 
1277  LWDEBUGF(4, "lwgeom_dimension got type %s",
1278  lwtype_name(geom->type));
1279 
1280  /* Empty? Zero. */
1281  /* if( lwgeom_is_empty(geom) ) return 0; */
1282 
1283  switch (geom->type)
1284  {
1285  case POINTTYPE:
1286  case MULTIPOINTTYPE:
1287  return 0;
1288  case CIRCSTRINGTYPE:
1289  case LINETYPE:
1290  case COMPOUNDTYPE:
1291  case MULTICURVETYPE:
1292  case MULTILINETYPE:
1293  return 1;
1294  case TRIANGLETYPE:
1295  case POLYGONTYPE:
1296  case CURVEPOLYTYPE:
1297  case MULTISURFACETYPE:
1298  case MULTIPOLYGONTYPE:
1299  case TINTYPE:
1300  return 2;
1301  case POLYHEDRALSURFACETYPE:
1302  {
1303  /* A closed polyhedral surface contains a volume. */
1304  int closed = lwpsurface_is_closed((LWPSURFACE*)geom);
1305  return ( closed ? 3 : 2 );
1306  }
1307  case COLLECTIONTYPE:
1308  {
1309  int maxdim = 0;
1310  uint32_t i;
1311  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1312  for( i = 0; i < col->ngeoms; i++ )
1313  {
1314  int dim = lwgeom_dimension(col->geoms[i]);
1315  maxdim = ( dim > maxdim ? dim : maxdim );
1316  }
1317  return maxdim;
1318  }
1319  default:
1320  lwerror("%s: unsupported input geometry type: %s",
1321  __func__, lwtype_name(geom->type));
1322  }
1323  return -1;
1324 }
#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:509
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:216
LWGEOM ** geoms
Definition: liblwgeom.h:511
#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:1271
#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
#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: