PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ getSRIDbySRS()

int getSRIDbySRS ( FunctionCallInfo  fcinfo,
const char *  srs 
)

Definition at line 139 of file lwgeom_export.c.

140{
141 static const int16_t max_query_size = 512;
142 char query[512];
143 Oid argtypes[] = {CSTRINGOID};
144 Datum values[] = {CStringGetDatum(srs)};
145 int32_t srid, err;
146
147 postgis_initialize_cache(fcinfo);
148 snprintf(query,
149 max_query_size,
150 "SELECT srid "
151 "FROM %s, "
152 "regexp_matches($1::text, E'([a-z]+):([0-9]+)', 'gi') AS re "
153 "WHERE re[1] ILIKE auth_name AND int4(re[2]) = auth_srid",
154 postgis_spatial_ref_sys());
155
156 if (!srs) return 0;
157
158 if (SPI_OK_CONNECT != SPI_connect())
159 {
160 elog(NOTICE, "getSRIDbySRS: could not connect to SPI manager");
161 return 0;
162 }
163
164 err = SPI_execute_with_args(query, 1, argtypes, values, NULL, true, 1);
165 if (err < 0)
166 {
167 elog(NOTICE, "getSRIDbySRS: error executing query %d", err);
168 SPI_finish();
169 return 0;
170 }
171
172 /* no entry in spatial_ref_sys */
173 if (SPI_processed <= 0)
174 {
175 snprintf(query,
176 max_query_size,
177 "SELECT srid "
178 "FROM %s, "
179 "regexp_matches($1::text, E'urn:ogc:def:crs:([a-z]+):.*:([0-9]+)', 'gi') AS re "
180 "WHERE re[1] ILIKE auth_name AND int4(re[2]) = auth_srid",
181 postgis_spatial_ref_sys());
182
183 err = SPI_execute_with_args(query, 1, argtypes, values, NULL, true, 1);
184 if (err < 0)
185 {
186 elog(NOTICE, "getSRIDbySRS: error executing query %d", err);
187 SPI_finish();
188 return 0;
189 }
190
191 if (SPI_processed <= 0)
192 {
193 SPI_finish();
194 return 0;
195 }
196 }
197
198 srid = atoi(SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1));
199 SPI_finish();
200
201 return srid;
202}

Referenced by geom_from_geojson().

Here is the caller graph for this function: