]> granicus.if.org Git - postgis/commitdiff
Changed those functions that is 1-based for band index to 0-based in rt_core. This...
authorBborie Park <bkpark at ucdavis.edu>
Fri, 21 Oct 2011 14:53:29 +0000 (14:53 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Fri, 21 Oct 2011 14:53:29 +0000 (14:53 +0000)
Associated ticket is #754

git-svn-id: http://svn.osgeo.org/postgis/trunk@7997 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_core/rt_api.h
raster/rt_pg/rt_pg.c
raster/rt_pg/rtpostgis.sql.in.c
raster/rt_pg/rtpostgis_drop.sql.in.c

index b8cad938ed6f32f8a7d8f01a0e23733d0fecb4b9..5b987deb4de95692cae673d369fdadd80122402d 100644 (file)
@@ -4155,6 +4155,22 @@ rt_raster_geopoint_to_cell(rt_raster raster,
        return 1;
 }
 
+/**
+ * Returns a set of "geomval" value, one for each group of pixel
+ * sharing the same value for the provided band.
+ *
+ * A "geomval " value is a complex type composed of a the wkt
+ * representation of a geometry (one for each group of pixel sharing
+ * the same value) and the value associated with this geometry.
+ *
+ * @param raster: the raster to get info from.
+ * @param nband: the band to polygonize. 0-based
+ *
+ * @return A set of "geomval" values, one for each group of pixels
+ * sharing the same value for the provided band. The returned values are
+ * WKT geometries, not real PostGIS geometries (this may change in the
+ * future, and the function returns real geometries)
+ */
 rt_geomval
 rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, int * pnElements)
 {
@@ -4178,20 +4194,20 @@ rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, int * pnElements)
     int iBandHasNodataValue = FALSE;
     double dBandNoData = 0.0;
 
-    uint32_t bandNums[1] = {nband - 1};
+    uint32_t bandNums[1] = {nband};
 
     /* Checkings */
 
 
     assert(NULL != raster);
-    assert(nband > 0 && nband <= rt_raster_get_num_bands(raster));
+    assert(nband >= 0 && nband < rt_raster_get_num_bands(raster));
 
     RASTER_DEBUG(2, "In rt_raster_dump_as_polygons");
 
     /*******************************
      * Get band
      *******************************/
-    band = rt_raster_get_band(raster, nband - 1);
+    band = rt_raster_get_band(raster, nband);
     if (NULL == band) {
         rterror("rt_raster_dump_as_wktpolygons: Error getting band %d from raster", nband);
         return 0;
@@ -5887,55 +5903,58 @@ int rt_raster_has_no_band(rt_raster raster, int nband) {
     return (NULL == raster || raster->numBands < nband);
 }
 
-int32_t rt_raster_copy_band(rt_raster torast,
-        rt_raster fromrast, int fromindex, int toindex)
-{
-    rt_band newband = NULL;
-
+/**
+ * Copy one band from one raster to another
+ * @param torast: raster to copy band to
+ * @param fromrast: raster to copy band from
+ * @param fromindex: index of band in source raster, 0-based
+ * @param toindex: index of new band in destination raster, 0-based
+ * @return The band index of the second raster where the new band is copied.
+ */
+int32_t
+rt_raster_copy_band(
+       rt_raster torast, rt_raster fromrast,
+       int fromindex, int toindex
+) {
+       rt_band newband = NULL;
 
-    assert(NULL != torast);
-    assert(NULL != fromrast);
+       assert(NULL != torast);
+       assert(NULL != fromrast);
 
-    /* Check raster dimensions */
-    if (torast->height != fromrast->height || torast->width != fromrast->width)
-    {
-        rtwarn("rt_raster_copy_band: Attempting to add a band with different width or height");
-        return -1;
-    }
+       /* Check raster dimensions */
+       if (torast->height != fromrast->height || torast->width != fromrast->width) {
+               rtwarn("rt_raster_copy_band: Attempting to add a band with different width or height");
+               return -1;
+       }
 
-    /* Check bands limits */
-    if (fromrast->numBands < 1)
-    {
-        rtwarn("rt_raster_copy_band: Second raster has no band");
-        return -1;
-    }
-    else if (fromindex < 0)
-    {
-        rtwarn("rt_raster_copy_band: Band index for second raster < 0. Defaulted to 1");
-        fromindex = 0;
-    }
-    else if (fromindex >= fromrast->numBands)
-    {
-        rtwarn("rt_raster_copy_band: Band index for second raster > number of bands, truncated from %u to %u", fromindex - 1, fromrast->numBands);
-        fromindex = fromrast->numBands - 1;
-    }
+       /* Check bands limits */
+       if (fromrast->numBands < 1) {
+               rtwarn("rt_raster_copy_band: Second raster has no band");
+               return -1;
+       }
+       else if (fromindex < 0) {
+               rtwarn("rt_raster_copy_band: Band index for second raster < 0. Defaulted to 0");
+               fromindex = 0;
+       }
+       else if (fromindex >= fromrast->numBands) {
+               rtwarn("rt_raster_copy_band: Band index for second raster > number of bands, truncated from %u to %u", fromindex, fromrast->numBands - 1);
+               fromindex = fromrast->numBands - 1;
+       }
 
-    if (toindex < 0)
-    {
-        rtwarn("rt_raster_copy_band: Band index for first raster < 0. Defaulted to 1");
-        toindex = 0;
-    }
-    else if (toindex > torast->numBands)
-    {
-        rtwarn("rt_raster_copy_band: Band index for first raster > number of bands, truncated from %u to %u", toindex - 1, torast->numBands);
-        toindex = torast->numBands;
-    }
+       if (toindex < 0) {
+               rtwarn("rt_raster_copy_band: Band index for first raster < 0. Defaulted to 0");
+               toindex = 0;
+       }
+       else if (toindex > torast->numBands) {
+               rtwarn("rt_raster_copy_band: Band index for first raster > number of bands, truncated from %u to %u", toindex, torast->numBands);
+               toindex = torast->numBands;
+       }
 
-    /* Get band from source raster */
-    newband = rt_raster_get_band(fromrast, fromindex);
+       /* Get band from source raster */
+       newband = rt_raster_get_band(fromrast, fromindex);
 
-    /* Add band to the second raster */
-    return rt_raster_add_band(torast, newband, toindex);
+       /* Add band to the second raster */
+       return rt_raster_add_band(torast, newband, toindex);
 }
 
 /**
@@ -6004,7 +6023,7 @@ rt_raster_from_band(rt_raster raster, uint32_t *bandNums, int count) {
  *
  * @param raster: raster of band to be replaced
  * @param band : new band to add to raster
- * @param index : index of band to replace (1-based)
+ * @param index : index of band to replace (0-based)
  *
  * @return 0 on error or replaced band
  */
@@ -6019,7 +6038,7 @@ rt_raster_replace_band(rt_raster raster, rt_band band, int index) {
                return 0;
        }
 
-       if (index > raster->numBands || index < 0) {
+       if (index >= raster->numBands || index < 0) {
                rterror("rt_raster_replace_band: Band index is not valid");
                return 0;
        }
index b31fe32e5e09c2fdd7ec61e810389f5c17aa9393..7dcff50e5ad4e5ad46c6283dd24cd39c728438b6 100644 (file)
@@ -871,7 +871,7 @@ LWPOLY* rt_raster_get_convex_hull(rt_raster raster);
  * the same value) and the value associated with this geometry.
  *
  * @param raster: the raster to get info from.
- * @param nband: the band to polygonize. From 1 to rt_raster_get_num_bands
+ * @param nband: the band to polygonize. 0-based
  *
  * @return A set of "geomval" values, one for each group of pixels
  * sharing the same value for the provided band. The returned values are
@@ -922,8 +922,8 @@ 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
  * @param fromrast: raster to copy band from
- * @param fromindex: index of band in source raster
- * @param toindex: index of new band in destination raster
+ * @param fromindex: index of band in source raster, 0-based
+ * @param toindex: index of new band in destination raster, 0-based
  * @return The band index of the second raster where the new band is copied.
  */
 int32_t rt_raster_copy_band(rt_raster torast,
@@ -948,7 +948,7 @@ rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums,
  * 
  * @param raster: raster of band to be replaced
  * @param band : new band to add to raster
- * @param index : index of band to replace (1-based)
+ * @param index : index of band to replace (0-based)
  *
  * @return 0 on error or replaced band
  */
index bcaeb0fd1ad6ee4cd9b7481fb68f87689b08dcb9..dff54c9744b808f3fc6667ae52b653100712e5f0 100644 (file)
@@ -788,7 +788,7 @@ Datum RASTER_dumpAsWKTPolygons(PG_FUNCTION_ARGS)
         /**
          * Dump raster
          */
-        geomval = rt_raster_dump_as_wktpolygons(raster, nband, &nElements);
+        geomval = rt_raster_dump_as_wktpolygons(raster, nband - 1, &nElements);
                                rt_raster_destroy(raster);
         if (NULL == geomval)
         {
index 56cded6aa450541754cae9a47045d294801eead9..c5eaac7ffcb82304d3fe8476118a4b155d1b7b1a 100644 (file)
@@ -1587,7 +1587,7 @@ CREATE OR REPLACE FUNCTION st_snaptogrid(rast raster, gridx double precision, gr
        LANGUAGE 'sql' STABLE STRICT;
 
 -----------------------------------------------------------------------
--- MapAlgebra
+-- One Raster ST_MapAlgebra
 -----------------------------------------------------------------------
 -- This function can not be STRICT, because nodatavaluerepl can be NULL (could be just '' though)
 -- or pixeltype can not be determined (could be st_bandpixeltype(raster, band) though)
@@ -1660,7 +1660,6 @@ CREATE OR REPLACE FUNCTION st_mapalgebrafct(rast raster, userfunction regprocedu
     AS $$ SELECT st_mapalgebrafct($1, 1, NULL, $2, NULL) $$
     LANGUAGE SQL;
 
------------------------------------------------------------------------
 -----------------------------------------------------------------------
 -- Get information about the raster
 -----------------------------------------------------------------------
@@ -1669,16 +1668,11 @@ CREATE OR REPLACE FUNCTION st_isempty(rast raster)
     AS 'MODULE_PATHNAME', 'RASTER_isEmpty'
     LANGUAGE 'C' IMMUTABLE STRICT;
 
-CREATE OR REPLACE FUNCTION st_hasnoband(rast raster, nband int)
+CREATE OR REPLACE FUNCTION st_hasnoband(rast raster, nband int DEFAULT 1)
     RETURNS boolean
     AS 'MODULE_PATHNAME', 'RASTER_hasNoBand'
     LANGUAGE 'C' IMMUTABLE STRICT;
 
-CREATE OR REPLACE FUNCTION st_hasnoband(rast raster)
-    RETURNS boolean
-    AS 'select st_hasnoband($1, 1)'
-    LANGUAGE 'SQL' IMMUTABLE STRICT;
-
 -----------------------------------------------------------------------
 -- Raster Band Accessors
 -----------------------------------------------------------------------
index 97f7187861d571640b73f8bfd0408b6d61b62600..e7ca3f3e9234e6c2facf35e51530523571428339 100644 (file)
@@ -69,3 +69,6 @@ DROP FUNCTION IF EXISTS _ST_AsRaster(geometry,double precision , double precisio
 -- arg names changed
 DROP FUNCTION IF EXISTS _ST_Resample(raster, text, double precision, integer, double precision, double precision, double precision, double precision, double precision, double precision);
 
+-- default parameters added
+DROP FUNCTION IF EXISTS ST_HasNoBand(raster);
+