PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ getSRIDbySRS()

int getSRIDbySRS ( const char *  srs)

Definition at line 102 of file lwgeom_export.c.

References LWGEOM_asGML(), and PG_FUNCTION_INFO_V1().

Referenced by geom_from_geojson().

103 {
104  char query[256];
105  int srid, err;
106 
107  if (srs == NULL)
108  return 0;
109 
110  if (SPI_OK_CONNECT != SPI_connect ())
111  {
112  elog(NOTICE, "getSRIDbySRS: could not connect to SPI manager");
113  SPI_finish();
114  return 0;
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 call graph for this function:
Here is the caller graph for this function: