PostGIS  2.5.1dev-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.

References LWGEOM::bbox, COLLECTIONTYPE, twkb_parse_state::coords, twkb_parse_state::factor, twkb_parse_state::factor_m, twkb_parse_state::factor_z, GBOX::flags, gbox_clone(), gflags(), twkb_parse_state::has_bbox, twkb_parse_state::has_m, twkb_parse_state::has_z, 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(), twkb_parse_state::lwtype, lwtype_name(), GBOX::mmax, GBOX::mmin, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, POINTTYPE, POLYGONTYPE, 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().

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 }
#define LINETYPE
Definition: liblwgeom.h:85
uint8_t has_z
Definition: lwin_twkb.c:49
double factor_z
Definition: lwin_twkb.c:55
GBOX * bbox
Definition: liblwgeom.h:400
static LWLINE * lwline_from_twkb_state(twkb_parse_state *s)
LINESTRING.
Definition: lwin_twkb.c:238
static LWCOLLECTION * lwcollection_from_twkb_state(twkb_parse_state *s)
COLLECTION, MULTIPOINTTYPE, MULTILINETYPE, MULTIPOLYGONTYPE.
Definition: lwin_twkb.c:452
#define POLYGONTYPE
Definition: liblwgeom.h:86
double xmax
Definition: liblwgeom.h:295
uint8_t has_m
Definition: lwin_twkb.c:50
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
static LWPOLY * lwpoly_from_twkb_state(twkb_parse_state *s)
POLYGON.
Definition: lwin_twkb.c:272
uint8_t has_bbox
Definition: lwin_twkb.c:46
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:320
unsigned int uint32_t
Definition: uthash.h:78
double zmax
Definition: liblwgeom.h:299
double ymin
Definition: liblwgeom.h:296
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:330
#define TWKB_IN_MAXCOORDS
Definition: lwin_twkb.c:31
double xmin
Definition: liblwgeom.h:294
#define LW_FALSE
Definition: liblwgeom.h:76
int64_t * coords
Definition: lwin_twkb.c:65
uint32_t lwtype
Definition: lwin_twkb.c:44
double factor_m
Definition: lwin_twkb.c:56
double ymax
Definition: liblwgeom.h:297
static LWCOLLECTION * lwmultipoint_from_twkb_state(twkb_parse_state *s)
MULTIPOINT.
Definition: lwin_twkb.c:336
uint8_t flags
Definition: liblwgeom.h:293
static LWCOLLECTION * lwmultipoly_from_twkb_state(twkb_parse_state *s)
MULTIPOLYGON.
Definition: lwin_twkb.c:413
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
static LWPOINT * lwpoint_from_twkb_state(twkb_parse_state *s)
POINT.
Definition: lwin_twkb.c:221
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
static double twkb_parse_state_double(twkb_parse_state *s, double factor)
Definition: lwin_twkb.c:109
double mmin
Definition: liblwgeom.h:300
double zmin
Definition: liblwgeom.h:298
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
double mmax
Definition: liblwgeom.h:301
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
GBOX * gbox_clone(const GBOX *gbox)
Definition: g_box.c:52
static LWCOLLECTION * lwmultiline_from_twkb_state(twkb_parse_state *s)
MULTILINESTRING.
Definition: lwin_twkb.c:374
static void header_from_twkb_state(twkb_parse_state *s)
Definition: lwin_twkb.c:490
#define MULTILINETYPE
Definition: liblwgeom.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:300
Here is the call graph for this function:
Here is the caller graph for this function: