PostGIS  2.4.9dev-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 676 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().

677 {
678  char wkb_little_endian;
679  uint32_t wkb_type;
680 
681  LWDEBUG(4,"Entered function");
682 
683  /* Fail when handed incorrect starting byte */
684  wkb_little_endian = byte_from_wkb_state(s);
685  if( wkb_little_endian != 1 && wkb_little_endian != 0 )
686  {
687  LWDEBUG(4,"Leaving due to bad first byte!");
688  lwerror("Invalid endian flag value encountered.");
689  return NULL;
690  }
691 
692  /* Check the endianness of our input */
693  s->swap_bytes = LW_FALSE;
694  if( getMachineEndian() == NDR ) /* Machine arch is little */
695  {
696  if ( ! wkb_little_endian ) /* Data is big! */
697  s->swap_bytes = LW_TRUE;
698  }
699  else /* Machine arch is big */
700  {
701  if ( wkb_little_endian ) /* Data is little! */
702  s->swap_bytes = LW_TRUE;
703  }
704 
705  /* Read the type number */
706  wkb_type = integer_from_wkb_state(s);
707  LWDEBUGF(4,"Got WKB type number: 0x%X", wkb_type);
708  lwtype_from_wkb_state(s, wkb_type);
709 
710  /* Read the SRID, if necessary */
711  if( s->has_srid )
712  {
714  /* TODO: warn on explicit UNKNOWN srid ? */
715  LWDEBUGF(4,"Got SRID: %u", s->srid);
716  }
717 
718  /* Do the right thing */
719  switch( s->lwtype )
720  {
721  case POINTTYPE:
722  return (LWGEOM*)lwpoint_from_wkb_state(s);
723  break;
724  case LINETYPE:
725  return (LWGEOM*)lwline_from_wkb_state(s);
726  break;
727  case CIRCSTRINGTYPE:
729  break;
730  case POLYGONTYPE:
731  return (LWGEOM*)lwpoly_from_wkb_state(s);
732  break;
733  case TRIANGLETYPE:
734  return (LWGEOM*)lwtriangle_from_wkb_state(s);
735  break;
736  case CURVEPOLYTYPE:
738  break;
739  case MULTIPOINTTYPE:
740  case MULTILINETYPE:
741  case MULTIPOLYGONTYPE:
742  case COMPOUNDTYPE:
743  case MULTICURVETYPE:
744  case MULTISURFACETYPE:
746  case TINTYPE:
747  case COLLECTIONTYPE:
749  break;
750 
751  /* Unknown type! */
752  default:
753  lwerror("Unsupported geometry type: %s [%d]", lwtype_name(s->lwtype), s->lwtype);
754  }
755 
756  /* Return value to keep compiler happy. */
757  return NULL;
758 
759 }
#define LINETYPE
Definition: liblwgeom.h:86
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:380
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:136
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:555
#define MULTICURVETYPE
Definition: liblwgeom.h:95
static LWCURVEPOLY * lwcurvepoly_from_wkb_state(wkb_parse_state *s)
CURVEPOLYTYPE.
Definition: lwin_wkb.c:601
static char byte_from_wkb_state(wkb_parse_state *s)
Byte Read a byte and advance the parse state forward.
Definition: lwin_wkb.c:248
static LWCOLLECTION * lwcollection_from_wkb_state(wkb_parse_state *s)
POLYHEDRALSURFACETYPE.
Definition: lwin_wkb.c:636
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:267
uint32_t lwtype
Definition: lwin_wkb.c:41
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define NDR
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#define TRIANGLETYPE
Definition: liblwgeom.h:98
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
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:502
unsigned int uint32_t
Definition: uthash.h:78
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
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:472
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
#define TINTYPE
Definition: liblwgeom.h:99
char getMachineEndian(void)
Definition: lwutil.c:360
uint32_t srid
Definition: lwin_wkb.c:42
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define MULTISURFACETYPE
Definition: liblwgeom.h:96
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:444
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
#define MULTILINETYPE
Definition: liblwgeom.h:89
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
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:388
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
Here is the call graph for this function:
Here is the caller graph for this function: