PostGIS  2.3.8dev-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 1205 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().

1206 {
1207 
1208  /* Null? Zero. */
1209  if( ! geom ) return -1;
1210 
1211  LWDEBUGF(4, "lwgeom_dimension got type %s",
1212  lwtype_name(geom->type));
1213 
1214  /* Empty? Zero. */
1215  /* if( lwgeom_is_empty(geom) ) return 0; */
1216 
1217  switch (geom->type)
1218  {
1219  case POINTTYPE:
1220  case MULTIPOINTTYPE:
1221  return 0;
1222  case CIRCSTRINGTYPE:
1223  case LINETYPE:
1224  case COMPOUNDTYPE:
1225  case MULTICURVETYPE:
1226  case MULTILINETYPE:
1227  return 1;
1228  case TRIANGLETYPE:
1229  case POLYGONTYPE:
1230  case CURVEPOLYTYPE:
1231  case MULTISURFACETYPE:
1232  case MULTIPOLYGONTYPE:
1233  case TINTYPE:
1234  return 2;
1235  case POLYHEDRALSURFACETYPE:
1236  {
1237  /* A closed polyhedral surface contains a volume. */
1238  int closed = lwpsurface_is_closed((LWPSURFACE*)geom);
1239  return ( closed ? 3 : 2 );
1240  }
1241  case COLLECTIONTYPE:
1242  {
1243  int maxdim = 0, i;
1244  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1245  for( i = 0; i < col->ngeoms; i++ )
1246  {
1247  int dim = lwgeom_dimension(col->geoms[i]);
1248  maxdim = ( dim > maxdim ? dim : maxdim );
1249  }
1250  return maxdim;
1251  }
1252  default:
1253  lwerror("%s: unsupported input geometry type: %s",
1254  __func__, lwtype_name(geom->type));
1255  }
1256  return -1;
1257 }
#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
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:508
#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:1205
#define MULTISURFACETYPE
Definition: liblwgeom.h:95
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
uint8_t type
Definition: liblwgeom.h:395
#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:102
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
Here is the call graph for this function:
Here is the caller graph for this function: