288 SPITupleTable *tuptable = NULL;
309 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);
310 sql = (
char *) palloc(len);
312 elog(ERROR,
"rtpg_getSR: Could not allocate memory for sql\n");
316 spi_result = SPI_connect();
317 if (spi_result != SPI_OK_CONNECT) {
319 elog(ERROR,
"rtpg_getSR: Could not connect to database using SPI\n");
324 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);
326 spi_result = SPI_execute(
sql,
TRUE, 0);
328 if (spi_result != SPI_OK_SELECT || SPI_tuptable == NULL || SPI_processed != 1) {
329 if (SPI_tuptable) SPI_freetuptable(tuptable);
331 elog(ERROR,
"rtpg_getSR: Cannot find SRID (%d) in spatial_ref_sys", srid);
335 tupdesc = SPI_tuptable->tupdesc;
336 tuptable = SPI_tuptable;
337 tuple = tuptable->vals[0];
340 for (i = 1; i < 4; i++) {
341 tmp = SPI_getvalue(tuple, tupdesc, i);
345 SPI_result != SPI_ERROR_NOATTRIBUTE &&
346 SPI_result != SPI_ERROR_NOOUTFUNC &&
353 len = strlen(tmp) + 1;
354 srs = SPI_palloc(
sizeof(
char) * len);
357 if (SPI_tuptable) SPI_freetuptable(tuptable);
359 elog(ERROR,
"rtpg_getSR: Could not allocate memory for spatial reference text\n");
362 strncpy(srs, tmp, len);
373 if (SPI_tuptable) SPI_freetuptable(tuptable);
378 if (SPI_tuptable) SPI_freetuptable(tuptable);
380 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,...)