PostGIS  3.0.6dev-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 272 of file rt_util.c.

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