PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 632 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().

633 {
634  char wkb_little_endian;
635  uint32_t wkb_type;
636 
637  LWDEBUG(4,"Entered function");
638 
639  /* Fail when handed incorrect starting byte */
640  wkb_little_endian = byte_from_wkb_state(s);
641  if( wkb_little_endian != 1 && wkb_little_endian != 0 )
642  {
643  LWDEBUG(4,"Leaving due to bad first byte!");
644  lwerror("Invalid endian flag value encountered.");
645  return NULL;
646  }
647 
648  /* Check the endianness of our input */
649  s->swap_bytes = LW_FALSE;
650  if( getMachineEndian() == NDR ) /* Machine arch is little */
651  {
652  if ( ! wkb_little_endian ) /* Data is big! */
653  s->swap_bytes = LW_TRUE;
654  }
655  else /* Machine arch is big */
656  {
657  if ( wkb_little_endian ) /* Data is little! */
658  s->swap_bytes = LW_TRUE;
659  }
660 
661  /* Read the type number */
662  wkb_type = integer_from_wkb_state(s);
663  LWDEBUGF(4,"Got WKB type number: 0x%X", wkb_type);
664  lwtype_from_wkb_state(s, wkb_type);
665 
666  /* Read the SRID, if necessary */
667  if( s->has_srid )
668  {
670  /* TODO: warn on explicit UNKNOWN srid ? */
671  LWDEBUGF(4,"Got SRID: %u", s->srid);
672  }
673 
674  /* Do the right thing */
675  switch( s->lwtype )
676  {
677  case POINTTYPE:
678  return (LWGEOM*)lwpoint_from_wkb_state(s);
679  break;
680  case LINETYPE:
681  return (LWGEOM*)lwline_from_wkb_state(s);
682  break;
683  case CIRCSTRINGTYPE:
685  break;
686  case POLYGONTYPE:
687  return (LWGEOM*)lwpoly_from_wkb_state(s);
688  break;
689  case TRIANGLETYPE:
690  return (LWGEOM*)lwtriangle_from_wkb_state(s);
691  break;
692  case CURVEPOLYTYPE:
694  break;
695  case MULTIPOINTTYPE:
696  case MULTILINETYPE:
697  case MULTIPOLYGONTYPE:
698  case COMPOUNDTYPE:
699  case MULTICURVETYPE:
700  case MULTISURFACETYPE:
702  case TINTYPE:
703  case COLLECTIONTYPE:
705  break;
706 
707  /* Unknown type! */
708  default:
709  lwerror("Unsupported geometry type: %s [%d]", lwtype_name(s->lwtype), s->lwtype);
710  }
711 
712  /* Return value to keep compiler happy. */
713  return NULL;
714 
715 }
#define LINETYPE
Definition: liblwgeom.h:61
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:326
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:119
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:514
#define MULTICURVETYPE
Definition: liblwgeom.h:70
static LWCURVEPOLY * lwcurvepoly_from_wkb_state(wkb_parse_state *s)
CURVEPOLYTYPE.
Definition: lwin_wkb.c:566
static char byte_from_wkb_state(wkb_parse_state *s)
Byte Read a byte and advance the parse state forward.
Definition: lwin_wkb.c:231
static LWCOLLECTION * lwcollection_from_wkb_state(wkb_parse_state *s)
POLYHEDRALSURFACETYPE.
Definition: lwin_wkb.c:596
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:250
uint32_t lwtype
Definition: lwin_wkb.c:24
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define CURVEPOLYTYPE
Definition: liblwgeom.h:69
#define COMPOUNDTYPE
Definition: liblwgeom.h:68
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
#define NDR
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
#define TRIANGLETYPE
Definition: liblwgeom.h:73
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:72
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:463
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
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:433
#define LW_FALSE
Definition: liblwgeom.h:52
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
#define TINTYPE
Definition: liblwgeom.h:74
char getMachineEndian(void)
Definition: lwutil.c:306
uint32_t srid
Definition: lwin_wkb.c:25
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:65
#define MULTISURFACETYPE
Definition: liblwgeom.h:71
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:408
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:67
#define MULTILINETYPE
Definition: liblwgeom.h:64
#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:363
#define COLLECTIONTYPE
Definition: liblwgeom.h:66

Here is the call graph for this function:

Here is the caller graph for this function: