PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geometry_to_jsonb()

Datum geometry_to_jsonb ( PG_FUNCTION_ARGS  )

Definition at line 284 of file lwgeom_export.c.

285 {
286  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
287  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
288  const char *srs = NULL;
289  lwvarlena_t *geojson;
290  if (lwgeom->srid != SRID_UNKNOWN)
291  {
292  const int short_crs = LW_TRUE;
293  srs = GetSRSCacheBySRID(fcinfo, lwgeom->srid, short_crs);
294  }
295  geojson = lwgeom_to_geojson(lwgeom, srs, 15, 0);
296  lwgeom_free(lwgeom);
297  PG_RETURN_DATUM(DirectFunctionCall1(jsonb_in, PointerGetDatum(pstrdup(geojson->data))));
298 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
lwvarlena_t * lwgeom_to_geojson(const LWGEOM *geo, const char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
int32_t srid
Definition: liblwgeom.h:460
char data[]
Definition: liblwgeom.h:308

References lwvarlena_t::data, LW_TRUE, lwgeom_free(), lwgeom_from_gserialized(), lwgeom_to_geojson(), LWGEOM::srid, and SRID_UNKNOWN.

Here is the call graph for this function: