PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_from_WKB()

Datum LWGEOM_from_WKB ( PG_FUNCTION_ARGS  )

Definition at line 825 of file lwgeom_ogc.c.

References geometry_serialize(), gserialized_get_srid(), gserialized_set_srid(), LW_PARSER_CHECK_ALL, lwgeom_add_bbox(), LWGEOM_asText(), lwgeom_free(), lwgeom_from_wkb(), lwgeom_needs_bbox(), PG_FUNCTION_INFO_V1(), and SRID_UNKNOWN.

Referenced by LWGEOM_from_text().

826 {
827  bytea *bytea_wkb = (bytea*)PG_GETARG_BYTEA_P(0);
828  int32 srid = 0;
829  GSERIALIZED *geom;
830  LWGEOM *lwgeom;
831  uint8_t *wkb = (uint8_t*)VARDATA(bytea_wkb);
832 
833  lwgeom = lwgeom_from_wkb(wkb, VARSIZE(bytea_wkb)-VARHDRSZ, LW_PARSER_CHECK_ALL);
834 
835  if ( lwgeom_needs_bbox(lwgeom) )
836  lwgeom_add_bbox(lwgeom);
837 
838  geom = geometry_serialize(lwgeom);
839  lwgeom_free(lwgeom);
840  PG_FREE_IF_COPY(bytea_wkb, 0);
841 
842  if ( gserialized_get_srid(geom) != SRID_UNKNOWN )
843  {
844  elog(WARNING, "OGC WKB expected, EWKB provided - use GeometryFromEWKB() for this");
845  }
846 
847  if ( PG_NARGS() > 1 )
848  {
849  srid = PG_GETARG_INT32(1);
850  if ( srid != gserialized_get_srid(geom) )
851  gserialized_set_srid(geom, srid);
852  }
853 
854  PG_RETURN_POINTER(geom);
855 }
unsigned int int32
Definition: shpopen.c:273
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
void gserialized_set_srid(GSERIALIZED *s, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:117
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:648
#define LW_PARSER_CHECK_ALL
Definition: liblwgeom.h:2014
LWGEOM * lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
Definition: lwin_wkb.c:772
unsigned char uint8_t
Definition: uthash.h:79
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
Definition: lwgeom.c:1152
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:100
Here is the call graph for this function:
Here is the caller graph for this function: