From 0954cf51e26abaad9ee71444a4d73b453dd70594 Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Wed, 3 Oct 2012 20:53:06 +0000 Subject: [PATCH] Addition of shortcut function rt_raster_clone() git-svn-id: http://svn.osgeo.org/postgis/trunk@10368 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_api.c | 49 +++++++++++++++++++++++++++++++++++++++++ raster/rt_core/rt_api.h | 10 +++++++++ 2 files changed, 59 insertions(+) diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 911f4b933..5206bf806 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -8268,6 +8268,55 @@ rt_raster_replace_band(rt_raster raster, rt_band band, int index) { return oldband; } +/** + * Clone an existing raster + * + * @param raster: raster to clone + * @param deep: flag indicating if bands should be cloned + * + * @return a new rt_raster or NULL on error + */ +rt_raster +rt_raster_clone(rt_raster raster, uint8_t deep) { + rt_raster rtn = NULL; + double gt[6] = {0}; + + assert(NULL != raster); + + if (deep) { + int numband = rt_raster_get_num_bands(raster); + uint32_t *nband = NULL; + int i = 0; + + nband = rtalloc(sizeof(uint32_t) * numband); + if (nband == NULL) { + rterror("rt_raster_clone: Unable to allocate memory for deep clone"); + return NULL; + } + for (i = 0; i < numband; i++) + nband[i] = i; + + rtn = rt_raster_from_band(raster, nband, numband); + rtdealloc(nband); + + return rtn; + } + + rtn = rt_raster_new( + rt_raster_get_width(raster), + rt_raster_get_height(raster) + ); + if (rtn == NULL) { + rterror("rt_raster_clone: Unable to create cloned raster"); + return NULL; + } + + rt_raster_get_geotransform_matrix(raster, gt); + rt_raster_set_geotransform_matrix(rtn, gt); + + return rtn; +} + /** * Return formatted GDAL raster from raster * diff --git a/raster/rt_core/rt_api.h b/raster/rt_core/rt_api.h index 7d354b663..a36f9a68a 100644 --- a/raster/rt_core/rt_api.h +++ b/raster/rt_core/rt_api.h @@ -1353,6 +1353,16 @@ rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums, rt_band rt_raster_replace_band(rt_raster raster, rt_band band, int index); +/** + * Clone an existing raster + * + * @param raster: raster to clone + * @param deep: flag indicating if bands should be cloned + * + * @return a new rt_raster or NULL on error + */ +rt_raster rt_raster_clone(rt_raster raster, uint8_t deep); + /** * Return formatted GDAL raster from raster * -- 2.40.0