PostGIS  2.2.8dev-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 548 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().

549 {
550  GBOX bbox;
551  LWGEOM *geom = NULL;
552  uint32_t has_bbox = LW_FALSE;
553  int i;
554 
555  /* Read the first two bytes, and optional */
556  /* extended precision info and optional size info */
558 
559  /* Just experienced a geometry header, so now we */
560  /* need to reset our coordinate deltas */
561  for ( i = 0; i < TWKB_IN_MAXCOORDS; i++ )
562  {
563  s->coords[i] = 0.0;
564  }
565 
566  /* Read the bounding box, is there is one */
567  if ( s->has_bbox )
568  {
569  /* Initialize */
570  has_bbox = s->has_bbox;
571  memset(&bbox, 0, sizeof(GBOX));
572  bbox.flags = gflags(s->has_z, s->has_m, 0);
573 
574  /* X */
575  bbox.xmin = twkb_parse_state_double(s, s->factor);
576  bbox.xmax = bbox.xmin + twkb_parse_state_double(s, s->factor);
577  /* Y */
578  bbox.ymin = twkb_parse_state_double(s, s->factor);
579  bbox.ymax = bbox.ymin + twkb_parse_state_double(s, s->factor);
580  /* Z */
581  if ( s->has_z )
582  {
583  bbox.zmin = twkb_parse_state_double(s, s->factor_z);
584  bbox.zmax = bbox.zmin + twkb_parse_state_double(s, s->factor_z);
585  }
586  /* M */
587  if ( s->has_z )
588  {
589  bbox.mmin = twkb_parse_state_double(s, s->factor_m);
590  bbox.mmax = bbox.mmin + twkb_parse_state_double(s, s->factor_m);
591  }
592  }
593 
594  /* Switch to code for the particular type we're dealing with */
595  switch( s->lwtype )
596  {
597  case POINTTYPE:
599  break;
600  case LINETYPE:
602  break;
603  case POLYGONTYPE:
605  break;
606  case MULTIPOINTTYPE:
608  break;
609  case MULTILINETYPE:
611  break;
612  case MULTIPOLYGONTYPE:
614  break;
615  case COLLECTIONTYPE:
617  break;
618  /* Unknown type! */
619  default:
620  lwerror("Unsupported geometry type: %s [%d]", lwtype_name(s->lwtype), s->lwtype);
621  break;
622  }
623 
624  if ( has_bbox )
625  {
626  geom->bbox = gbox_clone(&bbox);
627  }
628 
629  return geom;
630 }
#define LINETYPE
Definition: liblwgeom.h:71
uint8_t has_z
Definition: lwin_twkb.c:35
double factor_z
Definition: lwin_twkb.c:41
GBOX * bbox
Definition: liblwgeom.h:382
static LWLINE * lwline_from_twkb_state(twkb_parse_state *s)
LINESTRING.
Definition: lwin_twkb.c:224
static LWCOLLECTION * lwcollection_from_twkb_state(twkb_parse_state *s)
COLLECTION, MULTIPOINTTYPE, MULTILINETYPE, MULTIPOLYGONTYPE.
Definition: lwin_twkb.c:438
#define POLYGONTYPE
Definition: liblwgeom.h:72
double xmax
Definition: liblwgeom.h:277
uint8_t has_m
Definition: lwin_twkb.c:36
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
static LWPOLY * lwpoly_from_twkb_state(twkb_parse_state *s)
POLYGON.
Definition: lwin_twkb.c:258
uint8_t has_bbox
Definition: lwin_twkb.c:32
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:239
double zmax
Definition: liblwgeom.h:281
double ymin
Definition: liblwgeom.h:278
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:249
#define TWKB_IN_MAXCOORDS
Definition: lwin_twkb.c:17
double xmin
Definition: liblwgeom.h:276
#define LW_FALSE
Definition: liblwgeom.h:62
int64_t * coords
Definition: lwin_twkb.c:51
uint32_t lwtype
Definition: lwin_twkb.c:30
double factor_m
Definition: lwin_twkb.c:42
double ymax
Definition: liblwgeom.h:279
static LWCOLLECTION * lwmultipoint_from_twkb_state(twkb_parse_state *s)
MULTIPOINT.
Definition: lwin_twkb.c:322
uint8_t flags
Definition: liblwgeom.h:275
static LWCOLLECTION * lwmultipoly_from_twkb_state(twkb_parse_state *s)
MULTIPOLYGON.
Definition: lwin_twkb.c:399
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:130
static LWPOINT * lwpoint_from_twkb_state(twkb_parse_state *s)
POINT.
Definition: lwin_twkb.c:207
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:75
static double twkb_parse_state_double(twkb_parse_state *s, double factor)
Definition: lwin_twkb.c:95
double mmin
Definition: liblwgeom.h:282
double zmin
Definition: liblwgeom.h:280
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
double mmax
Definition: liblwgeom.h:283
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:254
GBOX * gbox_clone(const GBOX *gbox)
Definition: g_box.c:41
static LWCOLLECTION * lwmultiline_from_twkb_state(twkb_parse_state *s)
MULTILINESTRING.
Definition: lwin_twkb.c:360
static void header_from_twkb_state(twkb_parse_state *s)
Definition: lwin_twkb.c:476
#define MULTILINETYPE
Definition: liblwgeom.h:74
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:219
Here is the call graph for this function:
Here is the caller graph for this function: