PostGIS  2.5.0dev-r@@SVN_REVISION@@
int getSRIDbySRS ( const char *  srs)

Definition at line 117 of file lwgeom_export.c.

Referenced by geom_from_geojson().

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

Here is the caller graph for this function: