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

Definition at line 101 of file lwgeom_export.c.

Referenced by geom_from_geojson().

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

Here is the caller graph for this function: