PostGIS  3.3.9dev-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 273 of file rt_util.c.

273  {
274  const char *srs = NULL;
275 
276  assert(authname != NULL);
277  assert(authcode != NULL);
278 
279  *authname = NULL;
280  *authcode = NULL;
281 
282  srs = GDALGetProjectionRef(hds);
283  if (srs != NULL && srs[0] != '\0') {
284  OGRSpatialReferenceH hSRS = OSRNewSpatialReference(NULL);
285 
286  if (OSRSetFromUserInput(hSRS, srs) == OGRERR_NONE) {
287  const char* pszAuthorityName = OSRGetAuthorityName(hSRS, NULL);
288  const char* pszAuthorityCode = OSRGetAuthorityCode(hSRS, NULL);
289 
290  if (pszAuthorityName != NULL && pszAuthorityCode != NULL) {
291  size_t authorityName_len = strlen(pszAuthorityName) +1;
292  size_t authorityCode_len = strlen(pszAuthorityCode) + 1;
293  *authname = rtalloc(sizeof(char) * authorityName_len);
294  *authcode = rtalloc(sizeof(char) * authorityCode_len);
295 
296  if (*authname == NULL || *authcode == NULL) {
297  rterror("rt_util_gdal_sr_auth_info: Could not allocate memory for auth name and code");
298  if (*authname != NULL) rtdealloc(*authname);
299  if (*authcode != NULL) rtdealloc(*authcode);
300  OSRDestroySpatialReference(hSRS);
301  return ES_ERROR;
302  }
303 
304  strncpy(*authname, pszAuthorityName, authorityName_len);
305  strncpy(*authcode, pszAuthorityCode, authorityCode_len);
306  }
307  }
308 
309  OSRDestroySpatialReference(hSRS);
310  }
311 
312  return ES_NONE;
313 }
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: