PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwgeom_from_twkb_state()

LWGEOM * lwgeom_from_twkb_state ( twkb_parse_state s)

Internal function declarations.

Generic handling for TWKB geometries.

The front of every TWKB geometry (including those embedded in collections) is a type byte and metadata byte, then optional size, bbox, etc. Read those, then switch to particular type handling code.

Definition at line 562 of file lwin_twkb.c.

563 {
564  GBOX bbox;
565  LWGEOM *geom = NULL;
566  uint32_t has_bbox = LW_FALSE;
567  int i;
568 
569  /* Read the first two bytes, and optional */
570  /* extended precision info and optional size info */
572 
573  /* Just experienced a geometry header, so now we */
574  /* need to reset our coordinate deltas */
575  for ( i = 0; i < TWKB_IN_MAXCOORDS; i++ )
576  {
577  s->coords[i] = 0.0;
578  }
579 
580  /* Read the bounding box, is there is one */
581  if ( s->has_bbox )
582  {
583  /* Initialize */
584  has_bbox = s->has_bbox;
585  memset(&bbox, 0, sizeof(GBOX));
586  bbox.flags = gflags(s->has_z, s->has_m, 0);
587 
588  /* X */
589  bbox.xmin = twkb_parse_state_double(s, s->factor);
590  bbox.xmax = bbox.xmin + twkb_parse_state_double(s, s->factor);
591  /* Y */
592  bbox.ymin = twkb_parse_state_double(s, s->factor);
593  bbox.ymax = bbox.ymin + twkb_parse_state_double(s, s->factor);
594  /* Z */
595  if ( s->has_z )
596  {
597  bbox.zmin = twkb_parse_state_double(s, s->factor_z);
598  bbox.zmax = bbox.zmin + twkb_parse_state_double(s, s->factor_z);
599  }
600  /* M */
601  if ( s->has_m )
602  {
603  bbox.mmin = twkb_parse_state_double(s, s->factor_m);
604  bbox.mmax = bbox.mmin + twkb_parse_state_double(s, s->factor_m);
605  }
606  }
607 
608  /* Switch to code for the particular type we're dealing with */
609  switch( s->lwtype )
610  {
611  case POINTTYPE:
613  break;
614  case LINETYPE:
616  break;
617  case POLYGONTYPE:
619  break;
620  case MULTIPOINTTYPE:
622  break;
623  case MULTILINETYPE:
625  break;
626  case MULTIPOLYGONTYPE:
628  break;
629  case COLLECTIONTYPE:
631  break;
632  /* Unknown type! */
633  default:
634  lwerror("Unsupported geometry type: %s [%d]", lwtype_name(s->lwtype), s->lwtype);
635  break;
636  }
637 
638  if ( has_bbox )
639  {
640  geom->bbox = gbox_clone(&bbox);
641  }
642 
643  return geom;
644 }
char * s
Definition: cu_in_wkt.c:23
GBOX * gbox_clone(const GBOX *gbox)
Definition: g_box.c:52
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:330
#define LW_FALSE
Definition: liblwgeom.h:77
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:300
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
#define MULTILINETYPE
Definition: liblwgeom.h:89
#define LINETYPE
Definition: liblwgeom.h:86
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:320
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
#define POLYGONTYPE
Definition: liblwgeom.h:87
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static LWCOLLECTION * lwmultipoly_from_twkb_state(twkb_parse_state *s)
MULTIPOLYGON.
Definition: lwin_twkb.c:413
#define TWKB_IN_MAXCOORDS
Definition: lwin_twkb.c:31
static double twkb_parse_state_double(twkb_parse_state *s, double factor)
Definition: lwin_twkb.c:109
static void header_from_twkb_state(twkb_parse_state *s)
Definition: lwin_twkb.c:490
static LWPOLY * lwpoly_from_twkb_state(twkb_parse_state *s)
POLYGON.
Definition: lwin_twkb.c:272
static LWCOLLECTION * lwmultiline_from_twkb_state(twkb_parse_state *s)
MULTILINESTRING.
Definition: lwin_twkb.c:374
static LWCOLLECTION * lwmultipoint_from_twkb_state(twkb_parse_state *s)
MULTIPOINT.
Definition: lwin_twkb.c:336
static LWCOLLECTION * lwcollection_from_twkb_state(twkb_parse_state *s)
COLLECTION, MULTIPOINTTYPE, MULTILINETYPE, MULTIPOLYGONTYPE.
Definition: lwin_twkb.c:452
static LWPOINT * lwpoint_from_twkb_state(twkb_parse_state *s)
POINT.
Definition: lwin_twkb.c:221
static LWLINE * lwline_from_twkb_state(twkb_parse_state *s)
LINESTRING.
Definition: lwin_twkb.c:238
double ymax
Definition: liblwgeom.h:298
double zmax
Definition: liblwgeom.h:300
double xmax
Definition: liblwgeom.h:296
double zmin
Definition: liblwgeom.h:299
double mmax
Definition: liblwgeom.h:302
double ymin
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:295
double mmin
Definition: liblwgeom.h:301
uint8_t flags
Definition: liblwgeom.h:294
GBOX * bbox
Definition: liblwgeom.h:401
unsigned int uint32_t
Definition: uthash.h:78

References LWGEOM::bbox, COLLECTIONTYPE, GBOX::flags, gbox_clone(), gflags(), header_from_twkb_state(), LINETYPE, LW_FALSE, lwcollection_as_lwgeom(), lwcollection_from_twkb_state(), lwerror(), lwline_as_lwgeom(), lwline_from_twkb_state(), lwmultiline_from_twkb_state(), lwmultipoint_from_twkb_state(), lwmultipoly_from_twkb_state(), lwpoint_as_lwgeom(), lwpoint_from_twkb_state(), lwpoly_as_lwgeom(), lwpoly_from_twkb_state(), lwtype_name(), GBOX::mmax, GBOX::mmin, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, POINTTYPE, POLYGONTYPE, s, TWKB_IN_MAXCOORDS, twkb_parse_state_double(), GBOX::xmax, GBOX::xmin, GBOX::ymax, GBOX::ymin, GBOX::zmax, and GBOX::zmin.

Referenced by lwcollection_from_twkb_state(), and lwgeom_from_twkb().

Here is the call graph for this function:
Here is the caller graph for this function: