PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ getSRIDbySRS()

int getSRIDbySRS ( const char *  srs)

Definition at line 117 of file lwgeom_export.c.

References LWGEOM_asGML(), and PG_FUNCTION_INFO_V1().

Referenced by geom_from_geojson().

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