PostGIS  2.1.10dev-r@@SVN_REVISION@@
uint8_t* rt_raster_to_gdal ( rt_raster  raster,
const char *  srs,
char *  format,
char **  options,
uint64_t *  gdalsize 
)

Return formatted GDAL raster from raster.

Parameters
raster: the raster to convert
srs: the raster's coordinate system in OGC WKT
format: format to convert to. GDAL driver short name
options: list of format creation options. array of strings
gdalsize: will be set to the size of returned bytea
Returns
formatted GDAL raster. the calling function is responsible for freeing the returned data using CPLFree()

Definition at line 8794 of file rt_api.c.

References FALSE, RASTER_DEBUG, RASTER_DEBUGF, rt_raster_to_gdal_mem(), rt_util_gdal_register_all(), rterror(), ovdump::src_ds, and TRUE.

Referenced by RASTER_asGDALRaster(), and test_raster_to_gdal().

8795  {
8796  GDALDriverH src_drv = NULL;
8797  int destroy_src_drv = 0;
8798  GDALDatasetH src_ds = NULL;
8799 
8800  vsi_l_offset rtn_lenvsi;
8801  uint64_t rtn_len = 0;
8802 
8803  GDALDriverH rtn_drv = NULL;
8804  GDALDatasetH rtn_ds = NULL;
8805  uint8_t *rtn = NULL;
8806 
8807  assert(NULL != raster);
8808  assert(NULL != gdalsize);
8809 
8810  /* any supported format is possible */
8812  RASTER_DEBUG(3, "loaded all supported GDAL formats");
8813 
8814  /* output format not specified */
8815  if (format == NULL || !strlen(format))
8816  format = "GTiff";
8817  RASTER_DEBUGF(3, "output format is %s", format);
8818 
8819  /* load raster into a GDAL MEM raster */
8820  src_ds = rt_raster_to_gdal_mem(raster, srs, NULL, NULL, 0, &src_drv, &destroy_src_drv);
8821  if (NULL == src_ds) {
8822  rterror("rt_raster_to_gdal: Could not convert raster to GDAL MEM format");
8823  return 0;
8824  }
8825 
8826  /* load driver */
8827  rtn_drv = GDALGetDriverByName(format);
8828  if (NULL == rtn_drv) {
8829  rterror("rt_raster_to_gdal: Could not load the output GDAL driver");
8830  GDALClose(src_ds);
8831  if (destroy_src_drv) GDALDestroyDriver(src_drv);
8832  return 0;
8833  }
8834  RASTER_DEBUG(3, "Output driver loaded");
8835 
8836  /* convert GDAL MEM raster to output format */
8837  RASTER_DEBUG(3, "Copying GDAL MEM raster to memory file in output format");
8838  rtn_ds = GDALCreateCopy(
8839  rtn_drv,
8840  "/vsimem/out.dat", /* should be fine assuming this is in a process */
8841  src_ds,
8842  FALSE, /* should copy be strictly equivelent? */
8843  options, /* format options */
8844  NULL, /* progress function */
8845  NULL /* progress data */
8846  );
8847 
8848  /* close source dataset */
8849  GDALClose(src_ds);
8850  if (destroy_src_drv) GDALDestroyDriver(src_drv);
8851  RASTER_DEBUG(3, "Closed GDAL MEM raster");
8852 
8853  if (NULL == rtn_ds) {
8854  rterror("rt_raster_to_gdal: Could not create the output GDAL dataset");
8855  return 0;
8856  }
8857 
8858  RASTER_DEBUGF(4, "dataset SRS: %s", GDALGetProjectionRef(rtn_ds));
8859 
8860  /* close dataset, this also flushes any pending writes */
8861  GDALClose(rtn_ds);
8862  RASTER_DEBUG(3, "Closed GDAL output raster");
8863 
8864  RASTER_DEBUG(3, "Done copying GDAL MEM raster to memory file in output format");
8865 
8866  /* from memory file to buffer */
8867  RASTER_DEBUG(3, "Copying GDAL memory file to buffer");
8868  rtn = VSIGetMemFileBuffer("/vsimem/out.dat", &rtn_lenvsi, TRUE);
8869  RASTER_DEBUG(3, "Done copying GDAL memory file to buffer");
8870  if (NULL == rtn) {
8871  rterror("rt_raster_to_gdal: Could not create the output GDAL raster");
8872  return 0;
8873  }
8874 
8875  rtn_len = (uint64_t) rtn_lenvsi;
8876  *gdalsize = rtn_len;
8877 
8878  return rtn;
8879 }
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_api.c:445
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.
Definition: rt_api.c:8989
#define RASTER_DEBUG(level, msg)
Definition: rt_api.h:281
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
#define FALSE
Definition: dbfopen.c:169
tuple src_ds
MAIN.
Definition: ovdump.py:53
#define TRUE
Definition: dbfopen.c:170

Here is the call graph for this function:

Here is the caller graph for this function: