PostGIS  3.7.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 743 of file lwin_wkb.c.

744 {
745  char wkb_little_endian;
746  uint32_t wkb_type;
747 
748  LWDEBUG(4,"Entered function");
749 
750  /* Fail when handed incorrect starting byte */
751  wkb_little_endian = byte_from_wkb_state(s);
752  if (s->error)
753  return NULL;
754  if( wkb_little_endian != 1 && wkb_little_endian != 0 )
755  {
756  LWDEBUG(4,"Leaving due to bad first byte!");
757  lwerror("Invalid endian flag value encountered.");
758  return NULL;
759  }
760 
761  /* Check the endianness of our input */
762  s->swap_bytes = LW_FALSE;
763 
764  /* Machine arch is big endian, request is for little */
765  if (IS_BIG_ENDIAN && wkb_little_endian)
766  s->swap_bytes = LW_TRUE;
767  /* Machine arch is little endian, request is for big */
768  else if ((!IS_BIG_ENDIAN) && (!wkb_little_endian))
769  s->swap_bytes = LW_TRUE;
770 
771  /* Read the type number */
772  wkb_type = integer_from_wkb_state(s);
773  if (s->error)
774  return NULL;
775  LWDEBUGF(4,"Got WKB type number: 0x%X", wkb_type);
776  lwtype_from_wkb_state(s, wkb_type);
777 
778  /* Read the SRID, if necessary */
779  if( s->has_srid )
780  {
782  if (s->error)
783  return NULL;
784  /* TODO: warn on explicit UNKNOWN srid ? */
785  LWDEBUGF(4,"Got SRID: %u", s->srid);
786  }
787 
788  /* Do the right thing */
789  switch( s->lwtype )
790  {
791  case POINTTYPE:
792  return (LWGEOM*)lwpoint_from_wkb_state(s);
793  break;
794  case LINETYPE:
795  return (LWGEOM*)lwline_from_wkb_state(s);
796  break;
797  case CIRCSTRINGTYPE:
799  break;
800  case POLYGONTYPE:
801  return (LWGEOM*)lwpoly_from_wkb_state(s);
802  break;
803  case TRIANGLETYPE:
805  break;
806  case CURVEPOLYTYPE:
808  break;
809  case MULTIPOINTTYPE:
810  case MULTILINETYPE:
811  case MULTIPOLYGONTYPE:
812  case COMPOUNDTYPE:
813  case MULTICURVETYPE:
814  case MULTISURFACETYPE:
816  case TINTYPE:
817  case COLLECTIONTYPE:
819  break;
820 
821  /* Unknown type! */
822  default:
823  lwerror("%s: Unsupported geometry type: %s", __func__, lwtype_name(s->lwtype));
824  }
825 
826  /* Return value to keep compiler happy. */
827  return NULL;
828 
829 }
char * s
Definition: cu_in_wkt.c:23
#define IS_BIG_ENDIAN
Definition: liblwgeom.h:326
#define LW_FALSE
Definition: liblwgeom.h:94
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
#define COMPOUNDTYPE
Definition: liblwgeom.h:110
#define CURVEPOLYTYPE
Definition: liblwgeom.h:111
#define MULTILINETYPE
Definition: liblwgeom.h:106
#define MULTISURFACETYPE
Definition: liblwgeom.h:113
#define LINETYPE
Definition: liblwgeom.h:103
#define MULTIPOINTTYPE
Definition: liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
#define TINTYPE
Definition: liblwgeom.h:116
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:107
#define POLYGONTYPE
Definition: liblwgeom.h:104
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:114
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:109
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
#define MULTICURVETYPE
Definition: liblwgeom.h:112
#define TRIANGLETYPE
Definition: liblwgeom.h:115
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
int32_t clamp_srid(int32_t srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
Definition: lwutil.c:339
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:101
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:106
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
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:285
static LWCURVEPOLY * lwcurvepoly_from_wkb_state(wkb_parse_state *s)
CURVEPOLYTYPE.
Definition: lwin_wkb.c:648
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:538
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:413
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:471
static LWCOLLECTION * lwcollection_from_wkb_state(wkb_parse_state *s)
POLYHEDRALSURFACETYPE.
Definition: lwin_wkb.c:693
static char byte_from_wkb_state(wkb_parse_state *s)
Byte Read a byte and advance the parse state forward.
Definition: lwin_wkb.c:264
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:502
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:145
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:603

References byte_from_wkb_state(), CIRCSTRINGTYPE, clamp_srid(), COLLECTIONTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, integer_from_wkb_state(), IS_BIG_ENDIAN, 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, 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: