PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ getSRIDbySRS()

int getSRIDbySRS ( const char *  SRS)

Definition at line 118 of file lwgeom_export.c.

References LWGEOM_asGML(), and PG_FUNCTION_INFO_V1().

Referenced by geom_from_geojson().

119 {
120  char query[256];
121  int srid, err;
122 
123  if (!srs) 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 
170  SPI_finish();
171 
172  return srid;
173 }
Here is the call graph for this function:
Here is the caller graph for this function: