PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 char *cstr;
290 lwvarlena_t *geojson;
291 if (lwgeom->srid != SRID_UNKNOWN)
292 {
293 const int short_crs = LW_TRUE;
294 srs = GetSRSCacheBySRID(fcinfo, lwgeom->srid, short_crs);
295 }
296 geojson = lwgeom_to_geojson(lwgeom, srs, 15, 0);
297 lwgeom_free(lwgeom);
298 cstr = palloc0(VARSIZE_ANY_EXHDR(geojson) + 1);
299 memcpy(cstr, VARDATA(geojson), VARSIZE_ANY_EXHDR(geojson));
300 PG_RETURN_DATUM(DirectFunctionCall1(jsonb_in, PointerGetDatum(cstr)));
301}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
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

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

Here is the call graph for this function: