PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_from_WKB()

Datum LWGEOM_from_WKB ( PG_FUNCTION_ARGS  )

Definition at line 930 of file lwgeom_ogc.c.

931 {
932  bytea *bytea_wkb = PG_GETARG_BYTEA_P(0);
933  int32 srid = 0;
934  GSERIALIZED *geom;
935  LWGEOM *lwgeom;
936  uint8_t *wkb = (uint8_t*)VARDATA(bytea_wkb);
937 
938  lwgeom = lwgeom_from_wkb(wkb, VARSIZE_ANY_EXHDR(bytea_wkb), LW_PARSER_CHECK_ALL);
939  if (!lwgeom)
940  lwpgerror("Unable to parse WKB");
941 
942  geom = geometry_serialize(lwgeom);
943  lwgeom_free(lwgeom);
944  PG_FREE_IF_COPY(bytea_wkb, 0);
945 
946  if ( gserialized_get_srid(geom) != SRID_UNKNOWN )
947  {
948  elog(WARNING, "OGC WKB expected, EWKB provided - use GeometryFromEWKB() for this");
949  }
950 
951  if ( PG_NARGS() > 1 )
952  {
953  srid = PG_GETARG_INT32(1);
954  if ( srid != gserialized_get_srid(geom) )
955  gserialized_set_srid(geom, srid);
956  }
957 
958  PG_RETURN_POINTER(geom);
959 }
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:155
void gserialized_set_srid(GSERIALIZED *g, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function).
Definition: gserialized.c:167
#define LW_PARSER_CHECK_ALL
Definition: liblwgeom.h:2147
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
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:842
unsigned int int32
Definition: shpopen.c:54

References gserialized_get_srid(), gserialized_set_srid(), LW_PARSER_CHECK_ALL, lwgeom_free(), lwgeom_from_wkb(), and SRID_UNKNOWN.

Here is the call graph for this function: