PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ getSRSbySRID()

char* getSRSbySRID ( int  srid,
bool  short_crs 
)

Definition at line 57 of file lwgeom_export.c.

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

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