PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ geography_as_geojson()

Datum geography_as_geojson ( PG_FUNCTION_ARGS  )

Definition at line 432 of file geography_inout.c.

433 {
434  char *geojson;
435  text *result;
436  int has_bbox = 0;
437  char * srs = NULL;
438  GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
439  int precision = PG_GETARG_INT32(1);
440  int option = PG_GETARG_INT32(2);
441  LWGEOM *lwgeom = lwgeom_from_gserialized(g);
442 
443  if (precision > DBL_DIG)
444  precision = DBL_DIG;
445  if (precision < 0)
446  precision = 0;
447 
448  /* Retrieve output option
449  * 0 = without option (default)
450  * 1 = bbox
451  * 2 = short crs
452  * 4 = long crs
453  */
454 
455  if (option & 2 || option & 4)
456  {
457  /* Geography only handle srid SRID_DEFAULT */
458  if (option & 2)
459  srs = getSRSbySRID(fcinfo, SRID_DEFAULT, true);
460  if (option & 4)
461  srs = getSRSbySRID(fcinfo, SRID_DEFAULT, false);
462 
463  if (!srs)
464  {
465  elog(ERROR, "SRID SRID_DEFAULT unknown in spatial_ref_sys table");
466  PG_RETURN_NULL();
467  }
468  }
469 
470  if (option & 1) has_bbox = 1;
471 
472  geojson = lwgeom_to_geojson(lwgeom, srs, precision, has_bbox);
473  lwgeom_free(lwgeom);
474  PG_FREE_IF_COPY(g, 0);
475  if (srs) pfree(srs);
476 
477  result = cstring_to_text(geojson);
478  lwfree(geojson);
479 
480  PG_RETURN_TEXT_P(result);
481 }
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:1138
void lwfree(void *mem)
Definition: lwutil.c:242
#define SRID_DEFAULT
Definition: liblwgeom.h:239
char * lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
Definition: lwout_geojson.c:49
char * getSRSbySRID(FunctionCallInfo fcinfo, int32_t srid, bool short_crs)
Definition: lwgeom_export.c:66

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

Here is the call graph for this function: