PostGIS  2.5.0dev-r@@SVN_REVISION@@
int lwgeom_is_closed ( const LWGEOM geom)

Return true or false depending on whether a geometry is a linear feature that closes on itself.

Definition at line 1034 of file lwgeom.c.

References CIRCSTRINGTYPE, COMPOUNDTYPE, LWCOLLECTION::geoms, LINETYPE, LW_FALSE, LW_TRUE, lwcircstring_is_closed(), lwcompound_is_closed(), lwgeom_as_lwcollection(), lwgeom_is_collection(), lwgeom_is_empty(), lwline_is_closed(), lwpoly_is_closed(), lwpsurface_is_closed(), lwtin_is_closed(), LWCOLLECTION::ngeoms, POLYGONTYPE, POLYHEDRALSURFACETYPE, TINTYPE, and LWGEOM::type.

Referenced by lwgeom_dimensionality(), and LWGEOM_isclosed().

1035 {
1036  int type = geom->type;
1037 
1038  if( lwgeom_is_empty(geom) )
1039  return LW_FALSE;
1040 
1041  /* Test linear types for closure */
1042  switch (type)
1043  {
1044  case LINETYPE:
1045  return lwline_is_closed((LWLINE*)geom);
1046  case POLYGONTYPE:
1047  return lwpoly_is_closed((LWPOLY*)geom);
1048  case CIRCSTRINGTYPE:
1049  return lwcircstring_is_closed((LWCIRCSTRING*)geom);
1050  case COMPOUNDTYPE:
1051  return lwcompound_is_closed((LWCOMPOUND*)geom);
1052  case TINTYPE:
1053  return lwtin_is_closed((LWTIN*)geom);
1054  case POLYHEDRALSURFACETYPE:
1055  return lwpsurface_is_closed((LWPSURFACE*)geom);
1056  }
1057 
1058  /* Recurse into collections and see if anything is not closed */
1059  if ( lwgeom_is_collection(geom) )
1060  {
1061  LWCOLLECTION *col = lwgeom_as_lwcollection(geom);
1062  uint32_t i;
1063  int closed;
1064  for ( i = 0; i < col->ngeoms; i++ )
1065  {
1066  closed = lwgeom_is_closed(col->geoms[i]);
1067  if ( ! closed )
1068  return LW_FALSE;
1069  }
1070  return LW_TRUE;
1071  }
1072 
1073  /* All non-linear non-collection types we will call closed */
1074  return LW_TRUE;
1075 }
#define LINETYPE
Definition: liblwgeom.h:85
int lwtin_is_closed(const LWTIN *tin)
Definition: lwtin.c:93
#define POLYGONTYPE
Definition: liblwgeom.h:86
#define COMPOUNDTYPE
Definition: liblwgeom.h:92
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:96
int lwcompound_is_closed(const LWCOMPOUND *curve)
Definition: lwcompound.c:35
uint32_t ngeoms
Definition: liblwgeom.h:506
int lwgeom_is_closed(const LWGEOM *geom)
Return true or false depending on whether a geometry is a linear feature that closes on itself...
Definition: lwgeom.c:1034
unsigned int uint32_t
Definition: uthash.h:78
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
LWGEOM ** geoms
Definition: liblwgeom.h:508
int lwpoly_is_closed(const LWPOLY *poly)
Definition: lwpoly.c:504
int lwcircstring_is_closed(const LWCIRCSTRING *curve)
Definition: lwcircstring.c:261
#define TINTYPE
Definition: liblwgeom.h:98
int lwpsurface_is_closed(const LWPSURFACE *psurface)
Definition: lwpsurface.c:99
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:223
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1386
int lwgeom_is_collection(const LWGEOM *geom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1078
int lwline_is_closed(const LWLINE *line)
Definition: lwline.c:454
uint8_t type
Definition: liblwgeom.h:395
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91

Here is the call graph for this function:

Here is the caller graph for this function: