PostGIS  2.5.7dev-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 270 of file rt_util.c.

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

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: