289 SPITupleTable *tuptable = NULL;
310 len =
sizeof(char) * (strlen(
"SELECT CASE WHEN (upper(auth_name) = 'EPSG' OR upper(auth_name) = 'EPSGA') AND length(COALESCE(auth_srid::text, '')) > 0 THEN upper(auth_name) || ':' || auth_srid WHEN length(COALESCE(auth_name, '') || COALESCE(auth_srid::text, '')) > 0 THEN COALESCE(auth_name, '') || COALESCE(auth_srid::text, '') ELSE '' END, proj4text, srtext FROM spatial_ref_sys WHERE srid = LIMIT 1") +
MAX_INT_CHARLEN + 1);
311 sql = (
char *) palloc(len);
313 elog(ERROR,
"rtpg_getSR: Could not allocate memory for sql\n");
317 spi_result = SPI_connect();
318 if (spi_result != SPI_OK_CONNECT) {
320 elog(ERROR,
"rtpg_getSR: Could not connect to database using SPI\n");
325 snprintf(
sql, len,
"SELECT CASE WHEN (upper(auth_name) = 'EPSG' OR upper(auth_name) = 'EPSGA') AND length(COALESCE(auth_srid::text, '')) > 0 THEN upper(auth_name) || ':' || auth_srid WHEN length(COALESCE(auth_name, '') || COALESCE(auth_srid::text, '')) > 0 THEN COALESCE(auth_name, '') || COALESCE(auth_srid::text, '') ELSE '' END, proj4text, srtext FROM spatial_ref_sys WHERE srid = %d LIMIT 1", srid);
327 spi_result = SPI_execute(
sql,
TRUE, 0);
329 if (spi_result != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
330 if (SPI_tuptable) SPI_freetuptable(tuptable);
332 elog(ERROR,
"rtpg_getSR: Cannot find SRID (%d) in spatial_ref_sys", srid);
336 tupdesc = SPI_tuptable->tupdesc;
337 tuptable = SPI_tuptable;
338 tuple = tuptable->vals[0];
341 for (i = 1; i < 4; i++) {
342 tmp = SPI_getvalue(tuple, tupdesc, i);
346 SPI_result != SPI_ERROR_NOATTRIBUTE &&
347 SPI_result != SPI_ERROR_NOOUTFUNC &&
354 len = strlen(tmp) + 1;
355 srs = SPI_palloc(
sizeof(
char) * len);
358 if (SPI_tuptable) SPI_freetuptable(tuptable);
360 elog(ERROR,
"rtpg_getSR: Could not allocate memory for spatial reference text\n");
363 strncpy(srs, tmp, len);
374 if (SPI_tuptable) SPI_freetuptable(tuptable);
379 if (SPI_tuptable) SPI_freetuptable(tuptable);
381 elog(ERROR,
"rtpg_getSR: Could not find a viable spatial reference for SRID (%d)", srid);
int rt_util_gdal_supported_sr(const char *srs)
#define POSTGIS_RT_DEBUGF(level, msg,...)