| 104 | |
| 105 | '''ST_SummaryStats(raster, nband) -> record'''[[BR]] |
| 106 | This is the core function that gets the summary statistics (# of values, mean, standard deviation, minimum value, maximum value) of a specified raster's band. It is this function that ST_Mean, ST_StdDev and ST_MinMax calls for their appropriate values. |
| 107 | |
| 108 | 1. ST_SummaryStats(rast raster, nband int, hasnodata boolean) -> record |
| 109 | |
| 110 | returns one record of five columns (count, mean, stddev, min, max) |
| 111 | |
| 112 | nband: index of band |
| 113 | |
| 114 | hasnodata: if FALSE, any pixel who's value is nodata is ignored |
| 115 | |
| 116 | {{{ |
| 117 | ST_SummaryStats(rast, 1, FALSE) |
| 118 | }}} |
| 119 | |
| 120 | 2. ST_SummaryStats(rast raster, nband int) -> record |
| 121 | |
| 122 | assumes hasnodata = FALSE |
| 123 | |
| 124 | {{{ |
| 125 | ST_SummaryStats(rast, 2) |
| 126 | }}} |
| 127 | |
| 128 | 3. ST_SummaryStats(rast raster, hasnodata boolean) -> record |
| 129 | |
| 130 | assumes nband = 1 |
| 131 | |
| 132 | {{{ |
| 133 | ST_SummaryStats(rast, TRUE) |
| 134 | }}} |
| 135 | |
| 136 | 4. ST_SummaryStats(rast raster) -> record |
| 137 | |
| 138 | assumes nband = 1 and hasnodata = FALSE |
| 139 | |
| 140 | {{{ |
| 141 | ST_SummaryStats(rast) |
| 142 | }}} |
| 143 | |
| 144 | Due to the time it may take to do on-the-fly calculation of summary stats for large rasters (say 10000 x 10000), an alternative that sacrifices accuracy for speed is required. The following functions sample a percentage of the raster in a methodical randomized manner. The algorithm used for sampling is... |
| 145 | |
| 146 | 1. select the larger dimension of the width and height. compute the number of pixels to sample in each "row" of the larger dimension |
| 147 | |
| 148 | 2. pick pixels from each "row" of the larger dimension in an incremental rolling manner where each increment is randomly determined. |
| 149 | |
| 150 | The set of ST_ApproxSummaryStats functions are: |
| 151 | |
| 152 | 1. ST_ApproxSummaryStats(rast raster, nband int, hasnodata boolean, sample_percent double precision) -> record |
| 153 | |
| 154 | sample_percent: a value between 0 and 1 indicating the percentage of the raster band's pixels to consider |
| 155 | |
| 156 | {{{ |
| 157 | ST_ApproxSummaryStats(rast, 3, FALSE, 0.1) |
| 158 | |
| 159 | ST_ApproxSummaryStats(rast, 1, TRUE, 0.5) |
| 160 | }}} |
| 161 | |
| 162 | 2. ST_ApproxSummaryStats(rast raster, nband int, sample_percent double precision) -> record |
| 163 | |
| 164 | assumes that nband = 1 |
| 165 | |
| 166 | {{{ |
| 167 | ST_ApproxSummaryStats(rast, 2 0.01) |
| 168 | |
| 169 | ST_ApproxSummaryStats(rast, 4, 0.025) |
| 170 | }}} |
| 171 | |
| 172 | 3. ST_ApproxSummaryStats(rast raster, hasnodata boolean, sample_percent double precision) -> record |
| 173 | |
| 174 | assumes that nband = 1 |
| 175 | |
| 176 | {{{ |
| 177 | ST_ApproxSummaryStats(rast, FALSE, 0.01) |
| 178 | |
| 179 | ST_ApproxSummaryStats(rast, TRUE, 0.025) |
| 180 | }}} |
| 181 | |
| 182 | 4. ST_ApproxSummaryStats(rast raster, sample_percent double precision) -> record |
| 183 | |
| 184 | assumes that nband = 1 and hasnodata = FALSE |
| 185 | |
| 186 | {{{ |
| 187 | ST_ApproxSummaryStats(rast, 0.25) |
| 188 | }}} |
| 189 | |
| 190 | 5. ST_ApproxSummaryStats(rast raster) -> record |
| 191 | |
| 192 | assumes that nband = 1, hasnodata = FALSE and sample_percent = 0.1 |
| 193 | |
| 194 | {{{ |
| 195 | ST_ApproxSummaryStats(rast) |
| 196 | }}} |
| 197 | |
| 198 | The situation arises where the summary statistics of a coverage table is required. As the coverage may be large (tens of gigabytes of memory or larger), the following functions are provided to permit an incremental computation of the summary statistics. |
| 199 | |
| 200 | 1. ST_SummaryStats(rastertable text, rastercolumn text, nband int, hasnodata boolean) -> record |
| 201 | |
| 202 | rastertable: name of table with raster column |
| 203 | |
| 204 | rastercolumn: name of column of data type raster |
| 205 | |
| 206 | {{{ |
| 207 | ST_SummaryStats('tmax_2010', 'rast', 1, FALSE) |
| 208 | |
| 209 | ST_SummaryStats('precip_2011', 'rast', 1, TRUE) |
| 210 | }}} |
| 211 | |
| 212 | 2. ST_SummaryStats(rastertable text, rastercolumn text, nband int) -> record |
| 213 | |
| 214 | hasnodata = FALSE |
| 215 | |
| 216 | {{{ |
| 217 | ST_SummaryStats('tmax_2010', 'rast', 1) |
| 218 | }}} |
| 219 | |
| 220 | 3. ST_SummaryStats(rastertable text, rastercolumn text, hasnodata boolean) -> record |
| 221 | |
| 222 | nband = 1 |
| 223 | |
| 224 | {{{ |
| 225 | ST_SummaryStats('precip_2011', 'rast', TRUE) |
| 226 | }}} |
| 227 | |
| 228 | 4. ST_SummaryStats(rastertable text, rastercolumn text) -> record |
| 229 | |
| 230 | nband = 1 and hasnodata = FALSE |
| 231 | |
| 232 | {{{ |
| 233 | ST_SummaryStats('tmin_2009', 'rast') |
| 234 | }}} |
| 235 | |
| 236 | Variations for ST_ApproxSummaryStats are: |
| 237 | |
| 238 | 1. ST_ApproxSummaryStats(rastertable text, rastercolumn text, nband int, hasnodata boolean, sample_percent double precision) -> record |
| 239 | |
| 240 | {{{ |
| 241 | ST_ApproxSummaryStats('tmax_2010', 'rast', 1, FALSE, 0.5) |
| 242 | |
| 243 | ST_ApproxSummaryStats('precip_2011', 'rast', 1, TRUE, 0.2) |
| 244 | }}} |
| 245 | |
| 246 | 2. ST_ApproxSummaryStats(rastertable text, rastercolumn text, nband int, sample_percent double precision) -> record |
| 247 | |
| 248 | hasnodata = FALSE |
| 249 | |
| 250 | {{{ |
| 251 | ST_ApproxSummaryStats('tmax_2010', 'rast', 1, 0.5) |
| 252 | |
| 253 | ST_ApproxSummaryStats('precip_2011', 'rast', 1, 0.2) |
| 254 | }}} |
| 255 | |
| 256 | 3. ST_ApproxSummaryStats(rastertable text, rastercolumn text, hasnodata boolean, sample_percent double precision) -> record |
| 257 | |
| 258 | nband = 1 |
| 259 | |
| 260 | {{{ |
| 261 | ST_ApproxSummaryStats('tmax_2010', 'rast', FALSE, 0.5) |
| 262 | |
| 263 | ST_ApproxSummaryStats('precip_2011', 'rast', TRUE, 0.2) |
| 264 | }}} |
| 265 | |
| 266 | 4. ST_ApproxSummaryStats(rastertable text, rastercolumn text, sample_percent double precision) -> record |
| 267 | |
| 268 | nband = 1 and hasnodata = FALSE |
| 269 | |
| 270 | {{{ |
| 271 | ST_ApproxSummaryStats('tmax_2010', 'rast', 0.5) |
| 272 | |
| 273 | ST_ApproxSummaryStats('precip_2011', 'rast', 0.2) |
| 274 | }}} |
| 275 | |
| 276 | 5. ST_ApproxSummaryStats(rastertable text, rastercolumn text) -> record |
| 277 | |
| 278 | nband = 1, hasnodata = FALSE and sample_percent = 0.1 |
| 279 | |
| 280 | {{{ |
| 281 | ST_ApproxSummaryStats('tmax_2010', 'rast') |
| 282 | |
| 283 | ST_ApproxSummaryStats('precip_2011', 'rast') |
| 284 | }}} |
| 285 | |
| 286 | The mean returned in the coverage functions (has rastertable and rastercolumn arguments) is a weighted mean of the means of each raster tile. The standard deviation returned is the cumulative standard deviation of all raster tiles. |
| 287 | |
| 288 | ---- |
| 289 | |