PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ getSRSbySRID()

char* getSRSbySRID ( int  SRID,
bool  short_crs 
)

Definition at line 56 of file lwgeom_export.c.

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

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