PostGIS  2.3.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 669 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().

670 {
671  char wkb_little_endian;
672  uint32_t wkb_type;
673 
674  LWDEBUG(4,"Entered function");
675 
676  /* Fail when handed incorrect starting byte */
677  wkb_little_endian = byte_from_wkb_state(s);
678  if( wkb_little_endian != 1 && wkb_little_endian != 0 )
679  {
680  LWDEBUG(4,"Leaving due to bad first byte!");
681  lwerror("Invalid endian flag value encountered.");
682  return NULL;
683  }
684 
685  /* Check the endianness of our input */
686  s->swap_bytes = LW_FALSE;
687  if( getMachineEndian() == NDR ) /* Machine arch is little */
688  {
689  if ( ! wkb_little_endian ) /* Data is big! */
690  s->swap_bytes = LW_TRUE;
691  }
692  else /* Machine arch is big */
693  {
694  if ( wkb_little_endian ) /* Data is little! */
695  s->swap_bytes = LW_TRUE;
696  }
697 
698  /* Read the type number */
699  wkb_type = integer_from_wkb_state(s);
700  LWDEBUGF(4,"Got WKB type number: 0x%X", wkb_type);
701  lwtype_from_wkb_state(s, wkb_type);
702 
703  /* Read the SRID, if necessary */
704  if( s->has_srid )
705  {
707  /* TODO: warn on explicit UNKNOWN srid ? */
708  LWDEBUGF(4,"Got SRID: %u", s->srid);
709  }
710 
711  /* Do the right thing */
712  switch( s->lwtype )
713  {
714  case POINTTYPE:
715  return (LWGEOM*)lwpoint_from_wkb_state(s);
716  break;
717  case LINETYPE:
718  return (LWGEOM*)lwline_from_wkb_state(s);
719  break;
720  case CIRCSTRINGTYPE:
722  break;
723  case POLYGONTYPE:
724  return (LWGEOM*)lwpoly_from_wkb_state(s);
725  break;
726  case TRIANGLETYPE:
727  return (LWGEOM*)lwtriangle_from_wkb_state(s);
728  break;
729  case CURVEPOLYTYPE:
731  break;
732  case MULTIPOINTTYPE:
733  case MULTILINETYPE:
734  case MULTIPOLYGONTYPE:
735  case COMPOUNDTYPE:
736  case MULTICURVETYPE:
737  case MULTISURFACETYPE:
739  case TINTYPE:
740  case COLLECTIONTYPE:
742  break;
743 
744  /* Unknown type! */
745  default:
746  lwerror("Unsupported geometry type: %s [%d]", lwtype_name(s->lwtype), s->lwtype);
747  }
748 
749  /* Return value to keep compiler happy. */
750  return NULL;
751 
752 }
#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:378
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:94
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:631
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: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:502
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:472
#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:358
uint32_t srid
Definition: lwin_wkb.c:42
#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:444
#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:388
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
Here is the call graph for this function:
Here is the caller graph for this function: