Return formatted GDAL raster from raster.
1600 GDALDriverH src_drv = NULL;
1601 int destroy_src_drv = 0;
1602 GDALDatasetH
src_ds = NULL;
1604 vsi_l_offset rtn_lenvsi;
1605 uint64_t rtn_len = 0;
1607 GDALDriverH rtn_drv = NULL;
1608 GDALDatasetH rtn_ds = NULL;
1609 uint8_t *rtn = NULL;
1612 assert(NULL != gdalsize);
1619 if (format == NULL || !strlen(format))
1626 rterror(
"rt_raster_to_gdal: Could not convert raster to GDAL MEM format");
1631 rtn_drv = GDALGetDriverByName(format);
1632 if (NULL == rtn_drv) {
1633 rterror(
"rt_raster_to_gdal: Could not load the output GDAL driver");
1635 if (destroy_src_drv) GDALDestroyDriver(src_drv);
1641 cc = GDALGetMetadataItem(rtn_drv, GDAL_DCAP_CREATECOPY, NULL);
1643 vio = GDALGetMetadataItem(rtn_drv, GDAL_DCAP_VIRTUALIO, NULL);
1645 if (cc == NULL || vio == NULL) {
1646 rterror(
"rt_raster_to_gdal: Output GDAL driver does not support CreateCopy and/or VirtualIO");
1648 if (destroy_src_drv) GDALDestroyDriver(src_drv);
1653 RASTER_DEBUG(3,
"Copying GDAL MEM raster to memory file in output format");
1654 rtn_ds = GDALCreateCopy(
1666 if (destroy_src_drv) GDALDestroyDriver(src_drv);
1669 if (NULL == rtn_ds) {
1670 rterror(
"rt_raster_to_gdal: Could not create the output GDAL dataset");
1674 RASTER_DEBUGF(4,
"dataset SRS: %s", GDALGetProjectionRef(rtn_ds));
1680 RASTER_DEBUG(3,
"Done copying GDAL MEM raster to memory file in output format");
1684 rtn = VSIGetMemFileBuffer(
"/vsimem/out.dat", &rtn_lenvsi,
TRUE);
1685 RASTER_DEBUG(3,
"Done copying GDAL memory file to buffer");
1687 rterror(
"rt_raster_to_gdal: Could not create the output GDAL raster");
1691 rtn_len = (uint64_t) rtn_lenvsi;
1692 *gdalsize = rtn_len;
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
#define RASTER_DEBUG(level, msg)
int rt_util_gdal_register_all(int force_register_all)
#define RASTER_DEBUGF(level, msg,...)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
GDALDatasetH rt_raster_to_gdal_mem(rt_raster raster, const char *srs, uint32_t *bandNums, int *excludeNodataValues, int count, GDALDriverH *rtn_drv, int *destroy_rtn_drv)
Return GDAL dataset using GDAL MEM driver from raster.