PostGIS  2.3.7dev-r@@SVN_REVISION@@
char* getSRSbySRID ( int  SRID,
bool  short_crs 
)

Definition at line 55 of file lwgeom_export.c.

Referenced by geography_as_geojson(), geography_as_gml(), LWGEOM_asGeoJson(), LWGEOM_asGML(), and LWGEOM_asX3D().

56 {
57  char query[256];
58  char *srs, *srscopy;
59  int size, err;
60 
61  if (SPI_OK_CONNECT != SPI_connect ())
62  {
63  elog(NOTICE, "getSRSbySRID: could not connect to SPI manager");
64  SPI_finish();
65  return NULL;
66  }
67 
68  if (short_crs)
69  sprintf(query, "SELECT auth_name||':'||auth_srid \
70  FROM spatial_ref_sys WHERE srid='%d'", srid);
71  else
72  sprintf(query, "SELECT 'urn:ogc:def:crs:'||auth_name||'::'||auth_srid \
73  FROM spatial_ref_sys WHERE srid='%d'", srid);
74 
75  err = SPI_exec(query, 1);
76  if ( err < 0 )
77  {
78  elog(NOTICE, "getSRSbySRID: error executing query %d", err);
79  SPI_finish();
80  return NULL;
81  }
82 
83  /* no entry in spatial_ref_sys */
84  if (SPI_processed <= 0)
85  {
86  SPI_finish();
87  return NULL;
88  }
89 
90  /* get result */
91  srs = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
92 
93  /* NULL result */
94  if ( ! srs )
95  {
96  SPI_finish();
97  return NULL;
98  }
99 
100  /* copy result to upper executor context */
101  size = strlen(srs)+1;
102  srscopy = SPI_palloc(size);
103  memcpy(srscopy, srs, size);
104 
105  /* disconnect from SPI */
106  SPI_finish();
107 
108  return srscopy;
109 }

Here is the caller graph for this function: