PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ getSRSbySRID()

char* getSRSbySRID ( FunctionCallInfo  fcinfo,
int  srid,
bool  short_crs 
)

Definition at line 60 of file lwgeom_export.c.

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

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

Here is the caller graph for this function: