PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ getSRIDbySRS()

int getSRIDbySRS ( FunctionCallInfo  fcinfo,
const char *  srs 
)

Definition at line 133 of file lwgeom_export.c.

134 {
135  static const int16_t max_query_size = 512;
136  char query[512];
137  Oid argtypes[] = {CSTRINGOID};
138  Datum values[] = {CStringGetDatum(srs)};
139  int32_t srid, err;
140 
141  postgis_initialize_cache(fcinfo);
142  snprintf(query,
143  max_query_size,
144  "SELECT srid "
145  "FROM %s, "
146  "regexp_matches($1::text, E'([a-z]+):([0-9]+)', 'gi') AS re "
147  "WHERE re[1] ILIKE auth_name AND int4(re[2]) = auth_srid",
148  postgis_spatial_ref_sys());
149 
150  if (!srs) return 0;
151 
152  if (SPI_OK_CONNECT != SPI_connect())
153  {
154  elog(NOTICE, "getSRIDbySRS: could not connect to SPI manager");
155  return 0;
156  }
157 
158  err = SPI_execute_with_args(query, 1, argtypes, values, NULL, true, 1);
159  if (err < 0)
160  {
161  elog(NOTICE, "getSRIDbySRS: error executing query %d", err);
162  SPI_finish();
163  return 0;
164  }
165 
166  /* no entry in spatial_ref_sys */
167  if (SPI_processed <= 0)
168  {
169  snprintf(query,
170  max_query_size,
171  "SELECT srid "
172  "FROM %s, "
173  "regexp_matches($1::text, E'urn:ogc:def:crs:([a-z]+):.*:([0-9]+)', 'gi') AS re "
174  "WHERE re[1] ILIKE auth_name AND int4(re[2]) = auth_srid",
175  postgis_spatial_ref_sys());
176 
177  err = SPI_execute_with_args(query, 1, argtypes, values, NULL, true, 1);
178  if (err < 0)
179  {
180  elog(NOTICE, "getSRIDbySRS: error executing query %d", err);
181  SPI_finish();
182  return 0;
183  }
184 
185  if (SPI_processed <= 0)
186  {
187  SPI_finish();
188  return 0;
189  }
190  }
191 
192  srid = atoi(SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1));
193  SPI_finish();
194 
195  return srid;
196 }

Referenced by geom_from_geojson().

Here is the caller graph for this function: