PostGIS  2.2.7dev-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 1192 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().

1193 {
1194 
1195  /* Null? Zero. */
1196  if( ! geom ) return -1;
1197 
1198  LWDEBUGF(4, "lwgeom_dimension got type %s",
1199  lwtype_name(geom->type));
1200 
1201  /* Empty? Zero. */
1202  /* if( lwgeom_is_empty(geom) ) return 0; */
1203 
1204  switch (geom->type)
1205  {
1206  case POINTTYPE:
1207  case MULTIPOINTTYPE:
1208  return 0;
1209  case CIRCSTRINGTYPE:
1210  case LINETYPE:
1211  case COMPOUNDTYPE:
1212  case MULTICURVETYPE:
1213  case MULTILINETYPE:
1214  return 1;
1215  case TRIANGLETYPE:
1216  case POLYGONTYPE:
1217  case CURVEPOLYTYPE:
1218  case MULTISURFACETYPE:
1219  case MULTIPOLYGONTYPE:
1220  case TINTYPE:
1221  return 2;
1222  case POLYHEDRALSURFACETYPE:
1223  {
1224  /* A closed polyhedral surface contains a volume. */
1225  int closed = lwpsurface_is_closed((LWPSURFACE*)geom);
1226  return ( closed ? 3 : 2 );
1227  }
1228  case COLLECTIONTYPE:
1229  {
1230  int maxdim = 0, i;
1231  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1232  for( i = 0; i < col->ngeoms; i++ )
1233  {
1234  int dim = lwgeom_dimension(col->geoms[i]);
1235  maxdim = ( dim > maxdim ? dim : maxdim );
1236  }
1237  return maxdim;
1238  }
1239  default:
1240  lwerror("%s: unsupported input geometry type: %s",
1241  __func__, lwtype_name(geom->type));
1242  }
1243  return -1;
1244 }
#define LINETYPE
Definition: liblwgeom.h:71
#define MULTICURVETYPE
Definition: liblwgeom.h:80
#define POLYGONTYPE
Definition: liblwgeom.h:72
#define CURVEPOLYTYPE
Definition: liblwgeom.h:79
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
#define TRIANGLETYPE
Definition: liblwgeom.h:83
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:82
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
LWGEOM ** geoms
Definition: liblwgeom.h:493
#define TINTYPE
Definition: liblwgeom.h:84
int lwpsurface_is_closed(const LWPSURFACE *psurface)
Definition: lwpsurface.c:86
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:75
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:1192
#define MULTISURFACETYPE
Definition: liblwgeom.h:81
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
uint8_t type
Definition: liblwgeom.h:380
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:77
#define MULTILINETYPE
Definition: liblwgeom.h:74
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76

Here is the call graph for this function:

Here is the caller graph for this function: