From: Bborie Park Date: Fri, 21 Oct 2011 18:11:46 +0000 (+0000) Subject: Changed rt_raster_has_no_band to use 0-based band index instead of 1-based. Removed... X-Git-Tag: 2.0.0alpha1~858 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8864196bef2df009d4a8257763a8991b5d25a897;p=postgis Changed rt_raster_has_no_band to use 0-based band index instead of 1-based. Removed function prototype ST_HasNoData(raster) as the other prototype ST_HasNoData(raster, nband) now uses the default value of 1 for nband. git-svn-id: http://svn.osgeo.org/postgis/trunk@7998 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/reference_raster.xml b/doc/reference_raster.xml index ef4ce0ac2..eaffce4eb 100644 --- a/doc/reference_raster.xml +++ b/doc/reference_raster.xml @@ -2798,14 +2798,10 @@ WHERE rid = 2; - - boolean ST_HasNoBand - raster rast - - boolean ST_HasNoBand - raster rast - integer bandnum + boolean ST_HasNoBand + raster rast + integer bandnum=1 diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 5b987deb4..ab27e5795 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -5891,16 +5891,29 @@ rt_raster_deserialize(void* serialized, int header_only) { return rast; } -int rt_raster_is_empty(rt_raster raster) { - - - return (NULL == raster || raster->height <= 0 || raster->width <= 0); +/** + * Return TRUE if the raster is empty. i.e. is NULL, width = 0 or height = 0 + * + * @param raster: the raster to get info from + * + * @return TRUE if the raster is empty, FALSE otherwise + */ +int +rt_raster_is_empty(rt_raster raster) { + return (NULL == raster || raster->height <= 0 || raster->width <= 0); } -int rt_raster_has_no_band(rt_raster raster, int nband) { - - - return (NULL == raster || raster->numBands < nband); +/** + * Return TRUE if the raster do not have a band of this number. + * + * @param raster: the raster to get info from + * @param nband: the band number. 0-based + * + * @return TRUE if the raster do not have a band of this number, FALSE otherwise + */ +int +rt_raster_has_no_band(rt_raster raster, int nband) { + return (NULL == raster || nband >= raster->numBands || nband < 0); } /** diff --git a/raster/rt_core/rt_api.h b/raster/rt_core/rt_api.h index 7dcff50e5..14acc5b33 100644 --- a/raster/rt_core/rt_api.h +++ b/raster/rt_core/rt_api.h @@ -904,20 +904,23 @@ rt_raster rt_raster_deserialize(void* serialized, int header_only); /** * Return TRUE if the raster is empty. i.e. is NULL, width = 0 or height = 0 + * * @param raster: the raster to get info from + * * @return TRUE if the raster is empty, FALSE otherwise */ int rt_raster_is_empty(rt_raster raster); /** * Return TRUE if the raster do not have a band of this number. + * * @param raster: the raster to get info from - * @param nband: the band number. + * @param nband: the band number. 0-based + * * @return TRUE if the raster do not have a band of this number, FALSE otherwise */ int rt_raster_has_no_band(rt_raster raster, int nband); - /** * Copy one band from one raster to another * @param torast: raster to copy band to diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index dff54c974..60daeb575 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -2393,7 +2393,7 @@ Datum RASTER_hasNoBand(PG_FUNCTION_ARGS) /* Get band number */ bandindex = PG_GETARG_INT32(1); - hasnoband = rt_raster_has_no_band(raster, bandindex); + hasnoband = rt_raster_has_no_band(raster, bandindex - 1); rt_raster_destroy(raster); @@ -2521,7 +2521,7 @@ Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS) * Check if the raster has the required band. Otherwise, return a raster * without band **/ - if (rt_raster_has_no_band(raster, nband)) { + if (rt_raster_has_no_band(raster, nband - 1)) { elog(NOTICE, "Raster does not have the required band. Returning a raster " "without a band"); rt_raster_destroy(raster); @@ -3122,7 +3122,7 @@ Datum RASTER_mapAlgebraFct(PG_FUNCTION_ARGS) * Check if the raster has the required band. Otherwise, return a raster * without band **/ - if (rt_raster_has_no_band(raster, nband)) { + if (rt_raster_has_no_band(raster, nband - 1)) { elog(NOTICE, "Raster does not have the required band. Returning a raster " "without a band"); rt_raster_destroy(raster);