PostGIS  2.1.10dev-r@@SVN_REVISION@@
char* getSRSbySRID ( int  srid,
bool  short_crs 
)

Definition at line 39 of file lwgeom_export.c.

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

40 {
41  char query[256];
42  char *srs, *srscopy;
43  int size, err;
44 
45  if (SPI_OK_CONNECT != SPI_connect ())
46  {
47  elog(NOTICE, "getSRSbySRID: could not connect to SPI manager");
48  SPI_finish();
49  return NULL;
50  }
51 
52  if (short_crs)
53  sprintf(query, "SELECT auth_name||':'||auth_srid \
54  FROM spatial_ref_sys WHERE srid='%d'", srid);
55  else
56  sprintf(query, "SELECT 'urn:ogc:def:crs:'||auth_name||'::'||auth_srid \
57  FROM spatial_ref_sys WHERE srid='%d'", srid);
58 
59  err = SPI_exec(query, 1);
60  if ( err < 0 )
61  {
62  elog(NOTICE, "getSRSbySRID: error executing query %d", err);
63  SPI_finish();
64  return NULL;
65  }
66 
67  /* no entry in spatial_ref_sys */
68  if (SPI_processed <= 0)
69  {
70  SPI_finish();
71  return NULL;
72  }
73 
74  /* get result */
75  srs = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
76 
77  /* NULL result */
78  if ( ! srs )
79  {
80  SPI_finish();
81  return NULL;
82  }
83 
84  /* copy result to upper executor context */
85  size = strlen(srs)+1;
86  srscopy = SPI_palloc(size);
87  memcpy(srscopy, srs, size);
88 
89  /* disconnect from SPI */
90  SPI_finish();
91 
92  return srscopy;
93 }

Here is the caller graph for this function: