PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geography_as_geojson()

Datum geography_as_geojson ( PG_FUNCTION_ARGS  )

Definition at line 387 of file geography_inout.c.

388 {
389  lwvarlena_t *geojson;
390  int has_bbox = 0;
391  const char *srs = NULL;
392  GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
393  int precision = PG_GETARG_INT32(1);
394  int option = PG_GETARG_INT32(2);
395  LWGEOM *lwgeom = lwgeom_from_gserialized(g);
396 
397  if (precision < 0)
398  precision = 0;
399 
400  /* Retrieve output option
401  * 0 = without option (default)
402  * 1 = bbox
403  * 2 = short crs
404  * 4 = long crs
405  */
406 
407  if (option & 2 || option & 4)
408  {
409  /* Geography only handle srid SRID_DEFAULT */
410  if (option & 2)
411  srs = GetSRSCacheBySRID(fcinfo, SRID_DEFAULT, true);
412  if (option & 4)
413  srs = GetSRSCacheBySRID(fcinfo, SRID_DEFAULT, false);
414 
415  if (!srs)
416  {
417  elog(ERROR, "SRID SRID_DEFAULT unknown in spatial_ref_sys table");
418  PG_RETURN_NULL();
419  }
420  }
421 
422  if (option & 1) has_bbox = 1;
423 
424  geojson = lwgeom_to_geojson(lwgeom, srs, precision, has_bbox);
425  lwgeom_free(lwgeom);
426  PG_FREE_IF_COPY(g, 0);
427 
428  PG_RETURN_TEXT_P(geojson);
429 }
static uint8_t precision
Definition: cu_in_twkb.c:25
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 SRID_DEFAULT
Definition: liblwgeom.h:225

References lwgeom_free(), lwgeom_from_gserialized(), lwgeom_to_geojson(), precision, and SRID_DEFAULT.

Here is the call graph for this function: