PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_from_WKB()

Datum LWGEOM_from_WKB ( PG_FUNCTION_ARGS  )

Definition at line 788 of file lwgeom_ogc.c.

789 {
790  bytea *bytea_wkb = PG_GETARG_BYTEA_P(0);
791  int32 srid = 0;
792  GSERIALIZED *geom;
793  LWGEOM *lwgeom;
794  uint8_t *wkb = (uint8_t*)VARDATA(bytea_wkb);
795 
796  lwgeom = lwgeom_from_wkb(wkb, VARSIZE_ANY_EXHDR(bytea_wkb), LW_PARSER_CHECK_ALL);
797  if (!lwgeom)
798  lwpgerror("Unable to parse WKB");
799 
800  geom = geometry_serialize(lwgeom);
801  lwgeom_free(lwgeom);
802  PG_FREE_IF_COPY(bytea_wkb, 0);
803 
804  if ( gserialized_get_srid(geom) != SRID_UNKNOWN )
805  {
806  elog(WARNING, "OGC WKB expected, EWKB provided - use GeometryFromEWKB() for this");
807  }
808 
809  if ( PG_NARGS() > 1 )
810  {
811  srid = PG_GETARG_INT32(1);
812  if ( srid != gserialized_get_srid(geom) )
813  gserialized_set_srid(geom, srid);
814  }
815 
816  PG_RETURN_POINTER(geom);
817 }
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:126
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:138
#define LW_PARSER_CHECK_ALL
Definition: liblwgeom.h:2061
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
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:825
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
unsigned int int32
Definition: shpopen.c:273

References geometry_serialize(), 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: