PostGIS 3.6.2dev-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 283 of file rt_util.c.

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