PostGIS  2.1.10dev-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 1124 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().

1125 {
1126 
1127  /* Null? Zero. */
1128  if( ! geom ) return -1;
1129 
1130  LWDEBUGF(4, "lwgeom_dimension got type %s",
1131  lwtype_name(geom->type));
1132 
1133  /* Empty? Zero. */
1134  /* if( lwgeom_is_empty(geom) ) return 0; */
1135 
1136  switch (geom->type)
1137  {
1138  case POINTTYPE:
1139  case MULTIPOINTTYPE:
1140  return 0;
1141  case CIRCSTRINGTYPE:
1142  case LINETYPE:
1143  case COMPOUNDTYPE:
1144  case MULTICURVETYPE:
1145  case MULTILINETYPE:
1146  return 1;
1147  case TRIANGLETYPE:
1148  case POLYGONTYPE:
1149  case CURVEPOLYTYPE:
1150  case MULTISURFACETYPE:
1151  case MULTIPOLYGONTYPE:
1152  case TINTYPE:
1153  return 2;
1154  case POLYHEDRALSURFACETYPE:
1155  {
1156  /* A closed polyhedral surface contains a volume. */
1157  int closed = lwpsurface_is_closed((LWPSURFACE*)geom);
1158  return ( closed ? 3 : 2 );
1159  }
1160  case COLLECTIONTYPE:
1161  {
1162  int maxdim = 0, i;
1163  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1164  for( i = 0; i < col->ngeoms; i++ )
1165  {
1166  int dim = lwgeom_dimension(col->geoms[i]);
1167  maxdim = ( dim > maxdim ? dim : maxdim );
1168  }
1169  return maxdim;
1170  }
1171  default:
1172  lwerror("lwgeom_dimension: unsupported input geometry type: %s",
1173  lwtype_name(geom->type));
1174  }
1175  return -1;
1176 }
#define LINETYPE
Definition: liblwgeom.h:61
#define MULTICURVETYPE
Definition: liblwgeom.h:70
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define CURVEPOLYTYPE
Definition: liblwgeom.h:69
#define COMPOUNDTYPE
Definition: liblwgeom.h:68
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
#define TRIANGLETYPE
Definition: liblwgeom.h:73
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:72
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
LWGEOM ** geoms
Definition: liblwgeom.h:465
#define TINTYPE
Definition: liblwgeom.h:74
int lwpsurface_is_closed(const LWPSURFACE *psurface)
Definition: lwpsurface.c:86
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:65
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:1124
#define MULTISURFACETYPE
Definition: liblwgeom.h:71
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
uint8_t type
Definition: liblwgeom.h:352
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:67
#define MULTILINETYPE
Definition: liblwgeom.h:64
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
#define COLLECTIONTYPE
Definition: liblwgeom.h:66

Here is the call graph for this function:

Here is the caller graph for this function: