PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ rt_util_gdal_sr_auth_info()

rt_errorstate rt_util_gdal_sr_auth_info ( GDALDatasetH  hds,
char **  authname,
char **  authcode 
)

Get auth name and code.

Parameters
authnameauthority organization of code. calling function is expected to free the memory allocated for value
authcodecode assigned by authority organization. calling function is expected to free the memory allocated for value
Returns
ES_NONE on success, ES_ERROR on error

Definition at line 276 of file rt_util.c.

276  {
277  const char *srs = NULL;
278 
279  assert(authname != NULL);
280  assert(authcode != NULL);
281 
282  *authname = NULL;
283  *authcode = NULL;
284 
285  srs = GDALGetProjectionRef(hds);
286  if (srs != NULL && srs[0] != '\0') {
287  OGRSpatialReferenceH hSRS = OSRNewSpatialReference(NULL);
288 
289  if (OSRSetFromUserInput(hSRS, srs) == OGRERR_NONE) {
290  const char* pszAuthorityName = OSRGetAuthorityName(hSRS, NULL);
291  const char* pszAuthorityCode = OSRGetAuthorityCode(hSRS, NULL);
292 
293  if (pszAuthorityName != NULL && pszAuthorityCode != NULL) {
294  size_t authorityName_len = strlen(pszAuthorityName) +1;
295  size_t authorityCode_len = strlen(pszAuthorityCode) + 1;
296  *authname = rtalloc(sizeof(char) * authorityName_len);
297  *authcode = rtalloc(sizeof(char) * authorityCode_len);
298 
299  if (*authname == NULL || *authcode == NULL) {
300  rterror("rt_util_gdal_sr_auth_info: Could not allocate memory for auth name and code");
301  if (*authname != NULL) rtdealloc(*authname);
302  if (*authcode != NULL) rtdealloc(*authcode);
303  OSRDestroySpatialReference(hSRS);
304  return ES_ERROR;
305  }
306 
307  strncpy(*authname, pszAuthorityName, authorityName_len);
308  strncpy(*authcode, pszAuthorityCode, authorityCode_len);
309  }
310  }
311 
312  OSRDestroySpatialReference(hSRS);
313  }
314 
315  return ES_NONE;
316 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:219
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:191
@ ES_NONE
Definition: librtcore.h:182
@ ES_ERROR
Definition: librtcore.h:183
void rtdealloc(void *mem)
Definition: rt_context.c:206

References ES_ERROR, ES_NONE, rtalloc(), rtdealloc(), and rterror().

Referenced by RASTER_addBandOutDB(), and rt_raster_from_gdal_dataset().

Here is the call graph for this function:
Here is the caller graph for this function: