PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geometry_to_json()

Datum geometry_to_json ( PG_FUNCTION_ARGS  )

Definition at line 266 of file lwgeom_export.c.

267 {
268  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
269  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
270  const char *srs = NULL;
271  lwvarlena_t *geojson;
272  if (lwgeom->srid != SRID_UNKNOWN)
273  {
274  const int short_crs = LW_TRUE;
275  srs = GetSRSCacheBySRID(fcinfo, lwgeom->srid, short_crs);
276  }
277  geojson = lwgeom_to_geojson(lwgeom, srs, 15, 0);
278  lwgeom_free(lwgeom);
279  PG_FREE_IF_COPY(geom, 0);
280  PG_RETURN_TEXT_P(geojson);
281 }
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

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

Here is the call graph for this function: