PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ getSRIDbySRS()

int getSRIDbySRS ( const char *  SRS)

Definition at line 119 of file lwgeom_export.c.

References LWGEOM_asGML(), and PG_FUNCTION_INFO_V1().

Referenced by geom_from_geojson().

120 {
121  char *query =
122  "SELECT srid "
123  "FROM spatial_ref_sys, "
124  "regexp_matches($1::text, E'([a-z]+):([0-9]+)', 'gi') AS re "
125  "WHERE re[1] ILIKE auth_name AND int4(re[2]) = auth_srid";
126  Oid argtypes[] = {CSTRINGOID};
127  Datum values[] = {CStringGetDatum(srs)};
128  int32_t srid, err;
129 
130  if (srs == NULL)
131  return 0;
132 
133  if (SPI_OK_CONNECT != SPI_connect())
134  {
135  elog(NOTICE, "getSRIDbySRS: could not connect to SPI manager");
136  return 0;
137  }
138 
139  err = SPI_execute_with_args(query, 1, argtypes, values, NULL, true, 1);
140  if (err < 0)
141  {
142  elog(NOTICE, "getSRIDbySRS: error executing query %d", err);
143  SPI_finish();
144  return 0;
145  }
146 
147  /* no entry in spatial_ref_sys */
148  if (SPI_processed <= 0)
149  {
150  query =
151  "SELECT srid "
152  "FROM spatial_ref_sys, "
153  "regexp_matches($1::text, E'urn:ogc:def:crs:([a-z]+):.*:([0-9]+)', 'gi') AS re "
154  "WHERE re[1] ILIKE auth_name AND int4(re[2]) = auth_srid";
155 
156  err = SPI_execute_with_args(query, 1, argtypes, values, NULL, true, 1);
157  if (err < 0)
158  {
159  elog(NOTICE, "getSRIDbySRS: error executing query %d", err);
160  SPI_finish();
161  return 0;
162  }
163 
164  if (SPI_processed <= 0)
165  {
166  SPI_finish();
167  return 0;
168  }
169  }
170 
171  srid = atoi(SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1));
172  if ( ! srs )
173  {
174  SPI_finish();
175  return 0;
176  }
177 
178  SPI_finish();
179 
180  return srid;
181 }
Here is the call graph for this function:
Here is the caller graph for this function: