PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_to_wkb_size()

static size_t lwgeom_to_wkb_size ( const LWGEOM geom,
uint8_t  variant 
)
static

Definition at line 648 of file lwout_wkb.c.

References CIRCSTRINGTYPE, COLLECTIONTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, empty_to_wkb_size(), LINETYPE, lwcollection_to_wkb_size(), lwerror(), lwgeom_is_empty(), lwline_to_wkb_size(), lwpoint_to_wkb_size(), lwpoly_to_wkb_size(), lwtriangle_to_wkb_size(), lwtype_name(), MULTICURVETYPE, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, MULTISURFACETYPE, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, TINTYPE, TRIANGLETYPE, LWGEOM::type, LWCOLLECTION::type, and WKB_EXTENDED.

Referenced by lwcollection_to_wkb_size(), and lwgeom_to_wkb().

649 {
650  size_t size = 0;
651 
652  if ( geom == NULL )
653  return 0;
654 
655  /* Short circuit out empty geometries */
656  if ( (!(variant & WKB_EXTENDED)) && lwgeom_is_empty(geom) )
657  {
658  return empty_to_wkb_size(geom, variant);
659  }
660 
661  switch ( geom->type )
662  {
663  case POINTTYPE:
664  size += lwpoint_to_wkb_size((LWPOINT*)geom, variant);
665  break;
666 
667  /* LineString and CircularString both have points elements */
668  case CIRCSTRINGTYPE:
669  case LINETYPE:
670  size += lwline_to_wkb_size((LWLINE*)geom, variant);
671  break;
672 
673  /* Polygon has nrings and rings elements */
674  case POLYGONTYPE:
675  size += lwpoly_to_wkb_size((LWPOLY*)geom, variant);
676  break;
677 
678  /* Triangle has one ring of three points */
679  case TRIANGLETYPE:
680  size += lwtriangle_to_wkb_size((LWTRIANGLE*)geom, variant);
681  break;
682 
683  /* All these Collection types have ngeoms and geoms elements */
684  case MULTIPOINTTYPE:
685  case MULTILINETYPE:
686  case MULTIPOLYGONTYPE:
687  case COMPOUNDTYPE:
688  case CURVEPOLYTYPE:
689  case MULTICURVETYPE:
690  case MULTISURFACETYPE:
691  case COLLECTIONTYPE:
693  case TINTYPE:
695  break;
696 
697  /* Unknown type! */
698  default:
699  lwerror("Unsupported geometry type: %s [%d]", lwtype_name(geom->type), geom->type);
700  }
701 
702  return size;
703 }
#define LINETYPE
Definition: liblwgeom.h:86
#define MULTICURVETYPE
Definition: liblwgeom.h:95
uint8_t variant
Definition: cu_in_twkb.c:26
#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
#define TINTYPE
Definition: liblwgeom.h:99
static size_t lwpoly_to_wkb_size(const LWPOLY *poly, uint8_t variant)
Definition: lwout_wkb.c:547
#define WKB_EXTENDED
Definition: liblwgeom.h:2076
static size_t empty_to_wkb_size(const LWGEOM *geom, uint8_t variant)
Definition: lwout_wkb.c:291
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
static size_t lwpoint_to_wkb_size(const LWPOINT *pt, uint8_t variant)
Definition: lwout_wkb.c:415
#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
static size_t lwcollection_to_wkb_size(const LWCOLLECTION *col, uint8_t variant)
Definition: lwout_wkb.c:602
static size_t lwtriangle_to_wkb_size(const LWTRIANGLE *tri, uint8_t variant)
Definition: lwout_wkb.c:500
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:1346
#define MULTILINETYPE
Definition: liblwgeom.h:89
static size_t lwline_to_wkb_size(const LWLINE *line, uint8_t variant)
Definition: lwout_wkb.c:461
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: