PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwgeom_from_wkb_state()

LWGEOM * lwgeom_from_wkb_state ( wkb_parse_state s)

Internal function declarations.

GEOMETRY Generic handling for WKB geometries.

The front of every WKB geometry (including those embedded in collections) is an endian byte, a type number and an optional srid number. We handle all those here, then pass to the appropriate handler for the specific type.

Definition at line 658 of file lwin_wkb.c.

References byte_from_wkb_state(), CIRCSTRINGTYPE, clamp_srid(), COLLECTIONTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, getMachineEndian(), wkb_parse_state::has_srid, integer_from_wkb_state(), LINETYPE, LW_FALSE, LW_TRUE, lwcircstring_from_wkb_state(), lwcollection_from_wkb_state(), lwcurvepoly_from_wkb_state(), LWDEBUG, LWDEBUGF, lwerror(), lwline_from_wkb_state(), lwpoint_from_wkb_state(), lwpoly_from_wkb_state(), lwtriangle_from_wkb_state(), wkb_parse_state::lwtype, lwtype_from_wkb_state(), lwtype_name(), MULTICURVETYPE, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, MULTISURFACETYPE, NDR, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, wkb_parse_state::srid, wkb_parse_state::swap_bytes, TINTYPE, and TRIANGLETYPE.

Referenced by lwcollection_from_wkb_state(), lwcurvepoly_from_wkb_state(), and lwgeom_from_wkb().

659 {
660  char wkb_little_endian;
661  uint32_t wkb_type;
662 
663  LWDEBUG(4,"Entered function");
664 
665  /* Fail when handed incorrect starting byte */
666  wkb_little_endian = byte_from_wkb_state(s);
667  if( wkb_little_endian != 1 && wkb_little_endian != 0 )
668  {
669  LWDEBUG(4,"Leaving due to bad first byte!");
670  lwerror("Invalid endian flag value encountered.");
671  return NULL;
672  }
673 
674  /* Check the endianness of our input */
675  s->swap_bytes = LW_FALSE;
676  if( getMachineEndian() == NDR ) /* Machine arch is little */
677  {
678  if ( ! wkb_little_endian ) /* Data is big! */
679  s->swap_bytes = LW_TRUE;
680  }
681  else /* Machine arch is big */
682  {
683  if ( wkb_little_endian ) /* Data is little! */
684  s->swap_bytes = LW_TRUE;
685  }
686 
687  /* Read the type number */
688  wkb_type = integer_from_wkb_state(s);
689  LWDEBUGF(4,"Got WKB type number: 0x%X", wkb_type);
690  lwtype_from_wkb_state(s, wkb_type);
691 
692  /* Read the SRID, if necessary */
693  if( s->has_srid )
694  {
696  /* TODO: warn on explicit UNKNOWN srid ? */
697  LWDEBUGF(4,"Got SRID: %u", s->srid);
698  }
699 
700  /* Do the right thing */
701  switch( s->lwtype )
702  {
703  case POINTTYPE:
704  return (LWGEOM*)lwpoint_from_wkb_state(s);
705  break;
706  case LINETYPE:
707  return (LWGEOM*)lwline_from_wkb_state(s);
708  break;
709  case CIRCSTRINGTYPE:
711  break;
712  case POLYGONTYPE:
713  return (LWGEOM*)lwpoly_from_wkb_state(s);
714  break;
715  case TRIANGLETYPE:
716  return (LWGEOM*)lwtriangle_from_wkb_state(s);
717  break;
718  case CURVEPOLYTYPE:
720  break;
721  case MULTIPOINTTYPE:
722  case MULTILINETYPE:
723  case MULTIPOLYGONTYPE:
724  case COMPOUNDTYPE:
725  case MULTICURVETYPE:
726  case MULTISURFACETYPE:
728  case TINTYPE:
729  case COLLECTIONTYPE:
731  break;
732 
733  /* Unknown type! */
734  default:
735  lwerror("Unsupported geometry type: %s [%d]", lwtype_name(s->lwtype), s->lwtype);
736  }
737 
738  /* Return value to keep compiler happy. */
739  return NULL;
740 
741 }
#define LINETYPE
Definition: liblwgeom.h:71
int clamp_srid(int srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
Definition: lwutil.c:350
static void lwtype_from_wkb_state(wkb_parse_state *s, uint32_t wkb_type)
Take in an unknown kind of wkb type number and ensure it comes out as an extended WKB type number (wi...
Definition: lwin_wkb.c:122
static LWTRIANGLE * lwtriangle_from_wkb_state(wkb_parse_state *s)
TRIANGLE Read a WKB triangle, starting just after the endian byte, type number and optional srid numb...
Definition: lwin_wkb.c:538
#define MULTICURVETYPE
Definition: liblwgeom.h:80
static LWCURVEPOLY * lwcurvepoly_from_wkb_state(wkb_parse_state *s)
CURVEPOLYTYPE.
Definition: lwin_wkb.c:590
static char byte_from_wkb_state(wkb_parse_state *s)
Byte Read a byte and advance the parse state forward.
Definition: lwin_wkb.c:234
static LWCOLLECTION * lwcollection_from_wkb_state(wkb_parse_state *s)
POLYHEDRALSURFACETYPE.
Definition: lwin_wkb.c:620
static uint32_t integer_from_wkb_state(wkb_parse_state *s)
Int32 Read 4-byte integer and advance the parse state forward.
Definition: lwin_wkb.c:253
uint32_t lwtype
Definition: lwin_wkb.c:27
#define POLYGONTYPE
Definition: liblwgeom.h:72
#define CURVEPOLYTYPE
Definition: liblwgeom.h:79
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
#define NDR
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
#define TRIANGLETYPE
Definition: liblwgeom.h:83
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:82
static LWPOLY * lwpoly_from_wkb_state(wkb_parse_state *s)
POLYGON Read a WKB polygon, starting just after the endian byte, type number and optional srid number...
Definition: lwin_wkb.c:485
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
static LWCIRCSTRING * lwcircstring_from_wkb_state(wkb_parse_state *s)
CIRCULARSTRING Read a WKB circularstring, starting just after the endian byte, type number and option...
Definition: lwin_wkb.c:455
#define LW_FALSE
Definition: liblwgeom.h:62
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
#define TINTYPE
Definition: liblwgeom.h:84
char getMachineEndian(void)
Definition: lwutil.c:330
uint32_t srid
Definition: lwin_wkb.c:28
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:75
#define MULTISURFACETYPE
Definition: liblwgeom.h:81
static LWLINE * lwline_from_wkb_state(wkb_parse_state *s)
LINESTRING Read a WKB linestring, starting just after the endian byte, type number and optional srid ...
Definition: lwin_wkb.c:430
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:77
#define MULTILINETYPE
Definition: liblwgeom.h:74
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
static LWPOINT * lwpoint_from_wkb_state(wkb_parse_state *s)
POINT Read a WKB point, starting just after the endian byte, type number and optional srid number...
Definition: lwin_wkb.c:374
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
Here is the call graph for this function:
Here is the caller graph for this function: