PostGIS  3.0.0dev-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 674 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().

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