PostGIS  2.4.9dev-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 1241 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().

1242 {
1243 
1244  /* Null? Zero. */
1245  if( ! geom ) return -1;
1246 
1247  LWDEBUGF(4, "lwgeom_dimension got type %s",
1248  lwtype_name(geom->type));
1249 
1250  /* Empty? Zero. */
1251  /* if( lwgeom_is_empty(geom) ) return 0; */
1252 
1253  switch (geom->type)
1254  {
1255  case POINTTYPE:
1256  case MULTIPOINTTYPE:
1257  return 0;
1258  case CIRCSTRINGTYPE:
1259  case LINETYPE:
1260  case COMPOUNDTYPE:
1261  case MULTICURVETYPE:
1262  case MULTILINETYPE:
1263  return 1;
1264  case TRIANGLETYPE:
1265  case POLYGONTYPE:
1266  case CURVEPOLYTYPE:
1267  case MULTISURFACETYPE:
1268  case MULTIPOLYGONTYPE:
1269  case TINTYPE:
1270  return 2;
1271  case POLYHEDRALSURFACETYPE:
1272  {
1273  /* A closed polyhedral surface contains a volume. */
1274  int closed = lwpsurface_is_closed((LWPSURFACE*)geom);
1275  return ( closed ? 3 : 2 );
1276  }
1277  case COLLECTIONTYPE:
1278  {
1279  int maxdim = 0, i;
1280  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1281  for( i = 0; i < col->ngeoms; i++ )
1282  {
1283  int dim = lwgeom_dimension(col->geoms[i]);
1284  maxdim = ( dim > maxdim ? dim : maxdim );
1285  }
1286  return maxdim;
1287  }
1288  default:
1289  lwerror("%s: unsupported input geometry type: %s",
1290  __func__, lwtype_name(geom->type));
1291  }
1292  return -1;
1293 }
#define LINETYPE
Definition: liblwgeom.h:86
#define MULTICURVETYPE
Definition: liblwgeom.h:95
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define TRIANGLETYPE
Definition: liblwgeom.h:98
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
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:509
#define TINTYPE
Definition: liblwgeom.h:99
int lwpsurface_is_closed(const LWPSURFACE *psurface)
Definition: lwpsurface.c:99
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
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:1241
#define MULTISURFACETYPE
Definition: liblwgeom.h:96
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
uint8_t type
Definition: liblwgeom.h:396
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
#define MULTILINETYPE
Definition: liblwgeom.h:89
#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:91
Here is the call graph for this function:
Here is the caller graph for this function: