PostGIS  2.5.0beta1dev-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.

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_clip_by_rect(), LWGEOM_dimension(), lwgeom_node(), and lwgeom_offsetcurve().

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 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:218
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:1287
#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: