PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 380 of file rt_util.c.

380 {
381 const char *srs = NULL;
382
383 assert(authname != NULL);
384 assert(authcode != NULL);
385
386 *authname = NULL;
387 *authcode = NULL;
388
389 srs = GDALGetProjectionRef(hds);
390 if (srs != NULL && srs[0] != '\0') {
391 OGRSpatialReferenceH hSRS = OSRNewSpatialReference(NULL);
392
393 if (OSRSetFromUserInput(hSRS, srs) == OGRERR_NONE) {
394 const char* pszAuthorityName = OSRGetAuthorityName(hSRS, NULL);
395 const char* pszAuthorityCode = OSRGetAuthorityCode(hSRS, NULL);
396
397 if (pszAuthorityName != NULL && pszAuthorityCode != NULL) {
398 size_t authorityName_len = strlen(pszAuthorityName) +1;
399 size_t authorityCode_len = strlen(pszAuthorityCode) + 1;
400 *authname = rtalloc(sizeof(char) * authorityName_len);
401 *authcode = rtalloc(sizeof(char) * authorityCode_len);
402
403 if (*authname == NULL || *authcode == NULL) {
404 rterror("rt_util_gdal_sr_auth_info: Could not allocate memory for auth name and code");
405 if (*authname != NULL) rtdealloc(*authname);
406 if (*authcode != NULL) rtdealloc(*authcode);
407 OSRDestroySpatialReference(hSRS);
408 return ES_ERROR;
409 }
410
411 strncpy(*authname, pszAuthorityName, authorityName_len);
412 strncpy(*authcode, pszAuthorityCode, authorityCode_len);
413 }
414 }
415
416 OSRDestroySpatialReference(hSRS);
417 }
418
419 return ES_NONE;
420}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
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: