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

Definition at line 40 of file lwgeom_export.c.

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

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

Here is the caller graph for this function: