PostGIS  2.5.7dev-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 693 of file lwin_wkb.c.

694 {
695  char wkb_little_endian;
696  uint32_t wkb_type;
697 
698  LWDEBUG(4,"Entered function");
699 
700  /* Fail when handed incorrect starting byte */
701  wkb_little_endian = byte_from_wkb_state(s);
702  if( wkb_little_endian != 1 && wkb_little_endian != 0 )
703  {
704  LWDEBUG(4,"Leaving due to bad first byte!");
705  lwerror("Invalid endian flag value encountered.");
706  return NULL;
707  }
708 
709  /* Check the endianness of our input */
710  s->swap_bytes = LW_FALSE;
711  if( getMachineEndian() == NDR ) /* Machine arch is little */
712  {
713  if ( ! wkb_little_endian ) /* Data is big! */
714  s->swap_bytes = LW_TRUE;
715  }
716  else /* Machine arch is big */
717  {
718  if ( wkb_little_endian ) /* Data is little! */
719  s->swap_bytes = LW_TRUE;
720  }
721 
722  /* Read the type number */
723  wkb_type = integer_from_wkb_state(s);
724  LWDEBUGF(4,"Got WKB type number: 0x%X", wkb_type);
725  lwtype_from_wkb_state(s, wkb_type);
726 
727  /* Read the SRID, if necessary */
728  if( s->has_srid )
729  {
731  /* TODO: warn on explicit UNKNOWN srid ? */
732  LWDEBUGF(4,"Got SRID: %u", s->srid);
733  }
734 
735  /* Do the right thing */
736  switch( s->lwtype )
737  {
738  case POINTTYPE:
739  return (LWGEOM*)lwpoint_from_wkb_state(s);
740  break;
741  case LINETYPE:
742  return (LWGEOM*)lwline_from_wkb_state(s);
743  break;
744  case CIRCSTRINGTYPE:
746  break;
747  case POLYGONTYPE:
748  return (LWGEOM*)lwpoly_from_wkb_state(s);
749  break;
750  case TRIANGLETYPE:
752  break;
753  case CURVEPOLYTYPE:
755  break;
756  case MULTIPOINTTYPE:
757  case MULTILINETYPE:
758  case MULTIPOLYGONTYPE:
759  case COMPOUNDTYPE:
760  case MULTICURVETYPE:
761  case MULTISURFACETYPE:
763  case TINTYPE:
764  case COLLECTIONTYPE:
766  break;
767 
768  /* Unknown type! */
769  default:
770  lwerror("Unsupported geometry type: %s [%d]", lwtype_name(s->lwtype), s->lwtype);
771  }
772 
773  /* Return value to keep compiler happy. */
774  return NULL;
775 
776 }
char * s
Definition: cu_in_wkt.c:23
#define LW_FALSE
Definition: liblwgeom.h:77
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
#define MULTILINETYPE
Definition: liblwgeom.h:89
#define MULTISURFACETYPE
Definition: liblwgeom.h:96
#define LINETYPE
Definition: liblwgeom.h:86
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define TINTYPE
Definition: liblwgeom.h:99
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
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:347
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
#define MULTICURVETYPE
Definition: liblwgeom.h:95
#define TRIANGLETYPE
Definition: liblwgeom.h:98
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
char getMachineEndian(void)
Definition: lwutil.c:327
#define NDR
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
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:275
static LWCURVEPOLY * lwcurvepoly_from_wkb_state(wkb_parse_state *s)
CURVEPOLYTYPE.
Definition: lwin_wkb.c:610
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:511
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:397
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:453
static LWCOLLECTION * lwcollection_from_wkb_state(wkb_parse_state *s)
POLYHEDRALSURFACETYPE.
Definition: lwin_wkb.c:645
static char byte_from_wkb_state(wkb_parse_state *s)
Byte Read a byte and advance the parse state forward.
Definition: lwin_wkb.c:256
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:481
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:144
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:564
unsigned int uint32_t
Definition: uthash.h:78

References byte_from_wkb_state(), CIRCSTRINGTYPE, clamp_srid(), COLLECTIONTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, getMachineEndian(), 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(), lwtype_from_wkb_state(), lwtype_name(), MULTICURVETYPE, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, MULTISURFACETYPE, NDR, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, s, TINTYPE, and TRIANGLETYPE.

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

Here is the call graph for this function:
Here is the caller graph for this function: