| 216 | |
| 217 | ---- |
| 218 | == '''Objective FV.01 - Being able to return a JPEG, a TIFF, a PNG or any image format supported by GDAL - ''Done''''' == |
| 219 | |
| 220 | '''ST_bytea(raster, integer) -> raster''' -- the integer parameters is the band number of the raster.[[BR]] |
| 221 | What is does? |
| 222 | |
| 223 | ---- |
| 224 | ~~'''Open Question:''' When exporting a multiband raster to JPEG, TIFF, PNG, SVG or KML, how should we specify the band number in the exporting function.~~ |
| 225 | |
| 226 | ~~There is two options to select the band to convert from a multiband raster in all the ST_AsFormat functions. [[BR]]~~ |
| 227 | [[BR]] |
| 228 | ~~ 1. Precede each call with ST_Band() to return a selected band.[[BR]]~~ |
| 229 | ~~ Pros: This is a general function that can be called before any function that would otherwise require a band parameter.[[BR]]~~ |
| 230 | ~~ Cons: This implies creating a temporary raster. This might be more elegant and general but is this too much overhead comparing with having a band parameter?~~ |
| 231 | |
| 232 | ~~ 2. Add a band parameter to each ST_AsFormat function.[[BR]]~~ |
| 233 | ~~ Pros: Hypothetically less overhead.[[BR]]~~ |
| 234 | ~~ Cons: Every functions implying access to a band should then have this parameter when in most case it would be equal to 1. In many cases it makes no sence to have to specify a band parameter since it is the whole raster that we want to export, including all the bands.~~ |
| 235 | |
| 236 | ~~Pierre: More I think about it more I think that the first option is the best one...~~ |
| 237 | |
| 238 | ~~mloskot: Perhaps there is a compromise in form of two sets of functions: 1) ST_As* which always burn the whole raster (all bands) 2) ST_BandAs* which takes number of band as a parameter and return only this requested band.~~ |
| 239 | |
| 240 | ---- |
| 241 | |
| 242 | '''ST_Band(raster, integer) -> raster''' -- the integer parameters are the band number of the rasters.[[BR]] |
| 243 | Return a single band from a multiband raster. If "band" is greater than the value returned by ST_GetNumBands(), the function returns the last band. This function should be used to select a band before converting it to JPEG, TIFF, PNG, SVG or KML with the corresponding function. e.g. '''ST_AsTIFF(ST_Band(raster, band)) |
| 244 | |
| 245 | A complete implementation of ST_Band should include the following: |
| 246 | |
| 247 | 1. ST_Band(rast raster, nbands int[]) -> raster |
| 248 | |
| 249 | nbands is an array of 1-based band indices of the bands to copy into the output raster |
| 250 | |
| 251 | For a raster rast with 3 bands: |
| 252 | {{{ |
| 253 | ST_Band(rast, ARRAY[1,3,2]) |
| 254 | |
| 255 | ST_Band(rast, ARRAY[3,2,1]) |
| 256 | }}} |
| 257 | You can rearrange the bands as above. You can also duplicate the bands: |
| 258 | {{{ |
| 259 | ST_Band(rast, ARRAY[1,2,3,2,1]) |
| 260 | }}} |
| 261 | |
| 262 | 2. ST_Band(rast raster, nband int) -> raster |
| 263 | |
| 264 | nband is a single integer of the 1-based band index of the band to copy into the output raster |
| 265 | |
| 266 | {{{ |
| 267 | ST_Band(rast, 1) |
| 268 | |
| 269 | ST_Band(rast, 3) |
| 270 | }}} |
| 271 | |
| 272 | 3. ST_Band(rast raster, nbands text) -> raster |
| 273 | |
| 274 | nbands is a comma separated string of 1-based band indices indicating the bands to copy into the output raster |
| 275 | |
| 276 | {{{ |
| 277 | ST_Band(rast, '1,2') |
| 278 | |
| 279 | ST_Band(rast, '1,2,3, 1, 1 , 2') |
| 280 | }}} |
| 281 | |
| 282 | 4. ST_Band(rast raster, nbands text, delimiter char) -> raster |
| 283 | |
| 284 | nbands is a user-specified delimiter separated string of 1-based band indices indicating the bands to copy into the output raster |
| 285 | |
| 286 | {{{ |
| 287 | ST_Band(rast, '1,2', ',') |
| 288 | |
| 289 | ST_Band(rast, '1,2,3, 1, 1 , 2', ',') |
| 290 | }}} |
| 291 | |
| 292 | 5. ST_Band(rast raster) -> raster |
| 293 | |
| 294 | the band to extract is automatically assumed to be one. |
| 295 | |
| 296 | {{{ |
| 297 | ST_Band(rast) |
| 298 | }}} |
| 299 | |
| 300 | If an index is outside the valid range of band indices for a raster (less than 1 or greater than the value returned by ST_NumBands), the function will fail and return. |
| 301 | |
| 302 | ~~''' Open Question: ''' Should the function fail if an index is invalid? How should this work when providing more than one indices to the function?~~ |
| 303 | |
| 304 | ---- |
| 305 | |
| 306 | '''ST_AsJPEG(raster, quality) -> JPEG as "bytea"'''[[BR]] |
| 307 | |
| 308 | The JPEG format has several limitations: |
| 309 | |
| 310 | 1. JPEG only allows 1 (greyscale) or 3 (RGB) bands of data |
| 311 | |
| 312 | 2. JPEG only supports 8BUI pixeltype |
| 313 | |
| 314 | 3. JPEG cannot embed spatial reference information within the file but can have an associated world file |
| 315 | |
| 316 | To address the limitations: |
| 317 | |
| 318 | 1. Use ST_Band to specify which band(s) should be passed to the ST_AsJPEG function. Variations of ST_AsJPEG are made available that allows specifying a band index. If a raster whose number of specified bands does not equal 1 or 3 is provided, a warning is raised and the first or the first three bands are used. |
| 319 | |
| 320 | 2. Throw an exception if any of the specified bands is not 8BUI. The user should use ST_Reclass to convert any non-8BUI bands to 8BUI. |
| 321 | |
| 322 | 3. Nothing can be done. |
| 323 | |
| 324 | A proposed set of variations of the ST_AsJPEG function: |
| 325 | |
| 326 | 1. ST_AsJPEG(rast raster, options text[]) |
| 327 | |
| 328 | rast: the raster with one or three bands in 8BUI pixel type to generate a JPEG image from |
| 329 | |
| 330 | options: array of creation options to pass to the GDAL JPEG driver |
| 331 | |
| 332 | {{{ |
| 333 | ST_AsJPEG(rast, ARRAY['QUALITY=90', 'PROGRESSIVE=ON']) |
| 334 | }}} |
| 335 | |
| 336 | 2. ST_AsJPEG(rast raster) |
| 337 | |
| 338 | Like !#1 above but use the driver's default creation options |
| 339 | |
| 340 | 3. ST_AsJPEG(rast raster, nbands int[], options text[]) |
| 341 | |
| 342 | nbands: an integer array specifying the band indices of the raster to include in the JPEG file |
| 343 | |
| 344 | {{{ |
| 345 | ST_AsJPEG(rast, ARRAY[1,3,6], ARRAY['QUALITY=50']) |
| 346 | }}} |
| 347 | |
| 348 | 4. ST_AsJPEG(rast raster, nbands int[]) |
| 349 | |
| 350 | Like !#3, but use the default creation options |
| 351 | |
| 352 | {{{ |
| 353 | ST_AsJPEG(rast, ARRAY[1,3,6]) |
| 354 | }}} |
| 355 | |
| 356 | 5. ST_AsJPEG(rast raster, nbands int[], quality int) |
| 357 | |
| 358 | quality: number between 10 and 100 indicating image quality |
| 359 | |
| 360 | {{{ |
| 361 | ST_AsJPEG(rast, ARRAY[1,2,3], 90) |
| 362 | }}} |
| 363 | |
| 364 | 6. ST_AsJPEG(rast raster, nband int, options text[]) |
| 365 | |
| 366 | nband: index of the band to include |
| 367 | |
| 368 | {{{ |
| 369 | ST_AsJPEG(rast, 2, ARRAY['QUALITY=25']) |
| 370 | }}} |
| 371 | |
| 372 | 7. ST_AsJPEG(rast raster, nband int, quality int) |
| 373 | |
| 374 | {{{ |
| 375 | ST_AsJPEG(rast, 5, 75) |
| 376 | }}} |
| 377 | |
| 378 | 8. ST_AsJPEG(rast raster, nband int) |
| 379 | |
| 380 | {{{ |
| 381 | ST_AsJPEG(rast, 4) |
| 382 | }}} |
| 383 | |
| 384 | ''OLD NOTES'' |
| 385 | |
| 386 | ~~Return the raster as a JPEG encoded as a PostgreSQL bytea. By default quality is set to 75, but this option can be used to select other values. Values must be in the range 10-100. Low values result in higher compression ratios, but poorer image quality. Values above 95 are not meaningfully better quality but can but substantially larger. (copied from http://www.gdal.org/frmt_jpeg.html)~~ |
| 387 | |
| 388 | |
| 389 | ~~'''Open Question:''' Is JPEG export limited to raster having 8 bit unsigned integer pixeltype (8BUI)?~~ |
| 390 | |
| 391 | ~~[http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 8 bits rasters. Should we do the same?~~ |
| 392 | |
| 393 | ~~Otherwise, how do we convert other types to 8BUI? e.g. 16BUI or 8BSI?~~ |
| 394 | |
| 395 | ~~Pierre: It might be more simple to ignore pixeltypes other than 8BUI but it would be very convenient to have a way to quickly export elevation data for example as a JPEG. It would be nice to have an elegant solution to this. Maybe something inspired from !MapServer.~~ |
| 396 | |
| 397 | ~~Proposition one (Pierre): ST_AsJPEG could simply (optionally when the pixeltype is not 8BUI) map the ST_Maximum() and ST_Minimum() value to 0-255. ST_Maximum() and ST_Minimum() are not in the spec yet but this could be on nice usage of it. They will imply caching the min and max when importing and editing. Both function should ignore the !NoDataValues. They could also be two parameters passed to ST_AsJPEG(raster, quality, min, max).~~ |
| 398 | |
| 399 | ~~Proposition two: There could also be just one parameter (string) defining a mapping method:~~ |
| 400 | |
| 401 | ~~ * Method "None": No mapping. This is possible only for 8BUI.~~ |
| 402 | |
| 403 | ~~ * Method "!MaxMinValue": Use the Max and the Min cached in the raster. e.g. for 16BSI (min, max) -> (-2033, 2456) -> (round((-2033 - -2033)/(2456 - -2033)*255), round((2456 - -2033)/(2456 - -2033)*255)) -> (0, 255).[[BR]]~~ |
| 404 | ~~[[BR]]This is equivalent to ST_AsJPEG(raster, quality, ST_Minimum(rast), ST_Maximum(rast))~~ |
| 405 | |
| 406 | ~~ * Method "!MaxMinType": Use the Max and the Min allowed by the type. e.g. for 16BSI (min, max) -> (-2033, 2456) -> (round((-2033 - -32768)/(32767 - -32768)*255), round((2456 - -32768)/(32767 - -32768)*255)) -> (120, 137)[[BR]]~~ |
| 407 | ~~[[BR]]This would be equivalent to ST_AsJPEG(raster, quality, ST_BandPixelTypeMin(rast), ST_BandPixelTypeMax(rast)). Both functions (ST_BandPixelTypeMin & ST_BandPixelTypeMax) are not yet planned and I could not find an SQL query that returns the equivalent range for a type. [http://groups.google.nl/group/microsoft.public.sqlserver.programming/browse_thread/thread/46512c2691da4607/6743f4aea485c6d1 One possible solution.]~~ |
| 408 | |
| 409 | |
| 410 | ~~mloskot: ATM, I have no thoughts on this issue.~~ |
| 411 | |
| 412 | ~~'''Open Question:''' Is JPEG export limited to raster having 1 or 3 bands?~~ |
| 413 | |
| 414 | ~~[http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 1 or 3 band rasters. Should we do the same? In this case 1 band rasters would be exported as a greyscale JPEG having R G and B identical and 3 band rasters would be interpreted as R, G and B.~~ |
| 415 | |
| 416 | ~~Pierre: I think the answer should be yes. I don't see how we could have a 2 band raster fit into RGB.~~ |
| 417 | |
| 418 | ~~mloskot: I agree, the answer should be yes.~~ |
| 419 | |
| 420 | ~~'''Here is an attempt to define the different versions of the function:'''~~ |
| 421 | |
| 422 | ~~The most minimalistic versions of the function should assume band 1, 2 and 3 as being r, g, b and the quality equal to 75:~~ |
| 423 | |
| 424 | ~~ ST_AsJPEG(raster) -quality = 75~~ |
| 425 | |
| 426 | ~~A variant allow specifying the quality:~~ |
| 427 | |
| 428 | ~~ ST_AsJPEG(raster, integer)~~ |
| 429 | |
| 430 | ~~Another variant should enable us to specify which band correspond to the r, the g and the b:~~ |
| 431 | |
| 432 | ~~ ST_AsJPEG(raster, integer, integer, integer) - raster, rband, gband, bband, quality=75~~ |
| 433 | |
| 434 | ~~ ST_AsJPEG(raster, integer, integer, integer, integer) - raster, rband, gband, bband, quality~~ |
| 435 | |
| 436 | ~~Another version should be designed to be used with a future ST_Band(raster) function. In this case there is no attempt to extract r, g or b band from any passed raster:~~ |
| 437 | |
| 438 | ~~ ST_AsJPEG(raster, raster, raster)~~ |
| 439 | |
| 440 | ~~ ST_AsJPEG(raster, raster, raster, integer) -with the quality param~~ |
| 441 | |
| 442 | ~~Another series should allow converting 1 band raster with pixel of type 8BUI to a grayscale JPEG (Carefull study of the GDAL behavior when converting a single band to JPEG should be done before confirming these functions):~~ |
| 443 | |
| 444 | ~~ ST_AsJPEG(raster, "GRAYSCALE") - convert only band 1 with quality = 75~~ |
| 445 | |
| 446 | ~~ ST_AsJPEG(raster, "GRAYSCALE", integer) - convert only band 1 with specified quality~~ |
| 447 | |
| 448 | ~~ ST_AsJPEG(raster, integer, "GRAYSCALE") - allow specifying the band number to convert~~ |
| 449 | |
| 450 | ~~ ST_AsJPEG(raster, integer, "GRAYSCALE", integer) - allow specifying the band number to convert and the quality~~ |
| 451 | |
| 452 | ~~Another series should allow converting 1 band raster of ANY pixel type to a grayscale JPEG. Pixel types different than 8BUI should be mapped according to specified min, max values and a mapping mode: "!MaxMinValue" (default) or "!MaxMinType".~~ |
| 453 | |
| 454 | ~~ ST_AsJPEG(raster, "GRAYSCALE", min, max, text) - convert only band 1 with quality = 75~~ |
| 455 | |
| 456 | ~~ ST_AsJPEG(raster, "GRAYSCALE", integer, min, max, text) - convert only band 1 with specified quality~~ |
| 457 | |
| 458 | ~~ ST_AsJPEG(raster, integer, "GRAYSCALE", min, max, text) - allow specifying the band number to convert~~ |
| 459 | |
| 460 | ~~ ST_AsJPEG(raster, integer, "GRAYSCALE", integer, min, max, text) - allow specifying the band number to convert and the quality~~ |
| 461 | |
| 462 | ---- |
| 463 | |
| 464 | '''ST_AsTIFF(raster, compression) -> TIFF as "bytea"'''[[BR]] |
| 465 | Return the raster as a TIFF encoded as a PostgreSQL bytea. If raster is a multiband raster and no band were selected with ST_Band() every band are written to the resulting TIFF. |
| 466 | |
| 467 | compression=[JPEG/LZW/PACKBITS/DEFLATE/CCITTRLE/CCITTFAX3/CCITTFAX4/NONE]: Set the type of compression to use. None is the default. The CCITT compression should only be used with 1bit (NBITS=1) data. JPEG should only be used with Byte data. When using JPEG add a number specifying the quality. 75 is the default. e.g. ST_AsTIFF(raster, "JPEG60") (copied from http://www.gdal.org/frmt_gtiff.html) |
| 468 | |
| 469 | A proposed implementation of the ST_AsTIFF functions. |
| 470 | |
| 471 | The TIFF format is probably the most robust available for converting rasters to GDAL rasters. Not only does it support all PostGIS Raster pixel types, it also provides plenty of creation options and possibly no issues with the number of bands. The only limitation found is that there can only be one NODATA value for all bands. |
| 472 | |
| 473 | ''If the compression parameter/option is specified to JPEG, all bands must be of pixel type 8BUI. If the compression parameter/option is specified to one of the CCITT options, all bands must be of pixel type 1BB. If any band violates the restriction, an exception is raised.'' |
| 474 | |
| 475 | The next three functions are the most basic of the ST_AsTIFF functions. |
| 476 | |
| 477 | 1. ST_AsTIFF(rast raster, options text[], srs text) -> bytea |
| 478 | |
| 479 | The most generic version of this function. All other ST_AsTIFF functions call this function. |
| 480 | |
| 481 | This function will check that all bands of the raster to be converted has the same NODATA value. If there are more than one possible NODATA values, a WARNING will be raised and the output TIFF will use the NODATA value of the first band with a NODATA value. |
| 482 | |
| 483 | options: the GDAL creation options found in the Creation Options section of the GDAL TIFF driver |
| 484 | |
| 485 | srs: the user-specified OGC WKT or the proj4 text for a spatial reference to embed in the GDAL raster. TIFF is one of the formats that supports embedding the spatial reference within the image file. |
| 486 | |
| 487 | {{{ |
| 488 | ST_AsTIFF(rast, ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 489 | |
| 490 | ST_AsTIFF(rast, ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9'], 'PROJCS["NAD83 / California Albers",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["standard_parallel_1",34],PARAMETER["standard_parallel_2",40.5],PARAMETER["latitude_of_center",0],PARAMETER["longitude_of_center",-120],PARAMETER["false_easting",0],PARAMETER["false_northing",-4000000],AUTHORITY["EPSG","3310"],AXIS["X",EAST],AXIS["Y",NORTH]]') |
| 491 | }}} |
| 492 | |
| 493 | 2. ST_AsTIFF(rast raster, options text[]) -> bytea |
| 494 | |
| 495 | This one removes the user-specified srs argument. The output TIFF's spatial reference will be set to the same as the input raster, if possible. |
| 496 | |
| 497 | {{{ |
| 498 | ST_AsTIFF(rast, ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9']) |
| 499 | }}} |
| 500 | |
| 501 | 3. ST_AsTIFF(rast raster) -> bytea |
| 502 | |
| 503 | The simplest implementation of this function. Since the options argument has been removed, the output TIFF will be created with default options. Like the prior function, the spatial reference of the TIFF will be set to the same as the input raster. |
| 504 | |
| 505 | {{{ |
| 506 | ST_AsTIFF(rast) |
| 507 | }}} |
| 508 | |
| 509 | |
| 510 | The next three functions add a band index argument to filter the raster's bands before generating the output TIFF. |
| 511 | |
| 512 | 4. ST_AsTIFF(rast raster, nbands int[], options text[], srs text) -> bytea |
| 513 | |
| 514 | {{{ |
| 515 | ST_AsTIFF(rast, ARRAY[3,1,2], ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 516 | }}} |
| 517 | |
| 518 | 5. ST_AsTIFF(rast raster, nbands int[], options text[]) -> bytea |
| 519 | |
| 520 | This one removes the user-specified srs argument. The output TIFF's spatial reference will be set to the same as the input raster, if possible. |
| 521 | |
| 522 | {{{ |
| 523 | ST_AsTIFF(rast, ARRAY[3,1,2], ARRAY['COMPRESS=DEFLATE', 'ZLEVEL=9']) |
| 524 | }}} |
| 525 | |
| 526 | 6. ST_AsTIFF(rast raster, nbands int[]) -> bytea |
| 527 | |
| 528 | Since the options argument has been removed, the output TIFF will be created with default options. Like the prior function, the spatial reference of the TIFF will be set to the same as the input raster. |
| 529 | |
| 530 | {{{ |
| 531 | ST_AsTIFF(rast, ARRAY[3,1,2]) |
| 532 | }}} |
| 533 | |
| 534 | |
| 535 | The next two functions add a compression argument. If the compression desired is JPEG or DEFLATE, the user can specify a quality as part of the compression string. |
| 536 | |
| 537 | Examples are: |
| 538 | |
| 539 | {{{ |
| 540 | JPEG90 |
| 541 | |
| 542 | JPEG |
| 543 | |
| 544 | DEFLATE8 |
| 545 | |
| 546 | DEFLATE |
| 547 | }}} |
| 548 | |
| 549 | 7. ST_AsTIFF(rast raster, compression text, srs text) -> bytea |
| 550 | |
| 551 | This function will parse the compression string for the compression type and the compression quality. It will also inspect to make sure that the pixel types of the raster's bands are appropriate for the compression type. This is primarily for JPEG and CCITT compression types, which only support 8BUI and 1BB respectively. |
| 552 | |
| 553 | {{{ |
| 554 | ST_AsTIFF(rast, 'JPEG90', '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 555 | |
| 556 | ST_AsTIFF(rast, 'JPEG', '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 557 | |
| 558 | ST_AsTIFF(rast, 'LZMA', '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 559 | }}} |
| 560 | |
| 561 | 8. ST_AsTIFF(rast raster, compression text) -> bytea |
| 562 | |
| 563 | The output TIFF will be created with default options. Like the prior function, the spatial reference of the TIFF will be set to the same as the input raster. |
| 564 | |
| 565 | {{{ |
| 566 | ST_AsTIFF(rast, 'LZMA') |
| 567 | }}} |
| 568 | |
| 569 | |
| 570 | The next two functions include band index and compression arguments |
| 571 | |
| 572 | 9. ST_AsTIFF(rast raster, nbands int[], compression text, srs text) -> bytea |
| 573 | |
| 574 | {{{ |
| 575 | ST_AsTIFF(rast, ARRAY[2], 'JPEG90', ARRAY['BIGTIFF=IF_NEEDED'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 576 | |
| 577 | ST_AsTIFF(rast, ARRAY[1,3], 'JPEG', ARRAY['BIGTIFF=IF_NEEDED'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 578 | |
| 579 | ST_AsTIFF(rast, ARRAY[3,1,2], 'LZMA', ARRAY['BIGTIFF=IF_NEEDED'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 580 | }}} |
| 581 | |
| 582 | 10. ST_AsTIFF(rast raster, nbands int[], compression text) -> bytea |
| 583 | |
| 584 | {{{ |
| 585 | ST_AsTIFF(rast, ARRAY[3,2], 'DEFLATE9') |
| 586 | }}} |
| 587 | |
| 588 | The output TIFF will be created with default options. The spatial reference of the TIFF will be set to the same as the input raster. |
| 589 | |
| 590 | ---- |
| 591 | ~~'''Open Question:''' What if we want to export only the first two band of a three band layer?~~ |
| 592 | |
| 593 | ~~Maybe we need a ST_RasterFromBands(band1, band2, etc...) to reconstitute a multiband raster from multiple sources (having the same width, height, pixelsize, etc...)~~ |
| 594 | |
| 595 | ~~mloskot: or ST_RasterFromBands(bands) where bands is ARRAY[int]. For instance, ST_RasterFromBands(ARRAY[1,3]) will burn new raster from 1 and 3 bands of input raster.~~ |
| 596 | |
| 597 | ---- |
| 598 | '''ST_AsPNG(raster, band) -> PNG as "bytea"''' |
| 599 | |
| 600 | Like the JPEG raster format, the PNG format has limitations: |
| 601 | |
| 602 | 1. PNG only allows 1 (greyscale) or 3 (RGB) bands of data |
| 603 | |
| 604 | 2. PNG only supports 8BUI and 16BUI pixeltypes. Any other pixeltype will be written as 8BUI, though the results are probably useless |
| 605 | |
| 606 | 3. PNG cannot embed spatial reference information within the file but can have an associated world file |
| 607 | |
| 608 | Like JPEG, the limitations can be resolved: |
| 609 | |
| 610 | 1. Use ST_Band to specify which band(s) should be passed to the ST_AsPNG function. If a raster whose number of specified bands does not equal 1 or 3 is provided, a warning is raised and the first or the first three bands are used. |
| 611 | |
| 612 | 2. Throw an exception if any of the specified bands is not 8BUI or 16BUI. The user should use ST_Reclass to convert any non-8BUI or 16BUI bands to 8BUI or 16BUI. |
| 613 | |
| 614 | 3. Nothing can be done within this function. ST_Georeference() can be used to the contents of the associated world file |
| 615 | |
| 616 | A proposed set of variations of the ST_AsPNG function: |
| 617 | |
| 618 | 1. ST_AsPNG(rast raster, options text[]) |
| 619 | |
| 620 | rast: the raster with one or three bands in 8BUI or 16BUI pixel type to generate a PNG image from |
| 621 | |
| 622 | options: array of creation options to pass to the GDAL PNG driver |
| 623 | |
| 624 | {{{ |
| 625 | ST_AsPNG(rast, ARRAY['ZLEVEL=9']) |
| 626 | }}} |
| 627 | |
| 628 | 2. ST_AsPNG(rast raster) |
| 629 | |
| 630 | Like !#1 above but use the driver's default creation options |
| 631 | |
| 632 | 3. ST_AsPNG(rast raster, nbands int[], options text[]) |
| 633 | |
| 634 | nbands: an integer array specifying the band indices of the raster to include in the PNG file |
| 635 | |
| 636 | {{{ |
| 637 | ST_AsPNG(rast, ARRAY[3,1,2], ARRAY['ZLEVEL=9']) |
| 638 | }}} |
| 639 | |
| 640 | 4. ST_AsPNG(rast raster, nbands int[]) |
| 641 | |
| 642 | Like !#3, but use the default creation options |
| 643 | |
| 644 | {{{ |
| 645 | ST_AsPNG(rast, ARRAY[3]) |
| 646 | }}} |
| 647 | |
| 648 | 5. ST_AsPNG(rast raster, nbands int[], compression int) |
| 649 | |
| 650 | compression: number between 1 and 9 indicating the amount of time to spend on compression. 1 is fastest with least compression. 9 is slowest with best compression |
| 651 | |
| 652 | {{{ |
| 653 | ST_AsPNG(rast, ARRAY[2,1,3], 3) |
| 654 | }}} |
| 655 | |
| 656 | 6. ST_AsPNG(rast raster, nband int, options text[]) |
| 657 | |
| 658 | nband: index of the band to include |
| 659 | |
| 660 | {{{ |
| 661 | ST_AsPNG(rast, 2, ARRAY['ZLEVEL=5']) |
| 662 | }}} |
| 663 | |
| 664 | 7. ST_AsPNG(rast raster, nband int, compression int) |
| 665 | |
| 666 | {{{ |
| 667 | ST_AsPNG(rast, 1, 8) |
| 668 | }}} |
| 669 | |
| 670 | 8. ST_AsPNG(rast raster, nband int) |
| 671 | |
| 672 | {{{ |
| 673 | ST_AsPNG(rast, 1) |
| 674 | }}} |
| 675 | |
| 676 | ---- |
| 677 | |
| 678 | '''ST_AsGDALRaster(raster, band int, type text, options text) -> bytea''' |
| 679 | |
| 680 | Use GDAL to convert the raster into one of the format suported by GDAL. |
| 681 | |
| 682 | This is a generic interface to outputting a supported and installed GDAL raster: |
| 683 | |
| 684 | 1. ST_AsGDALRaster(rast raster, format text, options text[], srs text) -> bytea |
| 685 | |
| 686 | This is the most generic and GDAL-specific method to convert a raster to a GDAL raster. All other version of ST_AsGDALRaster and other format specific functions (ST_AsJPEG, ST_AsTIFF and ST_AsPNG) are all wrappers around this function. Reference information for the format and options arguments of a particular format are specified at: http://gdal.org/formats_list.html. The arguments specified are: |
| 687 | |
| 688 | format: the GDAL format code. e.g. GTiff, JPEG, PNG |
| 689 | |
| 690 | options: the GDAL creation options found in the '''Creation Options''' section of a specified format. e.g. COMPRESS=JPEG, JPEG_QUALITY=90 |
| 691 | |
| 692 | srs: the user-specified OGC WKT or the proj4 text for a spatial reference to embed in the GDAL raster. Not all formats support embedding this information. e.g. the non-empty value for the srtext or proj4text column from the spatial_ref_sys table. |
| 693 | |
| 694 | {{{ |
| 695 | ST_AsGDALRaster(rast, 'GTiff', ARRAY['COMPRESS=JPEG', 'JPEG_QUALITY=90'], '+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') |
| 696 | |
| 697 | ST_AsGDALRaster(rast, 'GTiff', ARRAY['COMPRESS=JPEG', 'JPEG_QUALITY=90'], 'PROJCS["NAD83 / California Albers",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["standard_parallel_1",34],PARAMETER["standard_parallel_2",40.5],PARAMETER["latitude_of_center",0],PARAMETER["longitude_of_center",-120],PARAMETER["false_easting",0],PARAMETER["false_northing",-4000000],AUTHORITY["EPSG","3310"],AXIS["X",EAST],AXIS["Y",NORTH]]') |
| 698 | }}} |
| 699 | |
| 700 | |
| 701 | 2. ST_AsGDALRaster(rast raster, format text, options text[]) -> bytea |
| 702 | |
| 703 | This one removes the user-specified srs argument. The output GDAL raster's spatial reference will be set to the same as the input raster, if possible. |
| 704 | |
| 705 | {{{ |
| 706 | ST_AsGDALRaster(rast, 'JPEG', ARRAY['QUALITY=50']) |
| 707 | |
| 708 | ST_AsGDALRaster(rast, 'PNG', ARRAY['ZLEVEL=7']) |
| 709 | }}} |
| 710 | |
| 711 | 3. ST_AsGDALRaster(rast raster, format text) -> bytea |
| 712 | |
| 713 | The simplest implementation of this function. Since the options argument has been removed, the output GDAL raster will be created with default options. Like the prior function, the spatial reference of the GDAL raster will be set to the same as the input raster. |
| 714 | |
| 715 | {{{ |
| 716 | ST_AsGDALRaster(rast, 'JPEG') |
| 717 | }}} |
| 718 | |
| 719 | ---- |
| 720 | |
| 721 | '''ST_GDALDrivers() -> set of record''' |
| 722 | |
| 723 | As each GDAL installation may be different and ST_AsGDALRaster can be used to support formats other than GTiff, JPEG and PNG, a method is needed to expose to the end user the possible GDAL formats capable of being exported. This function will output the following columns. |
| 724 | |
| 725 | idx: the internal GDAL index number |
| 726 | |
| 727 | short_name: the GDAL format code. This is the value to pass to the format paramenter of ST_AsGDALRaster |
| 728 | |
| 729 | long_name: the full name of the GDAL format |
| 730 | |
| 731 | create_options: the creation options available for the format as an XML string. |
| 732 | |
| 733 | The formats outputted from ST_getGDALDrivers have been filtered to only those that the GDAL capabilities !CreateCopy and Virtual IO support. |
| 734 | |
| 735 | '''Open Question:''' Should the GDAL raster process be capable of supporting the GDAL capability Create? As the GDAL raster process writes nothing to a file in the filesystem (via Virtual IO), should there be support for writing the output GDAL raster temporarily to the filesystem? If so, how is it done in other PostgreSQL extensions in a secure manner? |
| 736 | |
| 737 | ---- |
| 738 | |
| 739 | ~~'''ST_srtext(rast raster) -> text''' |
| 740 | |
| 741 | ~~A helper function to get the value of column srtext or proj4text for a raster with an SRID. By default, the srtext is returned. If srtext is not available but proj4text is, the proj4text is returned. |
| 742 | |
| 743 | ~~This function may be removed based upon the capabilities of SPI. It may not be possible to remove this function as the srs function argument of ST_AsGDALRaster can be NULL, thereby instructing the function to not embed any spatial reference information into the output GDAL raster. |
| 744 | |
| 745 | ---- |
| 746 | |
| 747 | '''ST_Reclass(rast raster, VARIADIC argset reclassarg[]) -> raster''' |
| 748 | |
| 749 | Due to limitations in the JPEG (8BUI) and PNG (8BUI and 16BUI) raster formats regarding supported pixel/data types, a method must be provided that can convert a band of a larger data type to 8BUI, amongst other uses. ST_Reclass allows raster's band pixel values to be remapped from one range of numbers to another as well as between pixel types, e.g. 32BF to 8BUI. |
| 750 | |
| 751 | ST_Reclass returns a duplicate of the submitted raster with the bands specified to be reclassed being processed. This means that if a raster with 5 bands are submitted and band 1 is to be reclassed, the output raster will have 5 bands with band 1 reclassified. The other four bands will not be touched. |
| 752 | |
| 753 | 1. ST_Reclass(rast raster, VARIADIC argset reclassarg[]) -> raster |
| 754 | |
| 755 | rast: the raster whose specified bands are to be reclassified |
| 756 | |
| 757 | reclassarg: a new custom type defining the parameters required for reclassifying a band's pixel values. |
| 758 | |
| 759 | {{{ |
| 760 | CREATE TYPE reclassarg AS ( |
| 761 | |
| 762 | nband int, |
| 763 | |
| 764 | reclassexpr text, |
| 765 | |
| 766 | pixeltype text, |
| 767 | |
| 768 | nodata double |
| 769 | |
| 770 | ); |
| 771 | }}} |
| 772 | |
| 773 | nband: index of the band to reclass (1-based) |
| 774 | |
| 775 | reclassexpr: reclassification expression indicating the ranges to convert from and to. More than one expression can be provided by separating the expression with a comma (,). The values provided can be of any valid numeric type. |
| 776 | |
| 777 | ''rangefrom:rangeto[, rangefrom:rangeto]'' |
| 778 | |
| 779 | {{{ |
| 780 | 0-100:0-10 |
| 781 | |
| 782 | 0-100:0-10, 101-1000:11-100 |
| 783 | |
| 784 | 0-100:0-10, 101-1000:11-100, 1001-10000:101-1000 |
| 785 | }}} |
| 786 | |
| 787 | In the last example above, the default evaluation of the ranges is |
| 788 | |
| 789 | {{{ |
| 790 | 0 <= x < 100 reclassified to 0 <= y <= 10 |
| 791 | |
| 792 | 101 <= x < 1000 reclassified to 11 <= y <= 100 |
| 793 | |
| 794 | 1001 <= x < 10000 reclassified to 101 <= y <= 1000 |
| 795 | }}} |
| 796 | |
| 797 | To change the evaluation of rangefrom, use square brackets and parentheses. |
| 798 | |
| 799 | {{{ |
| 800 | 1. [a-b] = a <= x <= b |
| 801 | |
| 802 | 2. (a-b] = a < x <= b |
| 803 | |
| 804 | 3. [a-b) = a <= x < b |
| 805 | |
| 806 | 4. (a-b) = a < x < b |
| 807 | }}} |
| 808 | |
| 809 | !#3 above is the default evaluation of x in the range a-b. The use of square brackets and parentheses are optional, so the examples below would be permitted. Missing notations substitute the appropriate notation from #3 above. |
| 810 | |
| 811 | {{{ |
| 812 | [a-b = a <= x < b |
| 813 | |
| 814 | (a-b = a < x < b |
| 815 | |
| 816 | a-b] = a <= x <= b |
| 817 | |
| 818 | a-b) = a <= x < b |
| 819 | }}} |
| 820 | |
| 821 | Two special cases are also available for use when x may be outside the range of a-b. This situation is possible if your range is based upon an approximation, such as from ST_ApproxMinMax. |
| 822 | |
| 823 | {{{ |
| 824 | ]a-b or )a-b = x < a, rule matches |
| 825 | |
| 826 | a-b[ or a-b( = x >= b, rule matches |
| 827 | }}} |
| 828 | |
| 829 | pixeltype: the reclassified band's pixel type, e.g. 8BUI, 16BUI, 32BF |
| 830 | |
| 831 | nodata: the nodata value of the reclassified band. If the source band has a nodata value, all source pixel value equal to the source nodata value will be converted to the reclassified band's nodata value. If set to NULL, the reclassified band will NOT have a nodata value specified. |
| 832 | |
| 833 | {{{ |
| 834 | ST_Reclass(rast, ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', NULL)); |
| 835 | |
| 836 | ST_Reclass(rast, ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001)); |
| 837 | |
| 838 | ST_Reclass(rast, |
| 839 | ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001), |
| 840 | ROW(2, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001), |
| 841 | ROW(3, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001), |
| 842 | ROW(5, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001) |
| 843 | ) |
| 844 | }}} |
| 845 | |
| 846 | An expanded example |
| 847 | |
| 848 | {{{ |
| 849 | SELECT ST_Reclass( |
| 850 | ST_Band(rast, ARRAY[1,1,1]), |
| 851 | ROW(1, LEAST(covmin, 0)::text || '-0:0,0-' || GREATEST(covmax, 0)::text || ':0-255', '8BUI'), |
| 852 | ROW(2, LEAST(covmin, 0)::text || '-0:200,0-' || GREATEST(covmax, 0)::text' || ':0-255','8BUI'), |
| 853 | ROW(3, LEAST(covmin, 0)::text || '-0:255,0-' || (GREATEST(covmax, 0)/2)::text' || ':0,' || (GREATEST(covmax, 0)/2)::text' || ':' || GREATEST(covmax, 0)::text || ':0-255', '8BUI') |
| 854 | ) |
| 855 | FROM mycoverage |
| 856 | }}} |
| 857 | |
| 858 | 2. ST_Reclass(rast raster, nband int, reclassexpr text, pixeltype text, nodata double) -> raster |
| 859 | |
| 860 | provides a method to process just one band of a raster |
| 861 | |
| 862 | {{{ |
| 863 | ST_Reclass(rast, 1, '0-100:0-10', '8BUI', 11) |
| 864 | }}} |
| 865 | |
| 866 | 3. ST_Reclass(rast raster, nband int, reclassexpr text, pixeltype text) -> raster |
| 867 | |
| 868 | nodata parameter removed so reclassified band will NOT have a nodata value set |
| 869 | |
| 870 | {{{ |
| 871 | ST_Reclass(rast, 1, '0-100:0-10', '8BUI') |
| 872 | }}} |
| 873 | |
| 874 | 4. ST_Reclass(rast raster, reclassexpr text, pixeltype text) -> raster |
| 875 | |
| 876 | nband parameter removed so reclassified band is assumed to be 1. nodata parameter removed so reclassified band has NO nodata value. |
| 877 | |
| 878 | {{{ |
| 879 | ST_Reclass(rast, '0-100:0-10', '8BUI') |
| 880 | }}} |
| 881 | |
| 882 | 5. ST_Reclass(rast raster, reclassexpr text, pixeltype text, nodata double) -> raster |
| 883 | |
| 884 | nband parameter removed so reclassified band is assumed to be 1 |
| 885 | |
| 886 | {{{ |
| 887 | ST_Reclass(rast, '0-100:0-10', '8BUI', 11) |
| 888 | }}} |
| 889 | |
| 890 | ---- |
| 891 | |
| 892 | == '''Objective FV.02 - Being able to intersect vector and raster to produce raster.''' == |
| 893 | |
| 894 | '''ST_Intersects(raster, raster) -> boolean'''[[BR]] |
| 895 | |
| 896 | This function uses the same tests as the two geometry version of ST_Intersects where tests see if two rasters overlap, touches or has one within the other. If any condition is true, the two rasters intersect. |
| 897 | |
| 898 | For this description, the rasters are called A and B and the bands tested are assumed to be 1. |
| 899 | |
| 900 | Preliminary criteria before the real work begins: |
| 901 | |
| 902 | 1. make sure that rasters A and B have the same SRID. if not, return false. |
| 903 | |
| 904 | 2. make sure that the convex hulls of A and B intersect. if not, return false. |
| 905 | |
| 906 | Special case where a raster may be fully contained within another raster's cell (the entirety of A within a cell of B): |
| 907 | |
| 908 | 1. using every third pixel by row and column, test each selected cell's geopoint (excluding no data by default unless exclude_nodata_value = FALSE) of A to that of B for overlap. |
| 909 | |
| 910 | 2. if a cell of A does overlap a cell of B, return true. |
| 911 | |
| 912 | 3. if no cell of A overlaps with B, continue to additional testing |
| 913 | |
| 914 | Actual testing involves the use of calculating the intersection of grid lines between A and B |
| 915 | |
| 916 | 1. Using every third A's column and B's row, calculate the intersection point of each pair of grid lines. |
| 917 | |
| 918 | 2. If intersection point doesn't exist or is outside the bounds of the end points comprising each grid line used, go back to step 1. |
| 919 | |
| 920 | 3. If intersection point exists and within bounds, sample the area around the intersection point by offset the intersection point by a small amount (1/10th of the smaller scale of A and B) for 360 degrees starting from 00:00. sampled points are 0, 45, 90, 135, 180, 225, 270 and 315 degrees. |
| 921 | |
| 922 | 4. At each sample point, test to see if the geopoint has non-nodata (unless including nodata) values in both A and B. if so, return true. |
| 923 | |
| 924 | 5. At the same time as step 4, build an adjacency matrix for the intersection to see if two non-overlapping pixels from A and B touch. |
| 925 | |
| 926 | 6. Once all sample points have been tested and no overlapping pixels found, the adjacency matrix is checked to see if any sampled pixel of A touched a sampled pixel of B. If two pixels touched, return true. |
| 927 | |
| 928 | 7. If after all the searching and testing, nothing intersects or touches, return false. |
| 929 | |
| 930 | A set of ST_Intersects functions for rasters: |
| 931 | |
| 932 | 1. ST_Intersects(raster rastA, raster rastB, integer bandA DEFAULT NULL, integer bandB DEFAULT NULL) -> boolean |
| 933 | |
| 934 | If bandA and bandB are NULL, only the convex hulls of the rasters will be tested. If bandA or bandB are provided, both parameters must be provided and not NULL. |
| 935 | |
| 936 | 2. ST_Intersects(raster rastA, integer bandA, raster rastB, integer bandB) -> boolean |
| 937 | |
| 938 | A refactored set of St_Intersects() for testing a raster and a geometry. The first set converts the geometry to a raster to see if the two rasters intersect. |
| 939 | |
| 940 | 3. ST_Intersects(rast raster, geom geometry, nband integer DEFAULT NULL) -> boolean |
| 941 | |
| 942 | 4. ST_Intersects(rast raster, nband integer, geom geometry) -> boolean |
| 943 | |
| 944 | The second set of ST_Intersects() for testing a raster and a geometry converts the raster to a geometry and sees if the geometries intersect. |
| 945 | |
| 946 | 5. ST_Intersects(geom geometry, rast raster, nband DEFAULT NULL) -> boolean |
| 947 | |
| 948 | The order in which the geometry and raster are passed into ST_Intersects determines which method of testing is used. If geometry is first, the raster is converted to a set of geometries. If raster is first, the geometry is converted to a raster. |
| 949 | |
| 950 | These set of functions are required because there are cases where ST_Intersects(raster, geometry) != ST_Intersects(geometry, raster). |
| 951 | |
| 952 | [[Image(st_intersects_triangle.png)]] |
| 953 | |
| 954 | In the image above, the black border denotes the boundary of a triangle polygon and the red within is the raster version of the geometry. The polygon touches the raster in blue while the red raster does not. |
| 955 | |
| 956 | '''ST_AsRaster(geometry, pixeltype, val, nodataval, ulx, uly, width, height, pixelsizex, pixelsizey, skewx, skewy) -> raster''' |
| 957 | |
| 958 | ST_AsRaster provides the ability convert a geometry into a raster. To create the raster, the X and Y scale or the width and height of the raster must be provided. |
| 959 | |
| 960 | The output raster will be in the same coordinate system as the source geometry. The only exception is for ST_AsRaster variations with a raster input parameter. |
| 961 | |
| 962 | 1. ST_AsRaster([[BR]] |
| 963 | geom geometry,[[BR]] |
| 964 | scalex double precision, scaley double precision,[[BR]] |
| 965 | gridx double precision DEFAULT NULL, gridy double precision DEFAULT NULL,[[BR]] |
| 966 | pixeltype text[] DEFAULT ARRAY!['8BUI']::text[],[[BR]] |
| 967 | value double precision[] DEFAULT ARRAY![1]::double precision[],[[BR]] |
| 968 | nodataval double precision[] DEFAULT ARRAY![0]::double precision[],[[BR]] |
| 969 | skewx double precision DEFAULT 0, skewy double precision DEFAULT 0,[[BR]] |
| 970 | touched boolean DEFAULT FALSE |
| 971 | ) -> raster |
| 972 | |
| 973 | geom: the geometry to convert to a raster. Can be any valid PostGIS geometry. |
| 974 | |
| 975 | scalex: the scale/pixel size in the X axis of the output raster. If scalex and scaley are zero (0), the output raster's scale will be autocomputed. |
| 976 | |
| 977 | scaley: the scale/pixel size in the Y axis of the output raster. If scalex and scaley are zero (0), the output raster's scale will be autocomputed. |
| 978 | |
| 979 | pixeltype: array of pixel types for each band. Each array element is a band. |
| 980 | |
| 981 | value: array of values to burn into the raster for the geometry. Each array element is a band. |
| 982 | |
| 983 | nodataval: array of nodata values to burn into the raster. Each array element is a band. If an array element is null, that band will not have a nodata value. |
| 984 | |
| 985 | upperleftx: the X value of the upper-left corner of the output raster |
| 986 | |
| 987 | upperlefty: the Y value of the upper-left corner of the output raster |
| 988 | |
| 989 | gridx: the X coordinate of a point on the grid to which the raster will be aligned. Value is in the raster's world coordinates. |
| 990 | |
| 991 | gridy: the Y coordinate of a point on the grid to which the raster will be aligned. Value is in the raster's world coordinates. |
| 992 | |
| 993 | skewx: the skew along the X axis of the raster. by default, the skew along the X axis is zero. |
| 994 | |
| 995 | skewy: the skew along the Y axis of the raster. by default, the skew along the X axis is zero. |
| 996 | |
| 997 | touched: from the GDAL man page for gdal_rasterize: "Enables the ALL_TOUCHED rasterization option so that all pixels touched by lines or polygons will be updated not just those one the line render path, or whose center point is within the polygon. Defaults to disabled for normal rendering rules." |
| 998 | |
| 999 | ''If the number of elements for pixeltype, value and nodataval do not match, the minimum number of elements will be used.'' |
| 1000 | |
| 1001 | 2. ST_AsRaster( |
| 1002 | geom geometry,[[BR]] |
| 1003 | scalex double precision, scaley double precision,[[BR]] |
| 1004 | pixeltype text[],[[BR]] |
| 1005 | value double precision[] DEFAULT ARRAY![1]::double precision[],[[BR]] |
| 1006 | nodataval double precision[] DEFAULT ARRAY![0]::double precision[],[[BR]] |
| 1007 | upperleftx double precision DEFAULT NULL, upperlefty double precision DEFAULT NULL,[[BR]] |
| 1008 | skewx double precision DEFAULT 0, skewy double precision DEFAULT 0,[[BR]] |
| 1009 | touched boolean DEFAULT FALSE |
| 1010 | ) -> raster |
| 1011 | |
| 1012 | 3. ST_AsRaster( |
| 1013 | geom geometry,[[BR]] |
| 1014 | width integer, height integer,[[BR]] |
| 1015 | gridx double precision DEFAULT NULL, gridy double precision DEFAULT NULL,[[BR]] |
| 1016 | pixeltype text[] DEFAULT ARRAY!['8BUI']::text[],[[BR]] |
| 1017 | value double precision[] DEFAULT ARRAY![1]::double precision[],[[BR]] |
| 1018 | nodataval double precision[] DEFAULT ARRAY![0]::double precision[],[[BR]] |
| 1019 | skewx double precision DEFAULT 0, skewy double precision DEFAULT 0,[[BR]] |
| 1020 | touched boolean DEFAULT FALSE |
| 1021 | ) -> raster |
| 1022 | |
| 1023 | 4. ST_AsRaster( |
| 1024 | geom geometry,[[BR]] |
| 1025 | width integer, height integer,[[BR]] |
| 1026 | pixeltype text[],[[BR]] |
| 1027 | value double precision[] DEFAULT ARRAY![1]::double precision[],[[BR]] |
| 1028 | nodataval double precision[] DEFAULT ARRAY![0]::double precision[],[[BR]] |
| 1029 | upperleftx double precision DEFAULT NULL, upperlefty double precision DEFAULT NULL,[[BR]] |
| 1030 | skewx double precision DEFAULT 0, skewy double precision DEFAULT 0,[[BR]] |
| 1031 | touched boolean DEFAULT FALSE |
| 1032 | ) -> raster |
| 1033 | |
| 1034 | 5. ST_AsRaster( |
| 1035 | geom geometry,[[BR]] |
| 1036 | scalex double precision, scaley double precision,[[BR]] |
| 1037 | gridx double precision, gridy double precision,[[BR]] |
| 1038 | pixeltype text,[[BR]] |
| 1039 | value double precision DEFAULT 1,[[BR]] |
| 1040 | nodataval double precision DEFAULT 0,[[BR]] |
| 1041 | skewx double precision DEFAULT 0, skewy double precision DEFAULT 0,[[BR]] |
| 1042 | touched boolean DEFAULT FALSE |
| 1043 | ) -> raster |
| 1044 | |
| 1045 | 6. ST_AsRaster( |
| 1046 | geom geometry,[[BR]] |
| 1047 | scalex double precision, scaley double precision,[[BR]] |
| 1048 | pixeltype text,[[BR]] |
| 1049 | value double precision DEFAULT 1,[[BR]] |
| 1050 | nodataval double precision DEFAULT 0,[[BR]] |
| 1051 | upperleftx double precision DEFAULT NULL, upperlefty double precision DEFAULT NULL,[[BR]] |
| 1052 | skewx double precision DEFAULT 0, skewy double precision DEFAULT 0,[[BR]] |
| 1053 | touched boolean DEFAULT FALSE |
| 1054 | ) -> raster |
| 1055 | |
| 1056 | 7. ST_AsRaster( |
| 1057 | geom geometry,[[BR]] |
| 1058 | width integer, height integer,[[BR]] |
| 1059 | gridx double precision, gridy double precision,[[BR]] |
| 1060 | pixeltype text,[[BR]] |
| 1061 | value double precision DEFAULT 1,[[BR]] |
| 1062 | nodataval double precision DEFAULT 0,[[BR]] |
| 1063 | skewx double precision DEFAULT 0, skewy double precision DEFAULT 0,[[BR]] |
| 1064 | touched boolean DEFAULT FALSE |
| 1065 | ) -> raster |
| 1066 | |
| 1067 | 8. ST_AsRaster( |
| 1068 | geom geometry,[[BR]] |
| 1069 | width integer, height integer,[[BR]] |
| 1070 | pixeltype text,[[BR]] |
| 1071 | value double precision DEFAULT 1,[[BR]] |
| 1072 | nodataval double precision DEFAULT 0,[[BR]] |
| 1073 | upperleftx double precision DEFAULT NULL, upperlefty double precision DEFAULT NULL,[[BR]] |
| 1074 | skewx double precision DEFAULT 0, skewy double precision DEFAULT 0,[[BR]] |
| 1075 | touched boolean DEFAULT FALSE |
| 1076 | ) -> raster |
| 1077 | |
| 1078 | 9. ST_AsRaster( |
| 1079 | geom geometry,[[BR]] |
| 1080 | ref raster,[[BR]] |
| 1081 | pixeltype text[] DEFAULT ARRAY!['8BUI']::text[],[[BR]] |
| 1082 | value double precision[] DEFAULT ARRAY![1]::double precision[],[[BR]] |
| 1083 | nodataval double precision[] DEFAULT ARRAY![0]::double precision[],[[BR]] |
| 1084 | touched boolean DEFAULT FALSE |
| 1085 | ) -> raster |
| 1086 | |
| 1087 | 10. ST_AsRaster( |
| 1088 | geom geometry,[[BR]] |
| 1089 | ref raster,[[BR]] |
| 1090 | pixeltype text,[[BR]] |
| 1091 | value double precision DEFAULT 1,[[BR]] |
| 1092 | nodataval double precision DEFAULT 0,[[BR]] |
| 1093 | touched boolean DEFAULT FALSE |
| 1094 | ) -> raster |
| 1095 | |
| 1096 | |
| 1097 | ~~ * Rasterize the provided geometry to a raster created using the specified parameters.~~ |
| 1098 | ~~ * Implemented as a wrapper around GDAL like ST_DumpAsPolygons() does.~~ |
| 1099 | ~~ * ST_AsRaster is necessary to implement ST_Intersection(geometry, raster, band) -> raster and an eventual ST_BurnToRaster(raster, geometry) -> raster where the provided geometry is first rasterized to the same alignment as the other raster involved.~~ |
| 1100 | ~~ * Each geometry of a table is rasterized as one raster. To produce a global unique raster including all the geometries of a table (loosing overlaps by the way), a user must use the planned ST_Union aggregate function to merge all the rasters together optionally in a GROUP BY query grouping some rows together.~~ |
| 1101 | |
| 1102 | ~~ * The raster is burned with the specified value converted (or truncated) with a warning to the provided pixeltype. The hasnodatavalue flag of the resulting raster must be set and the nodata value is set to the provided value (expect in variant 10 and 12).~~ |
| 1103 | |
| 1104 | ~~ * Alignment, width, height and pixelsize are optionally computed:~~[[BR]] |
| 1105 | ~~ -From the vector extent of the geometry,~~[[BR]] |
| 1106 | ~~ -Imposed with parameters,~~[[BR]] |
| 1107 | ~~ -From another provided raster.~~ |
| 1108 | |
| 1109 | ~~ * Alignment can be optionally specified as:~~[[BR]] |
| 1110 | ~~ -A x and a y world coordinates specifying an arbitrary pixel corner. Although it can be, it IS NOT necessarily the coordinates of the upper left corner pixel.~~[[BR]] |
| 1111 | ~~ -A ulx and a uly world coordinates specifying the upperleft corner of the raster. This IS NECESSARILY the upper left corner of the upperleft pixel. In this case a width and a height must also be provided.~~[[BR]] |
| 1112 | ~~ -An existing raster. The x and y are derived from the provided raster and the resulting raster has the same ulx, uly, width and height as the provided raster. A 'CROP' option allows cropping the resulting raster to the minimal extent of the geometry keeping the x and y alignment of the provided raster.~~[[BR]] |
| 1113 | ~~ -Default alignment is the upper left corner of the envelope of the geometry. This might result in table where all rasters are misaligned, but this is useful when reconverting to raster a set of polygons vectorized from rasters (with ST_DumpAsPolygon() or ST_Intersection()).~~ |
| 1114 | |
| 1115 | ~~ * Pixelsize can be optionally specified as:~~[[BR]] |
| 1116 | ~~ -One or two floating point numbers. If only one is provided, both x and y pixelsizes are assigned the same value.~~[[BR]] |
| 1117 | ~~ -A width and a height (integers). In this case the x pixelsize is the x extent divided by the provided width and the y pixelsize is the y extent divided by the provided height. This is useful only when the alignment is specified as the upper left corner of the raster.~~[[BR]] |
| 1118 | ~~ -“FIRST_SEGMENT_LENGTH”. The pixelsize is set to the length of the first line segment encountered in the geometry. This is useful when reconverting to raster polygons vectorized from rasters (with ST_DumpAsPolygon() or ST_Intersection()). In this case, all segments are of the same length which is the original raster pixel size. This is useful only when alignment is not specified. If the geometry is a point, return an error.~~[[BR]] |
| 1119 | ~~ -Default is the smallest of the width or height of the extent of the source geometry divided by 250. If the smallest of the width or height of the extent of the source geometry is zero then a warning is reported an no NULL is returned.~~ |
| 1120 | |
| 1121 | ~~ * It would be interesting to have a 'ADD_WEIGHTING_INFO' option to create a second band with the length of the line or the area of polygon (or the distance to the center of points) intersecting each pixel. This band could then be used in a ST_Union(rast, 'MAX_LENGTH') or a ST_Union(rast, 'MAX_AREA') function burning the value of the line having the longest intersection with the pixel or the value of the polygon having the biggest intersecting area. For this to be useful ST_Union should work with a ST_MapAlgebra(rast1, rast2) able to refer to pixel value in any band (e.g. rast1.2 referring to the pixel value in the second band). The ST_Union(rast, 'MAX_LENGTH') aggregate could then be implemented with the following state expression: 'CASE WHEN rast1.2 > rast2.2 THEN rast1.1 ELSE rast2.1 ENDIF'. Otherwise we would have to imbricate four Mapalgebra functions. ST_Union(rast, 'MAX_COMBINED_LENGTH') could use a ST_MapAlgebra(rast1, rast2) able to take a custom user function. The state function would accumulate, in a temporary table, the total intersecting length or area for a same value over every overlapping pixels and the final function would determine which of the values from the temporary table would be the right one to burn in the final raster pixel. Variations of ST_Union which could then be easily implemented could be: ST_Union(rast, 'WEIGHTED') to weight the value with the length, the area or the count, ST_Union(rast, 'MOST_FREQUENT') to burn the value for the most frequent points values.~~ |
| 1122 | |
| 1123 | ~~ '''Variants'''~~ |
| 1124 | |
| 1125 | ~~ * There are many variants because we are creating a raster from scratch. We want to make it easy (serie one and four) to convert geometries to raster and at the same time we want to have flexibility to control the resulting raster properties (series two and three).~~ |
| 1126 | ~~ * Variant 3, 5 and 13 are the most useful.~~ |
| 1127 | ~~ * Variant 6, 7, 8, 9, 10, 11, 12 are also useful.~~ |
| 1128 | ~~ * Variant 1, 2, 4 are useful for quick conversion.~~ |
| 1129 | ~~ * All variant should be pl/pgsql variant of variant 9 which is the only one needing to be implemented as a rt_pg functions.~~ |
| 1130 | |
| 1131 | ~~ * The '''first series of variant''' get their alignment from the extent of the geometry.~~ |
| 1132 | |
| 1133 | ~~ 1) ST_AsRaster(geometry, pixeltype, val, nodataval) – 0, alignment is computed from the geometry envelope, pixel size is computed by dividing the extent by 250. This variant is optional and discouraged as it results in many unaligned rasters for a table with many geometries.~~ |
| 1134 | |
| 1135 | ~~ 2) ST_AsRaster(geometry, pixeltype, val, nodataval, pixelsize float8) – 1, x and y are computed from upper left corner it the geometry envelope. This variant is optional and discouraged as it results in many unaligned rasters for a table with many geometries.~~ |
| 1136 | |
| 1137 | ~~ 3) ST_AsRaster(geometry, pixeltype, val, nodataval, ‘FIRST_SEGMENT_LENGTH’) – 0, ulx and uly are get from the envelope, pixel size from the length of the first segment. This variant is useful only to rasterize geometries produced by ST_DumpAsPolygon or ST_Intersection. Otherwise it discouraged as it would result in many unaligned rasters for a table with many geometries.~~ |
| 1138 | |
| 1139 | ~~ * The '''second series of variant''' have their alignment specified by an arbitrary pixel corner of the desired raster.~~ |
| 1140 | |
| 1141 | ~~ 4) ST_AsRaster(geometry, pixeltype, val, nodataval, x float8, y float8) – 2, pixel size is computed by dividing the extent by 250. This variant is optional and discouraged as it results in many unaligned rasters for a table with many geometries.~~ |
| 1142 | |
| 1143 | ~~ 5) ST_AsRaster(geometry, pixeltype, val, nodataval, x float8, y float8, pixelsize) – 3, this is one of the preferred variant when the geometry is not the result of ST_DumpAsPolygon or ST_Intersection.~~ |
| 1144 | |
| 1145 | ~~ 6) ST_AsRaster(geometry, pixeltype, val, nodataval, x float8, y float8, pixelsizex, pixelsizey) - 4, this is one of the preferred variant when the geometry is not the result of ST_DumpAsPolygon or ST_Intersection.~~ |
| 1146 | |
| 1147 | ~~ 7) ST_AsRaster(geometry, pixeltype, val, nodataval, x float8, y float8, pixelsizex, pixelsizey, skewx, skewy) – 6, this is one of the preferred variant when the geometry is not the result of ST_DumpAsPolygon or ST_Intersection.~~ |
| 1148 | |
| 1149 | ~~ * The '''third series of variant''' have their alignment specified by the upper left corner of the upper left pixel of the desired raster.~~ |
| 1150 | |
| 1151 | ~~ 8) ST_AsRaster(geometry, pixeltype, val, nodataval, ulx, uly, width, height, pixelsize) – 2,2,1, this is useful to rasterize geometries to a common raster extent. Some geometries might be outside the extent of the desired raster extent resulting in a nodata value raster.~~ |
| 1152 | |
| 1153 | ~~ 9) ST_AsRaster(geometry, pixeltype, val, nodataval, ulx, uly, width, height, pixelsizex, pixelsizey, skewx, skewy) – 2,2,4, this is useful to rasterize geometries to a common raster extent. Some geometries might be outside the extent of the desired raster extent resulting in a nodata value raster. This is the only variant which must be implemented in the tr_pg layer. All other variant must be implemented in pl/PgSQL and derive the argument to call this variant.~~ |
| 1154 | |
| 1155 | ~~ * The '''fourth series of variant''' get their alignment (and size for variant 10 and 12) from an existing raster. Variant 10 and 11 keep the same extent as the provided raster and variant 12 and 13 have their extent cropped to the extent of the geometry.~~ |
| 1156 | |
| 1157 | ~~ 10) ST_AsRaster(geometry, val, raster) – 0, the target raster metadata (including pixeltype, hasnodatavalue and nodatavalue) are copied from the provided raster~~ |
| 1158 | |
| 1159 | ~~ 11) ST_AsRaster(geometry, pixeltype, val, nodataval, raster) – 0, the target raster metadata are copied from the provided raster.~~ |
| 1160 | |
| 1161 | ~~ 12) ST_AsRaster(geometry, val, raster, “CROP”) – 0, the target raster alignment and pixel size are copied from the provided raster (including pixeltype, hasnodatavalue and nodatavalue) but the extent is reduced to the geometry extent. We should not create a (too big) raster and crop at the end. The final extent should be computed BEFORE burning.~~ |
| 1162 | |
| 1163 | ~~ 13) ST_AsRaster(geometry, pixeltype, val, nodataval, raster, “CROP”) – 0, the target raster alignment and pixel size are copied from the provided raster but the extent is reduced to the geometry extent. We should not create a (too big) raster and crop at the end. The final extent should be computed BEFORE burning.~~ |
| 1164 | |
| 1165 | ~~ '''Questions'''~~ |
| 1166 | |
| 1167 | ~~ -How does GDAL/ArcGIS choose the pixel size and the ul of the final raster?~~ |
| 1168 | |
| 1169 | ~~ -How does GDAL/ArcGIS allow selecting the value column -What if it is a text column?~~ |
| 1170 | |
| 1171 | ~~ -How does GDAL/ArcGIS allow giving a thickness to points and lines -No thickness is given. All pixels intersecting the geometry are burned following a selected method.~~ |
| 1172 | |
| 1173 | ~~ -How does GDAL/ArcGIS select which value to assign to the pixel when two or more features intersect with the pixel?~~ |
| 1174 | |
| 1175 | '''ST_Intersection(raster, band, geometry) -> raster''' |
| 1176 | |
| 1177 | ST_Intersection is plpgsql function wrapping the two-raster ST_MapAlgebra functions. Performance should be about the same as calling ST_MapAlgebra directly except for the case where returnband is BOTH as that results in two separate ST_MapAlgebra calls. |
| 1178 | |
| 1179 | A set of ST_Intersection functions for raster, raster. |
| 1180 | |
| 1181 | {{{ |
| 1182 | 1. ST_Intersection( |
| 1183 | rast1 raster, nband1 int, |
| 1184 | rast2 raster, nband2 int, |
| 1185 | returnband text DEFAULT 'BOTH', |
| 1186 | otheruserfunc regprocedure DEFAULT NULL |
| 1187 | ); |
| 1188 | }}} |
| 1189 | |
| 1190 | returnband: can be FIRST, SECOND, BOTH, OTHER |
| 1191 | |
| 1192 | * FIRST returns the band of rast1 in the intersecting extent. returning raster will have one band. |
| 1193 | * SECOND returns the band of rast2 in the intersecting extent. returning raster will have one band. |
| 1194 | * BOTH returns the bands of rast1 and rast2 in the intersection extent. returning raster will have two bands. |
| 1195 | * OTHER returns the computed band based upon rast1 and rast2 in the intersecting extent. returning raster will have one band. If OTHER, must provide a regprocedure to otherfunc |
| 1196 | |
| 1197 | otheruserfunc: function to call when returnband = OTHER. Function format must be identical to tworastuserfunc of 2-raster ST_MapAlgebraFct. |
| 1198 | |
| 1199 | {{{ |
| 1200 | 2. ST_Intersection( |
| 1201 | rast1 raster, nband1 int, |
| 1202 | rast2 raster, nband2 int, |
| 1203 | otheruserfunc regprocedure |
| 1204 | ); |
| 1205 | }}} |
| 1206 | |
| 1207 | {{{ |
| 1208 | 3. ST_Intersection( |
| 1209 | rast1 raster, |
| 1210 | rast2 raster, |
| 1211 | returnband text DEFAULT 'BOTH', |
| 1212 | otheruserfunc regprocedure DEFAULT NULL |
| 1213 | ); |
| 1214 | }}} |
| 1215 | |
| 1216 | {{{ |
| 1217 | 4. ST_Intersection( |
| 1218 | rast1 raster, |
| 1219 | rast2 raster, |
| 1220 | otheruserfunc regprocedure |
| 1221 | ); |
| 1222 | }}} |
| 1223 | |
| 1224 | A set of ST_Intersection functions for raster, geometry (converted to raster). |
| 1225 | |
| 1226 | {{{ |
| 1227 | 1. ST_Intersection( |
| 1228 | rast raster, nband int, |
| 1229 | geom geometry, |
| 1230 | extent text DEFAULT 'INTERSECTION', |
| 1231 | otheruserfunc regprocedure DEFAULT NULL |
| 1232 | ) |
| 1233 | }}} |
| 1234 | |
| 1235 | extent: can be INTERSECTION, FIRST, SECOND, UNION though FIRST and INTERSECTION will probably be the most commonly used |
| 1236 | |
| 1237 | {{{ |
| 1238 | 2. ST_Intersection( |
| 1239 | rast raster, nband int, |
| 1240 | geom geometry, |
| 1241 | otheruserfunc regprocedure |
| 1242 | ); |
| 1243 | }}} |
| 1244 | |
| 1245 | {{{ |
| 1246 | 3. ST_Intersection( |
| 1247 | rast raster, |
| 1248 | geom geometry, |
| 1249 | extent text DEFAULT 'INTERSECTON', |
| 1250 | otheruserfunc regprocedure DEFAULT NULL |
| 1251 | ); |
| 1252 | }}} |
| 1253 | |
| 1254 | {{{ |
| 1255 | 4. ST_Intersection( |
| 1256 | rast raster, |
| 1257 | geom geometry, |
| 1258 | otheruserfunc regprocedure |
| 1259 | ); |
| 1260 | }}} |
| 1261 | |
| 1262 | ~~ The first series of variant return a raster having the same extent as the provided raster. |
| 1263 | |
| 1264 | ~~ Variant 1: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue) -> raster |
| 1265 | |
| 1266 | ~~ Variant 2: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue) -> raster |
| 1267 | |
| 1268 | ~~ Variant 3: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue) -> raster |
| 1269 | |
| 1270 | ~~ Variant 4: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue) -> raster |
| 1271 | |
| 1272 | ~~ The second series of variant return a raster having the minimal extent. |
| 1273 | |
| 1274 | ~~ Variant 5: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue, 'TRIM') -> raster |
| 1275 | |
| 1276 | ~~ Variant 6: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue, 'TRIM') -> raster |
| 1277 | |
| 1278 | ~~ Variant 7: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue, 'TRIM') -> raster |
| 1279 | |
| 1280 | ~~ Variant 8: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue, 'TRIM') -> raster |
| 1281 | |
| 1282 | ~~ Returns a two bands raster the first band containing only the pixels from the provided raster intersecting with the geometry and the second band containing the same area filled with the provided value. |
| 1283 | |
| 1284 | ~~ The second band gets its pixeltype and nodatavalue from the parameters. |
| 1285 | |
| 1286 | ~~ Non intersecting pixels are filled with nodata values. |
| 1287 | |
| 1288 | ~~ Variant 1 return a raster having the same extent as the provided raster. |
| 1289 | |
| 1290 | ~~ Variant 3, 4, 7 and 8 defaults the band number to 1. |
| 1291 | |
| 1292 | ~~ Variant 5 to 8 "trim" or "crop" the raster to the withvalue extent (removing extra nodata value pixels surrounding the extent of the resulting withvalue extent). |
| 1293 | |
| 1294 | |
| 1295 | ~~ '''Open questions''' |
| 1296 | |
| 1297 | ~~ PR: Shoud we return one raster per raster/geometry couple or split the raster into as many small rasters as there are areas sharing a same value? The second behavior seems more coherent with the present behavior of ST_Intersection(raster, geometry) -> geometry even if this would produce tons of small two bands rasters. |
| 1298 | |
| 1299 | ~~ '''Implementation details''' |
| 1300 | |
| 1301 | ~~ Rasterize the geometry as a new raster (ST_AsRaster(geometry, pixeltype, val, nodataval, raster)) and then copy only pixels for which both raster bands have a value. |
| 1302 | ~~ Should be implemented as a wrapper around ST_MapAlgebra after rasterizing the geometry to a raster having the same alignment as the raster. |
| 1303 | |
| 1304 | ---- |
| 1305 | |
| 1306 | == '''Objective FV.03 - ST_MapAlgebra (1 and 2 raster variants)''' == |
| 1307 | |
| 1308 | '''Two raster ST_MapAlgebra''' |
| 1309 | |
| 1310 | These set of functions take two input rasters and create a 1-band output raster with the extent defined by extenttype. |
| 1311 | |
| 1312 | |
| 1313 | 1. ST_MapAlgebraExpr( |
| 1314 | rast1 raster, band1 integer,[[BR]] |
| 1315 | rast2 raster, band2 integer,[[BR]] |
| 1316 | expression text,[[BR]] |
| 1317 | pixeltype text DEFAULT NULL, extenttype text DEFAULT 'INTERSECTION',[[BR]] |
| 1318 | nodata1expr text DEFAULT NULL, nodata2expr text DEFAULT NULL,[[BR]] |
| 1319 | nodatanodataval double precision DEFAULT NULL |
| 1320 | ) -> raster |
| 1321 | |
| 1322 | rast1: the FIRST raster upon which a map algebra operation is to be done |
| 1323 | |
| 1324 | band1: the band index (1-based) of the FIRST raster upon whose pixels a map algebra operation is to be done |
| 1325 | |
| 1326 | rast2: the SECOND raster upon which a map algebra operation is to be done |
| 1327 | |
| 1328 | band2: the band index (1-based) of the SECOND raster upon whose pixels a map algebra operation is to be done |
| 1329 | |
| 1330 | expression: valid SQL expression resulting in a double precision value or NULL. called when band 1 pixel AND band 2 pixel are NOT NODATA |
| 1331 | |
| 1332 | pixeltype: the datatype of the output raster's one band |
| 1333 | |
| 1334 | extenttype: one of the following (INTERSECTION, UNION, FIRST, SECOND) |
| 1335 | |
| 1336 | nodata1expr: valid SQL expression resulting in a double precision value or NULL. called when band 1 pixel IS NODATA and band 2 pixel IS NOT NODATA |
| 1337 | |
| 1338 | nodata2expr: valid SQL expression resulting in a double precision value or NULL. called when band 1 pixel IS NOT NODATA and band 2 pixel IS NODATA |
| 1339 | |
| 1340 | nodatanodataval: double precision value used when band1 pixel and band 2 pixel are NODATA |
| 1341 | |
| 1342 | {{{ |
| 1343 | ST_MapAlgebraExpr(r1.rast, 1, r2.rast, 2, 'rast1', '32BF', 'INTERSECTION') |
| 1344 | |
| 1345 | ST_MapAlgebraExpr(r1.rast, 1, r2.rast, 2, '((rast1 + rast2)/2.)::numeric', '32BF', 'UNION', 'rast2', 'rast1', NULL) |
| 1346 | |
| 1347 | ST_MapAlgebraExpr(r1.rast, 1, r2.rast, 2, 'CASE WHEN rast2 IS NOT NULL THEN NULL ELSE rast1 END', '32BF', 'FIRST', NULL, 'rast1', NULL) |
| 1348 | |
| 1349 | ST_MapAlgebraExpr(r1.rast, 1, r2.rast, 2, 'CASE WHEN rast1 IS NOT NULL THEN NULL ELSE rast2 END', '32BF', 'SECOND', 'rast2', NULL, NULL) |
| 1350 | }}} |
| 1351 | |
| 1352 | 2. ST_MapAlgebraExpr( |
| 1353 | rast1 raster,[[BR]] |
| 1354 | rast2 raster,[[BR]] |
| 1355 | expression text,[[BR]] |
| 1356 | pixeltype text DEFAULT NULL, extenttype text DEFAULT 'INTERSECTION',[[BR]] |
| 1357 | nodata1expr text DEFAULT NULL, nodata2expr text DEFAULT NULL,[[BR]] |
| 1358 | nodatanodataval double precision DEFAULT NULL |
| 1359 | ) -> raster |
| 1360 | |
| 1361 | {{{ |
| 1362 | ST_MapAlgebraExpr(r1.rast, r2.rast, 'rast1', '32BF', 'INTERSECTION') |
| 1363 | |
| 1364 | ST_MapAlgebraExpr(r1.rast, r2.rast, '((rast1 + rast2)/2.)::numeric', '32BF', 'UNION', 'rast2', 'rast1', NULL) |
| 1365 | |
| 1366 | ST_MapAlgebraExpr(r1.rast, r2.rast, 'CASE WHEN rast2 IS NOT NULL THEN NULL ELSE rast1 END', '32BF', 'FIRST', NULL, 'rast1', NULL) |
| 1367 | |
| 1368 | ST_MapAlgebraExpr(r1.rast, r2.rast, 'CASE WHEN rast1 IS NOT NULL THEN NULL ELSE rast2 END', '32BF', 'SECOND', 'rast2', NULL, NULL) |
| 1369 | }}} |
| 1370 | |
| 1371 | This set of 2-raster ST_MapAlgebra functions require a user-provided function instead of expressions. The user-provided function must receive three parameters (two double precision and one VARIADIC text array) and returns one double precision value. A template for this user-provided function would be: |
| 1372 | |
| 1373 | {{{ |
| 1374 | CREATE OR REPLACE FUNCTION userfunction(rast1 double precision, rast2 double precision, VARIADIC arg text[]) |
| 1375 | RETURNS double precision |
| 1376 | AS $$ |
| 1377 | DECLARE |
| 1378 | BEGIN |
| 1379 | -- your code here |
| 1380 | END; |
| 1381 | $$ |
| 1382 | LANGUAGE 'plpgsql'; |
| 1383 | }}} |
| 1384 | |
| 1385 | The function should be able to support a NULL input parameter. The function may also be STRICT. |
| 1386 | |
| 1387 | 1. ST_MapAlgebraFct( |
| 1388 | rast1 raster, band1 integer,[[BR]] |
| 1389 | rast2 raster, band2 integer,[[BR]] |
| 1390 | userfunction regprocedure,[[BR]] |
| 1391 | pixeltype text DEFAULT NULL, extenttype text DEFAULT 'INTERSECTION',[[BR]] |
| 1392 | VARIADIC userargs text[] DEFAULT NULL |
| 1393 | ) |
| 1394 | |
| 1395 | {{{ |
| 1396 | ST_MapAlgebraFct(r1.rast, 1, r2.rast, 1, 'raster_mapalgebra_intersection(double precision, double precision, text[])'::regprocedure, '32BF', 'INTERSECTION') |
| 1397 | }}} |
| 1398 | |
| 1399 | 2. ST_MapAlgebraFct( |
| 1400 | rast1 raster,[[BR]] |
| 1401 | rast2 raster,[[BR]] |
| 1402 | userfunction regprocedure,[[BR]] |
| 1403 | pixeltype text DEFAULT NULL, extenttype text DEFAULT 'INTERSECTION',[[BR]] |
| 1404 | VARIADIC userargs text[] DEFAULT NULL |
| 1405 | ) |
| 1406 | |
| 1407 | {{{ |
| 1408 | ST_MapAlgebraFct(r1.rast, r2.rast, 'raster_mapalgebra_intersection(double precision, double precision, text[])'::regprocedure, '32BF', 'INTERSECTION') |
| 1409 | }}} |
| 1410 | |
| 1411 | ---- |
| 1412 | == '''Objective FV.14 - Being able to intersect two rasters to get a raster.''' == |
| 1413 | |
| 1414 | '''ST_Intersection(raster, integer, raster, integer) -> raster''' - Returns a two bands raster with values only in the intersecting areas of both rasters. Integer parameters are the band number of the raster. |
| 1415 | |
| 1416 | Please look at ST_Intersection(raster, geometry) in FV.01 for complete specs. |
| 1417 | |
| 1418 | ~~ '''Variants''' |
| 1419 | |
| 1420 | ~~ 1) ST_Intersection(raster, integer, raster, integer) -> raster -- the integer parameters are the band number of the rasters[[BR]] |
| 1421 | ~~ 2) ST_Intersection(raster, raster, integer) -> raster -- default first raster to band # 1[[BR]] |
| 1422 | ~~ 3) ST_Intersection(raster, integer, raster) -> raster -- default second raster to band # 1[[BR]] |
| 1423 | ~~ 4) ST_Intersection(raster, raster) -> raster -- default both rasters to band # 1 |
| 1424 | |
| 1425 | ---- |
| 1426 | == '''Objective FV.16 - Being able to quickly get raster statistics. - ''Done''''' == |
| 1427 | |
| 1428 | '''Add cached basic raster statistic to the base raster WKB format. |
| 1429 | |
| 1430 | Statistics to be cached should include: |
| 1431 | |
| 1432 | min/max[[BR]] |
| 1433 | mean[[BR]] |
| 1434 | standard deviation[[BR]] |
| 1435 | histogram[[BR]] |
| 1436 | build parameters of stats (sample rate, method used to determine # of bins in histogram?)[[BR]] |
| 1437 | |
| 1438 | How are the statistics to be kept fresh? Automatically using some method to see how much of the raster has changed since the last stats calculation? Or let the user decide? |
| 1439 | |
| 1440 | ---- |
| 1441 | |
| 1442 | '''ST_SummaryStats(raster, nband) -> record'''[[BR]] |
| 1443 | 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. |
| 1444 | |
| 1445 | 1. ST_SummaryStats(rast raster, nband int, exclude_nodata_value boolean) -> record |
| 1446 | |
| 1447 | returns one record of five columns (count, mean, stddev, min, max) |
| 1448 | |
| 1449 | nband: index of band |
| 1450 | |
| 1451 | exclude_nodata_value: if FALSE, nodata values in band are included in the stats. if TRUE, nodata values are not included |
| 1452 | |
| 1453 | {{{ |
| 1454 | ST_SummaryStats(rast, 1, FALSE) |
| 1455 | }}} |
| 1456 | |
| 1457 | 2. ST_SummaryStats(rast raster, nband int) -> record |
| 1458 | |
| 1459 | assumes exclude_nodata_value = TRUE |
| 1460 | |
| 1461 | {{{ |
| 1462 | ST_SummaryStats(rast, 2) |
| 1463 | }}} |
| 1464 | |
| 1465 | 3. ST_SummaryStats(rast raster, exclude_nodata_value boolean) -> record |
| 1466 | |
| 1467 | assumes nband = 1 |
| 1468 | |
| 1469 | {{{ |
| 1470 | ST_SummaryStats(rast, TRUE) |
| 1471 | }}} |
| 1472 | |
| 1473 | 4. ST_SummaryStats(rast raster) -> record |
| 1474 | |
| 1475 | assumes nband = 1 and exclude_nodata_value = TRUE |
| 1476 | |
| 1477 | {{{ |
| 1478 | ST_SummaryStats(rast) |
| 1479 | }}} |
| 1480 | |
| 1481 | 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... |
| 1482 | |
| 1483 | 1. select the larger dimension of the width and height. compute the number of pixels to sample in each "row" of the larger dimension |
| 1484 | |
| 1485 | 2. pick pixels from each "row" of the larger dimension in an incremental rolling manner where each increment is randomly determined. |
| 1486 | |
| 1487 | The set of ST_ApproxSummaryStats functions are: |
| 1488 | |
| 1489 | 1. ST_ApproxSummaryStats(rast raster, nband int, exclude_nodata_value boolean, sample_percent double precision) -> record |
| 1490 | |
| 1491 | sample_percent: a value between 0 and 1 indicating the percentage of the raster band's pixels to consider |
| 1492 | |
| 1493 | {{{ |
| 1494 | ST_ApproxSummaryStats(rast, 3, FALSE, 0.1) |
| 1495 | |
| 1496 | ST_ApproxSummaryStats(rast, 1, TRUE, 0.5) |
| 1497 | }}} |
| 1498 | |
| 1499 | 2. ST_ApproxSummaryStats(rast raster, nband int, sample_percent double precision) -> record |
| 1500 | |
| 1501 | assumes that nband = 1 |
| 1502 | |
| 1503 | {{{ |
| 1504 | ST_ApproxSummaryStats(rast, 2 0.01) |
| 1505 | |
| 1506 | ST_ApproxSummaryStats(rast, 4, 0.025) |
| 1507 | }}} |
| 1508 | |
| 1509 | 3. ST_ApproxSummaryStats(rast raster, exclude_nodata_value boolean, sample_percent double precision) -> record |
| 1510 | |
| 1511 | assumes that nband = 1 |
| 1512 | |
| 1513 | {{{ |
| 1514 | ST_ApproxSummaryStats(rast, FALSE, 0.01) |
| 1515 | |
| 1516 | ST_ApproxSummaryStats(rast, TRUE, 0.025) |
| 1517 | }}} |
| 1518 | |
| 1519 | 4. ST_ApproxSummaryStats(rast raster, sample_percent double precision) -> record |
| 1520 | |
| 1521 | assumes that nband = 1 and exclude_nodata_value = TRUE |
| 1522 | |
| 1523 | {{{ |
| 1524 | ST_ApproxSummaryStats(rast, 0.25) |
| 1525 | }}} |
| 1526 | |
| 1527 | 5. ST_ApproxSummaryStats(rast raster) -> record |
| 1528 | |
| 1529 | assumes that nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 1530 | |
| 1531 | {{{ |
| 1532 | ST_ApproxSummaryStats(rast) |
| 1533 | }}} |
| 1534 | |
| 1535 | 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. |
| 1536 | |
| 1537 | 1. ST_SummaryStats(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean) -> record |
| 1538 | |
| 1539 | rastertable: name of table with raster column |
| 1540 | |
| 1541 | rastercolumn: name of column of data type raster |
| 1542 | |
| 1543 | {{{ |
| 1544 | ST_SummaryStats('tmax_2010', 'rast', 1, FALSE) |
| 1545 | |
| 1546 | ST_SummaryStats('precip_2011', 'rast', 1, TRUE) |
| 1547 | }}} |
| 1548 | |
| 1549 | 2. ST_SummaryStats(rastertable text, rastercolumn text, nband int) -> record |
| 1550 | |
| 1551 | exclude_nodata_value = TRUE |
| 1552 | |
| 1553 | {{{ |
| 1554 | ST_SummaryStats('tmax_2010', 'rast', 1) |
| 1555 | }}} |
| 1556 | |
| 1557 | 3. ST_SummaryStats(rastertable text, rastercolumn text, exclude_nodata_value boolean) -> record |
| 1558 | |
| 1559 | nband = 1 |
| 1560 | |
| 1561 | {{{ |
| 1562 | ST_SummaryStats('precip_2011', 'rast', TRUE) |
| 1563 | }}} |
| 1564 | |
| 1565 | 4. ST_SummaryStats(rastertable text, rastercolumn text) -> record |
| 1566 | |
| 1567 | nband = 1 and exclude_nodata_value = TRUE |
| 1568 | |
| 1569 | {{{ |
| 1570 | ST_SummaryStats('tmin_2009', 'rast') |
| 1571 | }}} |
| 1572 | |
| 1573 | Variations for ST_ApproxSummaryStats are: |
| 1574 | |
| 1575 | 1. ST_ApproxSummaryStats(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean, sample_percent double precision) -> record |
| 1576 | |
| 1577 | {{{ |
| 1578 | ST_ApproxSummaryStats('tmax_2010', 'rast', 1, FALSE, 0.5) |
| 1579 | |
| 1580 | ST_ApproxSummaryStats('precip_2011', 'rast', 1, TRUE, 0.2) |
| 1581 | }}} |
| 1582 | |
| 1583 | 2. ST_ApproxSummaryStats(rastertable text, rastercolumn text, nband int, sample_percent double precision) -> record |
| 1584 | |
| 1585 | exclude_nodata_value = TRUE |
| 1586 | |
| 1587 | {{{ |
| 1588 | ST_ApproxSummaryStats('tmax_2010', 'rast', 1, 0.5) |
| 1589 | |
| 1590 | ST_ApproxSummaryStats('precip_2011', 'rast', 1, 0.2) |
| 1591 | }}} |
| 1592 | |
| 1593 | 3. ST_ApproxSummaryStats(rastertable text, rastercolumn text, exclude_nodata_value boolean, sample_percent double precision) -> record |
| 1594 | |
| 1595 | nband = 1 |
| 1596 | |
| 1597 | {{{ |
| 1598 | ST_ApproxSummaryStats('tmax_2010', 'rast', FALSE, 0.5) |
| 1599 | |
| 1600 | ST_ApproxSummaryStats('precip_2011', 'rast', TRUE, 0.2) |
| 1601 | }}} |
| 1602 | |
| 1603 | 4. ST_ApproxSummaryStats(rastertable text, rastercolumn text, sample_percent double precision) -> record |
| 1604 | |
| 1605 | nband = 1 and exclude_nodata_value = TRUE |
| 1606 | |
| 1607 | {{{ |
| 1608 | ST_ApproxSummaryStats('tmax_2010', 'rast', 0.5) |
| 1609 | |
| 1610 | ST_ApproxSummaryStats('precip_2011', 'rast', 0.2) |
| 1611 | }}} |
| 1612 | |
| 1613 | 5. ST_ApproxSummaryStats(rastertable text, rastercolumn text) -> record |
| 1614 | |
| 1615 | nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 1616 | |
| 1617 | {{{ |
| 1618 | ST_ApproxSummaryStats('tmax_2010', 'rast') |
| 1619 | |
| 1620 | ST_ApproxSummaryStats('precip_2011', 'rast') |
| 1621 | }}} |
| 1622 | |
| 1623 | The mean returned in the coverage functions (has rastertable and rastercolumn arguments) is the true mean of the raster tiles. The standard deviation returned is the standard deviation of all raster tiles. |
| 1624 | |
| 1625 | ---- |
| 1626 | |
| 1627 | '''ST_Count(raster, nband) -> bigint'''[[BR]] |
| 1628 | |
| 1629 | This function calls ST_SummaryStats and only returns the count from that function. |
| 1630 | |
| 1631 | 1. ST_Count(rast raster, nband int, exclude_nodata_value boolean) -> bigint |
| 1632 | |
| 1633 | returns the count as an integer |
| 1634 | |
| 1635 | nband: index of band |
| 1636 | |
| 1637 | exclude_nodata_value: if FALSE, nodata values in band are included in the stats. if TRUE, nodata values are not included |
| 1638 | |
| 1639 | {{{ |
| 1640 | ST_Count(rast, 1, FALSE) |
| 1641 | }}} |
| 1642 | |
| 1643 | 2. ST_Count(rast raster, nband int) -> bigint |
| 1644 | |
| 1645 | assumes exclude_nodata_value = TRUE |
| 1646 | |
| 1647 | {{{ |
| 1648 | ST_Count(rast, 2) |
| 1649 | }}} |
| 1650 | |
| 1651 | 3. ST_Count(rast raster, exclude_nodata_value boolean) -> bigint |
| 1652 | |
| 1653 | assumes nband = 1 |
| 1654 | |
| 1655 | {{{ |
| 1656 | ST_Count(rast, TRUE) |
| 1657 | }}} |
| 1658 | |
| 1659 | 4. ST_Count(rast raster) -> bigint |
| 1660 | |
| 1661 | assumes nband = 1 and exclude_nodata_value = TRUE |
| 1662 | |
| 1663 | {{{ |
| 1664 | ST_Count(rast) |
| 1665 | }}} |
| 1666 | |
| 1667 | The set of ST_ApproxCount functions are: |
| 1668 | |
| 1669 | 1. ST_ApproxCount(rast raster, nband int, exclude_nodata_value boolean, sample_percent double precision) -> bigint |
| 1670 | |
| 1671 | sample_percent: a value between 0 and 1 indicating the percentage of the raster band's pixels to consider |
| 1672 | |
| 1673 | {{{ |
| 1674 | ST_ApproxCount(rast, 3, FALSE, 0.1) |
| 1675 | |
| 1676 | ST_ApproxCount(rast, 1, TRUE, 0.5) |
| 1677 | }}} |
| 1678 | |
| 1679 | 2. ST_ApproxCount(rast raster, nband int, sample_percent double precision) -> bigint |
| 1680 | |
| 1681 | assumes that nband = 1 |
| 1682 | |
| 1683 | {{{ |
| 1684 | ST_ApproxCount(rast, 2 0.01) |
| 1685 | |
| 1686 | ST_ApproxCount(rast, 4, 0.025) |
| 1687 | }}} |
| 1688 | |
| 1689 | 3. ST_ApproxCount(rast raster, exclude_nodata_value boolean, sample_percent double precision) -> bigint |
| 1690 | |
| 1691 | assumes that nband = 1 |
| 1692 | |
| 1693 | {{{ |
| 1694 | ST_ApproxCount(rast, FALSE, 0.01) |
| 1695 | |
| 1696 | ST_ApproxCount(rast, TRUE, 0.025) |
| 1697 | }}} |
| 1698 | |
| 1699 | 4. ST_ApproxCount(rast raster, sample_percent double precision) -> bigint |
| 1700 | |
| 1701 | assumes that nband = 1 and exclude_nodata_value = TRUE |
| 1702 | |
| 1703 | {{{ |
| 1704 | ST_ApproxCount(rast, 0.25) |
| 1705 | }}} |
| 1706 | |
| 1707 | 5. ST_ApproxCount(rast raster) -> bigint |
| 1708 | |
| 1709 | assumes that nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 1710 | |
| 1711 | {{{ |
| 1712 | ST_ApproxCount(rast) |
| 1713 | }}} |
| 1714 | |
| 1715 | The following functions are provided for coverage tables. |
| 1716 | |
| 1717 | 1. ST_Count(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean) -> bigint |
| 1718 | |
| 1719 | rastertable: name of table with raster column |
| 1720 | |
| 1721 | rastercolumn: name of column of data type raster |
| 1722 | |
| 1723 | {{{ |
| 1724 | ST_Count('tmax_2010', 'rast', 1, FALSE) |
| 1725 | |
| 1726 | ST_Count('precip_2011', 'rast', 1, TRUE) |
| 1727 | }}} |
| 1728 | |
| 1729 | 2. ST_Count(rastertable text, rastercolumn text, nband int) -> bigint |
| 1730 | |
| 1731 | exclude_nodata_value = TRUE |
| 1732 | |
| 1733 | {{{ |
| 1734 | ST_Count('tmax_2010', 'rast', 1) |
| 1735 | }}} |
| 1736 | |
| 1737 | 3. ST_Count(rastertable text, rastercolumn text, exclude_nodata_value boolean) -> bigint |
| 1738 | |
| 1739 | nband = 1 |
| 1740 | |
| 1741 | {{{ |
| 1742 | ST_Count('precip_2011', 'rast', TRUE) |
| 1743 | }}} |
| 1744 | |
| 1745 | 4. ST_Count(rastertable text, rastercolumn text) -> bigint |
| 1746 | |
| 1747 | nband = 1 and exclude_nodata_value = TRUE |
| 1748 | |
| 1749 | {{{ |
| 1750 | ST_Count('tmin_2009', 'rast') |
| 1751 | }}} |
| 1752 | |
| 1753 | Variations for ST_ApproxCount are: |
| 1754 | |
| 1755 | 1. ST_ApproxCount(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean, sample_percent double precision) -> bigint |
| 1756 | |
| 1757 | {{{ |
| 1758 | ST_ApproxCount('tmax_2010', 'rast', 1, FALSE, 0.5) |
| 1759 | |
| 1760 | ST_ApproxCount('precip_2011', 'rast', 1, TRUE, 0.2) |
| 1761 | }}} |
| 1762 | |
| 1763 | 2. ST_ApproxCount(rastertable text, rastercolumn text, nband int, sample_percent double precision) -> bigint |
| 1764 | |
| 1765 | exclude_nodata_value = TRUE |
| 1766 | |
| 1767 | {{{ |
| 1768 | ST_ApproxCount('tmax_2010', 'rast', 1, 0.5) |
| 1769 | |
| 1770 | ST_ApproxCount('precip_2011', 'rast', 1, 0.2) |
| 1771 | }}} |
| 1772 | |
| 1773 | 3. ST_ApproxCount(rastertable text, rastercolumn text, exclude_nodata_value boolean, sample_percent double precision) -> bigint |
| 1774 | |
| 1775 | nband = 1 |
| 1776 | |
| 1777 | {{{ |
| 1778 | ST_ApproxCount('tmax_2010', 'rast', FALSE, 0.5) |
| 1779 | |
| 1780 | ST_ApproxCount('precip_2011', 'rast', TRUE, 0.2) |
| 1781 | }}} |
| 1782 | |
| 1783 | 4. ST_ApproxCount(rastertable text, rastercolumn text, sample_percent double precision) -> bigint |
| 1784 | |
| 1785 | nband = 1 and exclude_nodata_value = TRUE |
| 1786 | |
| 1787 | {{{ |
| 1788 | ST_ApproxCount('tmax_2010', 'rast', 0.5) |
| 1789 | |
| 1790 | ST_ApproxCount('precip_2011', 'rast', 0.2) |
| 1791 | }}} |
| 1792 | |
| 1793 | 5. ST_ApproxCount(rastertable text, rastercolumn text) -> bigint |
| 1794 | |
| 1795 | nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 1796 | |
| 1797 | {{{ |
| 1798 | ST_ApproxCount('tmax_2010', 'rast') |
| 1799 | |
| 1800 | ST_ApproxCount('precip_2011', 'rast') |
| 1801 | }}} |
| 1802 | |
| 1803 | ---- |
| 1804 | |
| 1805 | '''ST_Sum(raster, nband) -> double precision'''[[BR]] |
| 1806 | |
| 1807 | This function calls ST_SummaryStats and only returns the sum from that function. |
| 1808 | |
| 1809 | 1. ST_Sum(rast raster, nband int, exclude_nodata_value boolean) -> double precision |
| 1810 | |
| 1811 | returns the sum as an integer |
| 1812 | |
| 1813 | nband: index of band |
| 1814 | |
| 1815 | exclude_nodata_value: if FALSE, nodata values in band are included in the stats. if TRUE, nodata values are not included |
| 1816 | |
| 1817 | {{{ |
| 1818 | ST_Sum(rast, 1, FALSE) |
| 1819 | }}} |
| 1820 | |
| 1821 | 2. ST_Sum(rast raster, nband int) -> double precision |
| 1822 | |
| 1823 | assumes exclude_nodata_value = TRUE |
| 1824 | |
| 1825 | {{{ |
| 1826 | ST_Sum(rast, 2) |
| 1827 | }}} |
| 1828 | |
| 1829 | 3. ST_Sum(rast raster, exclude_nodata_value boolean) -> double precision |
| 1830 | |
| 1831 | assumes nband = 1 |
| 1832 | |
| 1833 | {{{ |
| 1834 | ST_Sum(rast, TRUE) |
| 1835 | }}} |
| 1836 | |
| 1837 | 4. ST_Sum(rast raster) -> double precision |
| 1838 | |
| 1839 | assumes nband = 1 and exclude_nodata_value = TRUE |
| 1840 | |
| 1841 | {{{ |
| 1842 | ST_Sum(rast) |
| 1843 | }}} |
| 1844 | |
| 1845 | The set of ST_ApproxSum functions are: |
| 1846 | |
| 1847 | 1. ST_ApproxSum(rast raster, nband int, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 1848 | |
| 1849 | sample_percent: a value between 0 and 1 indicating the percentage of the raster band's pixels to consider |
| 1850 | |
| 1851 | {{{ |
| 1852 | ST_ApproxSum(rast, 3, FALSE, 0.1) |
| 1853 | |
| 1854 | ST_ApproxSum(rast, 1, TRUE, 0.5) |
| 1855 | }}} |
| 1856 | |
| 1857 | 2. ST_ApproxSum(rast raster, nband int, sample_percent double precision) -> double precision |
| 1858 | |
| 1859 | assumes that nband = 1 |
| 1860 | |
| 1861 | {{{ |
| 1862 | ST_ApproxSum(rast, 2 0.01) |
| 1863 | |
| 1864 | ST_ApproxSum(rast, 4, 0.025) |
| 1865 | }}} |
| 1866 | |
| 1867 | 3. ST_ApproxSum(rast raster, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 1868 | |
| 1869 | assumes that nband = 1 |
| 1870 | |
| 1871 | {{{ |
| 1872 | ST_ApproxSum(rast, FALSE, 0.01) |
| 1873 | |
| 1874 | ST_ApproxSum(rast, TRUE, 0.025) |
| 1875 | }}} |
| 1876 | |
| 1877 | 4. ST_ApproxSum(rast raster, sample_percent double precision) -> double precision |
| 1878 | |
| 1879 | assumes that nband = 1 and exclude_nodata_value = TRUE |
| 1880 | |
| 1881 | {{{ |
| 1882 | ST_ApproxSum(rast, 0.25) |
| 1883 | }}} |
| 1884 | |
| 1885 | 5. ST_ApproxSum(rast raster) -> double precision |
| 1886 | |
| 1887 | assumes that nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 1888 | |
| 1889 | {{{ |
| 1890 | ST_ApproxSum(rast) |
| 1891 | }}} |
| 1892 | |
| 1893 | The following functions are provided for coverage tables. |
| 1894 | |
| 1895 | 1. ST_Sum(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean) -> double precision |
| 1896 | |
| 1897 | rastertable: name of table with raster column |
| 1898 | |
| 1899 | rastercolumn: name of column of data type raster |
| 1900 | |
| 1901 | {{{ |
| 1902 | ST_Sum('tmax_2010', 'rast', 1, FALSE) |
| 1903 | |
| 1904 | ST_Sum('precip_2011', 'rast', 1, TRUE) |
| 1905 | }}} |
| 1906 | |
| 1907 | 2. ST_Sum(rastertable text, rastercolumn text, nband int) -> double precision |
| 1908 | |
| 1909 | exclude_nodata_value = TRUE |
| 1910 | |
| 1911 | {{{ |
| 1912 | ST_Sum('tmax_2010', 'rast', 1) |
| 1913 | }}} |
| 1914 | |
| 1915 | 3. ST_Sum(rastertable text, rastercolumn text, exclude_nodata_value boolean) -> double precision |
| 1916 | |
| 1917 | nband = 1 |
| 1918 | |
| 1919 | {{{ |
| 1920 | ST_Sum('precip_2011', 'rast', TRUE) |
| 1921 | }}} |
| 1922 | |
| 1923 | 4. ST_Sum(rastertable text, rastercolumn text) -> double precision |
| 1924 | |
| 1925 | nband = 1 and exclude_nodata_value = TRUE |
| 1926 | |
| 1927 | {{{ |
| 1928 | ST_Sum('tmin_2009', 'rast') |
| 1929 | }}} |
| 1930 | |
| 1931 | Variations for ST_ApproxSum are: |
| 1932 | |
| 1933 | 1. ST_ApproxSum(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 1934 | |
| 1935 | {{{ |
| 1936 | ST_ApproxSum('tmax_2010', 'rast', 1, FALSE, 0.5) |
| 1937 | |
| 1938 | ST_ApproxSum('precip_2011', 'rast', 1, TRUE, 0.2) |
| 1939 | }}} |
| 1940 | |
| 1941 | 2. ST_ApproxSum(rastertable text, rastercolumn text, nband int, sample_percent double precision) -> double precision |
| 1942 | |
| 1943 | exclude_nodata_value = TRUE |
| 1944 | |
| 1945 | {{{ |
| 1946 | ST_ApproxSum('tmax_2010', 'rast', 1, 0.5) |
| 1947 | |
| 1948 | ST_ApproxSum('precip_2011', 'rast', 1, 0.2) |
| 1949 | }}} |
| 1950 | |
| 1951 | 3. ST_ApproxSum(rastertable text, rastercolumn text, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 1952 | |
| 1953 | nband = 1 |
| 1954 | |
| 1955 | {{{ |
| 1956 | ST_ApproxSum('tmax_2010', 'rast', FALSE, 0.5) |
| 1957 | |
| 1958 | ST_ApproxSum('precip_2011', 'rast', TRUE, 0.2) |
| 1959 | }}} |
| 1960 | |
| 1961 | 4. ST_ApproxSum(rastertable text, rastercolumn text, sample_percent double precision) -> double precision |
| 1962 | |
| 1963 | nband = 1 and exclude_nodata_value = TRUE |
| 1964 | |
| 1965 | {{{ |
| 1966 | ST_ApproxSum('tmax_2010', 'rast', 0.5) |
| 1967 | |
| 1968 | ST_ApproxSum('precip_2011', 'rast', 0.2) |
| 1969 | }}} |
| 1970 | |
| 1971 | 5. ST_ApproxSum(rastertable text, rastercolumn text) -> double precision |
| 1972 | |
| 1973 | nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 1974 | |
| 1975 | {{{ |
| 1976 | ST_ApproxSum('tmax_2010', 'rast') |
| 1977 | |
| 1978 | ST_ApproxSum('precip_2011', 'rast') |
| 1979 | }}} |
| 1980 | |
| 1981 | ---- |
| 1982 | |
| 1983 | '''ST_Mean(raster, nband) -> double precision'''[[BR]] |
| 1984 | This function calls ST_SummaryStats and only returns the mean from that function. |
| 1985 | |
| 1986 | 1. ST_Mean(rast raster, nband int, exclude_nodata_value boolean) -> double precision |
| 1987 | |
| 1988 | returns the mean as a double precision |
| 1989 | |
| 1990 | nband: index of band |
| 1991 | |
| 1992 | exclude_nodata_value: if FALSE, nodata values in band are included. if TRUE, nodata values are not included. |
| 1993 | |
| 1994 | {{{ |
| 1995 | ST_Mean(rast, 1, FALSE) |
| 1996 | }}} |
| 1997 | |
| 1998 | 2. ST_Mean(rast raster, nband int) -> double precision |
| 1999 | |
| 2000 | assumes exclude_nodata_value = TRUE |
| 2001 | |
| 2002 | {{{ |
| 2003 | ST_Mean(rast, 2) |
| 2004 | }}} |
| 2005 | |
| 2006 | 3. ST_Mean(rast raster, exclude_nodata_value boolean) -> double precision |
| 2007 | |
| 2008 | assumes nband = 1 |
| 2009 | |
| 2010 | {{{ |
| 2011 | ST_Mean(rast, TRUE) |
| 2012 | }}} |
| 2013 | |
| 2014 | 4. ST_Mean(rast raster) -> double precision |
| 2015 | |
| 2016 | assumes nband = 1 and exclude_nodata_value = TRUE |
| 2017 | |
| 2018 | {{{ |
| 2019 | ST_Mean(rast) |
| 2020 | }}} |
| 2021 | |
| 2022 | The set of ST_ApproxMean functions are: |
| 2023 | |
| 2024 | 1. ST_ApproxMean(rast raster, nband int, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 2025 | |
| 2026 | sample_percent: a value between 0 and 1 indicating the percentage of the raster band's pixels to consider |
| 2027 | |
| 2028 | {{{ |
| 2029 | ST_ApproxMean(rast, 3, FALSE, 0.1) |
| 2030 | |
| 2031 | ST_ApproxMean(rast, 1, TRUE, 0.5) |
| 2032 | }}} |
| 2033 | |
| 2034 | 2. ST_ApproxMean(rast raster, nband int, sample_percent double precision) -> double precision |
| 2035 | |
| 2036 | assumes that nband = 1 |
| 2037 | |
| 2038 | {{{ |
| 2039 | ST_ApproxMean(rast, 2 0.01) |
| 2040 | |
| 2041 | ST_ApproxMean(rast, 4, 0.025) |
| 2042 | }}} |
| 2043 | |
| 2044 | 3. ST_ApproxMean(rast raster, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 2045 | |
| 2046 | assumes that nband = 1 |
| 2047 | |
| 2048 | {{{ |
| 2049 | ST_ApproxMean(rast, FALSE, 0.01) |
| 2050 | |
| 2051 | ST_ApproxMean(rast, TRUE, 0.025) |
| 2052 | }}} |
| 2053 | |
| 2054 | 4. ST_ApproxMean(rast raster, sample_percent double precision) -> double precision |
| 2055 | |
| 2056 | assumes that nband = 1 and exclude_nodata_value = TRUE |
| 2057 | |
| 2058 | {{{ |
| 2059 | ST_ApproxMean(rast, 0.25) |
| 2060 | }}} |
| 2061 | |
| 2062 | 5. ST_ApproxMean(rast raster) -> double precision |
| 2063 | |
| 2064 | assumes that nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 2065 | |
| 2066 | {{{ |
| 2067 | ST_ApproxMean(rast) |
| 2068 | }}} |
| 2069 | |
| 2070 | The following functions are provided for coverage tables. |
| 2071 | |
| 2072 | 1. ST_Mean(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean) -> double precision |
| 2073 | |
| 2074 | rastertable: name of table with raster column |
| 2075 | |
| 2076 | rastercolumn: name of column of data type raster |
| 2077 | |
| 2078 | {{{ |
| 2079 | ST_Mean('tmax_2010', 'rast', 1, FALSE) |
| 2080 | |
| 2081 | ST_Mean('precip_2011', 'rast', 1, TRUE) |
| 2082 | }}} |
| 2083 | |
| 2084 | 2. ST_Mean(rastertable text, rastercolumn text, nband int) -> double precision |
| 2085 | |
| 2086 | exclude_nodata_value = TRUE |
| 2087 | |
| 2088 | {{{ |
| 2089 | ST_Mean('tmax_2010', 'rast', 1) |
| 2090 | }}} |
| 2091 | |
| 2092 | 3. ST_Mean(rastertable text, rastercolumn text, exclude_nodata_value boolean) -> double precision |
| 2093 | |
| 2094 | nband = 1 |
| 2095 | |
| 2096 | {{{ |
| 2097 | ST_Mean('precip_2011', 'rast', TRUE) |
| 2098 | }}} |
| 2099 | |
| 2100 | 4. ST_Mean(rastertable text, rastercolumn text) -> double precision |
| 2101 | |
| 2102 | nband = 1 and exclude_nodata_value = TRUE |
| 2103 | |
| 2104 | {{{ |
| 2105 | ST_Mean('tmin_2009', 'rast') |
| 2106 | }}} |
| 2107 | |
| 2108 | Variations for ST_ApproxMean are: |
| 2109 | |
| 2110 | 1. ST_ApproxMean(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 2111 | |
| 2112 | {{{ |
| 2113 | ST_ApproxMean('tmax_2010', 'rast', 1, FALSE, 0.5) |
| 2114 | |
| 2115 | ST_ApproxMean('precip_2011', 'rast', 1, TRUE, 0.2) |
| 2116 | }}} |
| 2117 | |
| 2118 | 2. ST_ApproxMean(rastertable text, rastercolumn text, nband int, sample_percent double precision) -> double precision |
| 2119 | |
| 2120 | exclude_nodata_value = TRUE |
| 2121 | |
| 2122 | {{{ |
| 2123 | ST_ApproxMean('tmax_2010', 'rast', 1, 0.5) |
| 2124 | |
| 2125 | ST_ApproxMean('precip_2011', 'rast', 1, 0.2) |
| 2126 | }}} |
| 2127 | |
| 2128 | 3. ST_ApproxMean(rastertable text, rastercolumn text, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 2129 | |
| 2130 | nband = 1 |
| 2131 | |
| 2132 | {{{ |
| 2133 | ST_ApproxMean('tmax_2010', 'rast', FALSE, 0.5) |
| 2134 | |
| 2135 | ST_ApproxMean('precip_2011', 'rast', TRUE, 0.2) |
| 2136 | }}} |
| 2137 | |
| 2138 | 4. ST_ApproxMean(rastertable text, rastercolumn text, sample_percent double precision) -> double precision |
| 2139 | |
| 2140 | nband = 1 and exclude_nodata_value = TRUE |
| 2141 | |
| 2142 | {{{ |
| 2143 | ST_ApproxMean('tmax_2010', 'rast', 0.5) |
| 2144 | |
| 2145 | ST_ApproxMean('precip_2011', 'rast', 0.2) |
| 2146 | }}} |
| 2147 | |
| 2148 | 5. ST_ApproxMean(rastertable text, rastercolumn text) -> double precision |
| 2149 | |
| 2150 | nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 2151 | |
| 2152 | {{{ |
| 2153 | ST_ApproxMean('tmax_2010', 'rast') |
| 2154 | |
| 2155 | ST_ApproxMean('precip_2011', 'rast') |
| 2156 | }}} |
| 2157 | |
| 2158 | The mean returned in the coverage functions (has rastertable and rastercolumn arguments) is the true mean of the raster tiles. |
| 2159 | |
| 2160 | ---- |
| 2161 | |
| 2162 | '''ST_StdDev(raster, nband) -> double precision'''[[BR]] |
| 2163 | This function calls ST_SummaryStats and only returns the standard deviation from that function. |
| 2164 | |
| 2165 | 1. ST_StdDev(rast raster, nband int, exclude_nodata_value boolean) -> double precision |
| 2166 | |
| 2167 | returns the standard deviation as a double precision |
| 2168 | |
| 2169 | nband: index of band |
| 2170 | |
| 2171 | exclude_nodata_value: if FALSE, nodata values in band are included. if TRUE, nodata values are not included. |
| 2172 | |
| 2173 | {{{ |
| 2174 | ST_StdDev(rast, 1, FALSE) |
| 2175 | }}} |
| 2176 | |
| 2177 | 2. ST_StdDev(rast raster, nband int) -> double precision |
| 2178 | |
| 2179 | assumes exclude_nodata_value = TRUE |
| 2180 | |
| 2181 | {{{ |
| 2182 | ST_StdDev(rast, 2) |
| 2183 | }}} |
| 2184 | |
| 2185 | 3. ST_StdDev(rast raster, exclude_nodata_value boolean) -> double precision |
| 2186 | |
| 2187 | assumes nband = 1 |
| 2188 | |
| 2189 | {{{ |
| 2190 | ST_StdDev(rast, TRUE) |
| 2191 | }}} |
| 2192 | |
| 2193 | 4. ST_StdDev(rast raster) -> double precision |
| 2194 | |
| 2195 | assumes nband = 1 and exclude_nodata_value = TRUE |
| 2196 | |
| 2197 | {{{ |
| 2198 | ST_StdDev(rast) |
| 2199 | }}} |
| 2200 | |
| 2201 | The set of ST_ApproxStdDev functions are: |
| 2202 | |
| 2203 | 1. ST_ApproxStdDev(rast raster, nband int, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 2204 | |
| 2205 | sample_percent: a value between 0 and 1 indicating the percentage of the raster band's pixels to consider |
| 2206 | |
| 2207 | {{{ |
| 2208 | ST_ApproxStdDev(rast, 3, FALSE, 0.1) |
| 2209 | |
| 2210 | ST_ApproxStdDev(rast, 1, TRUE, 0.5) |
| 2211 | }}} |
| 2212 | |
| 2213 | 2. ST_ApproxStdDev(rast raster, nband int, sample_percent double precision) -> double precision |
| 2214 | |
| 2215 | assumes that nband = 1 |
| 2216 | |
| 2217 | {{{ |
| 2218 | ST_ApproxStdDev(rast, 2 0.01) |
| 2219 | |
| 2220 | ST_ApproxStdDev(rast, 4, 0.025) |
| 2221 | }}} |
| 2222 | |
| 2223 | 3. ST_ApproxStdDev(rast raster, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 2224 | |
| 2225 | assumes that nband = 1 |
| 2226 | |
| 2227 | {{{ |
| 2228 | ST_ApproxStdDev(rast, FALSE, 0.01) |
| 2229 | |
| 2230 | ST_ApproxStdDev(rast, TRUE, 0.025) |
| 2231 | }}} |
| 2232 | |
| 2233 | 4. ST_ApproxStdDev(rast raster, sample_percent double precision) -> double precision |
| 2234 | |
| 2235 | assumes that nband = 1 and exclude_nodata_value = TRUE |
| 2236 | |
| 2237 | {{{ |
| 2238 | ST_ApproxStdDev(rast, 0.25) |
| 2239 | }}} |
| 2240 | |
| 2241 | 5. ST_ApproxStdDev(rast raster) -> double precision |
| 2242 | |
| 2243 | assumes that nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 2244 | |
| 2245 | {{{ |
| 2246 | ST_ApproxStdDev(rast) |
| 2247 | }}} |
| 2248 | |
| 2249 | The following functions are provided for coverage tables. |
| 2250 | |
| 2251 | 1. ST_StdDev(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean) -> double precision |
| 2252 | |
| 2253 | rastertable: name of table with raster column |
| 2254 | |
| 2255 | rastercolumn: name of column of data type raster |
| 2256 | |
| 2257 | {{{ |
| 2258 | ST_StdDev('tmax_2010', 'rast', 1, FALSE) |
| 2259 | |
| 2260 | ST_StdDev('precip_2011', 'rast', 1, TRUE) |
| 2261 | }}} |
| 2262 | |
| 2263 | 2. ST_StdDev(rastertable text, rastercolumn text, nband int) -> double precision |
| 2264 | |
| 2265 | exclude_nodata_value = TRUE |
| 2266 | |
| 2267 | {{{ |
| 2268 | ST_StdDev('tmax_2010', 'rast', 1) |
| 2269 | }}} |
| 2270 | |
| 2271 | 3. ST_StdDev(rastertable text, rastercolumn text, exclude_nodata_value boolean) -> double precision |
| 2272 | |
| 2273 | nband = 1 |
| 2274 | |
| 2275 | {{{ |
| 2276 | ST_StdDev('precip_2011', 'rast', TRUE) |
| 2277 | }}} |
| 2278 | |
| 2279 | 4. ST_StdDev(rastertable text, rastercolumn text) -> double precision |
| 2280 | |
| 2281 | nband = 1 and exclude_nodata_value = TRUE |
| 2282 | |
| 2283 | {{{ |
| 2284 | ST_StdDev('tmin_2009', 'rast') |
| 2285 | }}} |
| 2286 | |
| 2287 | Variations for ST_ApproxStdDev are: |
| 2288 | |
| 2289 | 1. ST_ApproxStdDev(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 2290 | |
| 2291 | {{{ |
| 2292 | ST_ApproxStdDev('tmax_2010', 'rast', 1, FALSE, 0.5) |
| 2293 | |
| 2294 | ST_ApproxStdDev('precip_2011', 'rast', 1, TRUE, 0.2) |
| 2295 | }}} |
| 2296 | |
| 2297 | 2. ST_ApproxStdDev(rastertable text, rastercolumn text, nband int, sample_percent double precision) -> double precision |
| 2298 | |
| 2299 | exclude_nodata_value = TRUE |
| 2300 | |
| 2301 | {{{ |
| 2302 | ST_ApproxStdDev('tmax_2010', 'rast', 1, 0.5) |
| 2303 | |
| 2304 | ST_ApproxStdDev('precip_2011', 'rast', 1, 0.2) |
| 2305 | }}} |
| 2306 | |
| 2307 | 3. ST_ApproxStdDev(rastertable text, rastercolumn text, exclude_nodata_value boolean, sample_percent double precision) -> double precision |
| 2308 | |
| 2309 | nband = 1 |
| 2310 | |
| 2311 | {{{ |
| 2312 | ST_ApproxStdDev('tmax_2010', 'rast', FALSE, 0.5) |
| 2313 | |
| 2314 | ST_ApproxStdDev('precip_2011', 'rast', TRUE, 0.2) |
| 2315 | }}} |
| 2316 | |
| 2317 | 4. ST_ApproxStdDev(rastertable text, rastercolumn text, sample_percent double precision) -> double precision |
| 2318 | |
| 2319 | nband = 1 and exclude_nodata_value = TRUE |
| 2320 | |
| 2321 | {{{ |
| 2322 | ST_ApproxStdDev('tmax_2010', 'rast', 0.5) |
| 2323 | |
| 2324 | ST_ApproxStdDev('precip_2011', 'rast', 0.2) |
| 2325 | }}} |
| 2326 | |
| 2327 | 5. ST_ApproxStdDev(rastertable text, rastercolumn text) -> double precision |
| 2328 | |
| 2329 | nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 2330 | |
| 2331 | {{{ |
| 2332 | ST_ApproxStdDev('tmax_2010', 'rast') |
| 2333 | |
| 2334 | ST_ApproxStdDev('precip_2011', 'rast') |
| 2335 | }}} |
| 2336 | |
| 2337 | The standard deviation returned in the coverage functions (has rastertable and rastercolumn arguments) is the standard deviation of all raster tiles. |
| 2338 | |
| 2339 | ---- |
| 2340 | |
| 2341 | '''ST_MinMax(raster, nband) -> record'''[[BR]] |
| 2342 | This function calls ST_SummaryStats and only returns the min and max values from that function. |
| 2343 | |
| 2344 | 1. ST_MinMax(rast raster, nband int, exclude_nodata_value boolean) -> record |
| 2345 | |
| 2346 | returns the record (min double precision, max double precision) |
| 2347 | |
| 2348 | nband: index of band |
| 2349 | |
| 2350 | exclude_nodata_value: if FALSE, nodata values in band are included. if TRUE, nodata values are not included. |
| 2351 | |
| 2352 | {{{ |
| 2353 | ST_MinMax(rast, 1, FALSE) |
| 2354 | }}} |
| 2355 | |
| 2356 | 2. ST_MinMax(rast raster, nband int) -> record |
| 2357 | |
| 2358 | assumes exclude_nodata_value = TRUE |
| 2359 | |
| 2360 | {{{ |
| 2361 | ST_MinMax(rast, 2) |
| 2362 | }}} |
| 2363 | |
| 2364 | 3. ST_MinMax(rast raster, exclude_nodata_value boolean) -> record |
| 2365 | |
| 2366 | assumes nband = 1 |
| 2367 | |
| 2368 | {{{ |
| 2369 | ST_MinMax(rast, TRUE) |
| 2370 | }}} |
| 2371 | |
| 2372 | 4. ST_MinMax(rast raster) -> record |
| 2373 | |
| 2374 | assumes nband = 1 and exclude_nodata_value = TRUE |
| 2375 | |
| 2376 | {{{ |
| 2377 | ST_MinMax(rast) |
| 2378 | }}} |
| 2379 | |
| 2380 | The set of ST_ApproxMinMax functions are: |
| 2381 | |
| 2382 | 1. ST_ApproxMinMax(rast raster, nband int, exclude_nodata_value boolean, sample_percent record) -> record |
| 2383 | |
| 2384 | sample_percent: a value between 0 and 1 indicating the percentage of the raster band's pixels to consider |
| 2385 | |
| 2386 | {{{ |
| 2387 | ST_ApproxMinMax(rast, 3, FALSE, 0.1) |
| 2388 | |
| 2389 | ST_ApproxMinMax(rast, 1, TRUE, 0.5) |
| 2390 | }}} |
| 2391 | |
| 2392 | 2. ST_ApproxMinMax(rast raster, nband int, sample_percent double precision) -> record |
| 2393 | |
| 2394 | assumes that nband = 1 |
| 2395 | |
| 2396 | {{{ |
| 2397 | ST_ApproxMinMax(rast, 2 0.01) |
| 2398 | |
| 2399 | ST_ApproxMinMax(rast, 4, 0.025) |
| 2400 | }}} |
| 2401 | |
| 2402 | 3. ST_ApproxMinMax(rast raster, exclude_nodata_value boolean, sample_percent double precision) -> record |
| 2403 | |
| 2404 | assumes that nband = 1 |
| 2405 | |
| 2406 | {{{ |
| 2407 | ST_ApproxMinMax(rast, FALSE, 0.01) |
| 2408 | |
| 2409 | ST_ApproxMinMax(rast, TRUE, 0.025) |
| 2410 | }}} |
| 2411 | |
| 2412 | 4. ST_ApproxMinMax(rast raster, sample_percent double precision) -> record |
| 2413 | |
| 2414 | assumes that nband = 1 and exclude_nodata_value = TRUE |
| 2415 | |
| 2416 | {{{ |
| 2417 | ST_ApproxMinMax(rast, 0.25) |
| 2418 | }}} |
| 2419 | |
| 2420 | 5. ST_ApproxMinMax(rast raster) -> record |
| 2421 | |
| 2422 | assumes that nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 2423 | |
| 2424 | {{{ |
| 2425 | ST_ApproxMinMax(rast) |
| 2426 | }}} |
| 2427 | |
| 2428 | The following functions are provided for coverage tables. |
| 2429 | |
| 2430 | 1. ST_MinMax(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean) -> record |
| 2431 | |
| 2432 | rastertable: name of table with raster column |
| 2433 | |
| 2434 | rastercolumn: name of column of data type raster |
| 2435 | |
| 2436 | {{{ |
| 2437 | ST_MinMax('tmax_2010', 'rast', 1, FALSE) |
| 2438 | |
| 2439 | ST_MinMax('precip_2011', 'rast', 1, TRUE) |
| 2440 | }}} |
| 2441 | |
| 2442 | 2. ST_MinMax(rastertable text, rastercolumn text, nband int) -> record |
| 2443 | |
| 2444 | exclude_nodata_value = TRUE |
| 2445 | |
| 2446 | {{{ |
| 2447 | ST_MinMax('tmax_2010', 'rast', 1) |
| 2448 | }}} |
| 2449 | |
| 2450 | 3. ST_MinMax(rastertable text, rastercolumn text, exclude_nodata_value boolean) -> record |
| 2451 | |
| 2452 | nband = 1 |
| 2453 | |
| 2454 | {{{ |
| 2455 | ST_MinMax('precip_2011', 'rast', TRUE) |
| 2456 | }}} |
| 2457 | |
| 2458 | 4. ST_MinMax(rastertable text, rastercolumn text) -> record |
| 2459 | |
| 2460 | nband = 1 and exclude_nodata_value = TRUE |
| 2461 | |
| 2462 | {{{ |
| 2463 | ST_MinMax('tmin_2009', 'rast') |
| 2464 | }}} |
| 2465 | |
| 2466 | Variations for ST_ApproxMinMax are: |
| 2467 | |
| 2468 | 1. ST_ApproxMinMax(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean, sample_percent double precision) -> record |
| 2469 | |
| 2470 | {{{ |
| 2471 | ST_ApproxMinMax('tmax_2010', 'rast', 1, FALSE, 0.5) |
| 2472 | |
| 2473 | ST_ApproxMinMax('precip_2011', 'rast', 1, TRUE, 0.2) |
| 2474 | }}} |
| 2475 | |
| 2476 | 2. ST_ApproxMinMax(rastertable text, rastercolumn text, nband int, sample_percent double precision) -> record |
| 2477 | |
| 2478 | exclude_nodata_value = TRUE |
| 2479 | |
| 2480 | {{{ |
| 2481 | ST_ApproxMinMax('tmax_2010', 'rast', 1, 0.5) |
| 2482 | |
| 2483 | ST_ApproxMinMax('precip_2011', 'rast', 1, 0.2) |
| 2484 | }}} |
| 2485 | |
| 2486 | 3. ST_ApproxMinMax(rastertable text, rastercolumn text, exclude_nodata_value boolean, sample_percent double precision) -> record |
| 2487 | |
| 2488 | nband = 1 |
| 2489 | |
| 2490 | {{{ |
| 2491 | ST_ApproxMinMax('tmax_2010', 'rast', FALSE, 0.5) |
| 2492 | |
| 2493 | ST_ApproxMinMax('precip_2011', 'rast', TRUE, 0.2) |
| 2494 | }}} |
| 2495 | |
| 2496 | 4. ST_ApproxMinMax(rastertable text, rastercolumn text, sample_percent double precision) -> record |
| 2497 | |
| 2498 | nband = 1 and exclude_nodata_value = TRUE |
| 2499 | |
| 2500 | {{{ |
| 2501 | ST_ApproxMinMax('tmax_2010', 'rast', 0.5) |
| 2502 | |
| 2503 | ST_ApproxMinMax('precip_2011', 'rast', 0.2) |
| 2504 | }}} |
| 2505 | |
| 2506 | 5. ST_ApproxMinMax(rastertable text, rastercolumn text) -> record |
| 2507 | |
| 2508 | nband = 1, exclude_nodata_value = TRUE and sample_percent = 0.1 |
| 2509 | |
| 2510 | {{{ |
| 2511 | ST_ApproxMinMax('tmax_2010', 'rast') |
| 2512 | |
| 2513 | ST_ApproxMinMax('precip_2011', 'rast') |
| 2514 | }}} |
| 2515 | |
| 2516 | ---- |
| 2517 | |
| 2518 | '''ST_Histogram(raster, nband) -> set of records'''[[BR]] |
| 2519 | ST_Histogram and ST_ApproxHistogram provide methods to determine a raster's data distribution. |
| 2520 | |
| 2521 | The return of ST_Histogram and ST_ApproxHistogram is a set of records where each record is (min, max, count, percent). |
| 2522 | |
| 2523 | ST_Histogram has the following variations. |
| 2524 | |
| 2525 | 1. ST_Histogram(rast raster, nband int, exclude_nodata_value boolean, bins int, width double precision[], right boolean) -> set of records |
| 2526 | |
| 2527 | returns set of records of four columns (min, max, count, percent) |
| 2528 | |
| 2529 | nband: index of band to process on |
| 2530 | |
| 2531 | exclude_nodata_value: if FALSE, nodata values in band are included. if TRUE, nodata values are not included. |
| 2532 | |
| 2533 | bins: the number of categories/bins to have in the histogram. If NULL or value less than one, the number of categories will be auto-computed using Sturges' formula if the number of values >= 30 or Square-root choice if number of values < 30. |
| 2534 | |
| 2535 | http://en.wikipedia.org/wiki/Histogram#Mathematical_definition |
| 2536 | |
| 2537 | width: an array indicating the width of each category/bin. If the number of bins is greater than the number of widths, the widths are repeated. Example: 9 bins, widths are [a, b, c] will have the output be [a, b, c, a, b, c, a, b, c]. |
| 2538 | |
| 2539 | right: compute the histogram from the right rather than from the left (default). This changes the criteria for evaluating a value x from [a, b) to (a, b]. |
| 2540 | |
| 2541 | {{{ |
| 2542 | ST_Histogram(rast, 2, FALSE, NULL, NULL, FALSE) |
| 2543 | |
| 2544 | ST_Histogram(rast, 1, TRUE, 100, NULL, FALSE) |
| 2545 | |
| 2546 | ST_Histogram(rast, 2, FALSE, NULL, ARRAY[100, 50], FALSE) |
| 2547 | |
| 2548 | ST_Histogram(rast, 2, FALSE, 9, ARRAY[1000], TRUE) |
| 2549 | |
| 2550 | ST_Histogram(rast, 2, FALSE, 20, ARRAY[100, 200, 300], TRUE) |
| 2551 | }}} |
| 2552 | |
| 2553 | 2. ST_Histogram(rast raster, nband int, exclude_nodata_value boolean, bins int, right boolean) -> set of records |
| 2554 | |
| 2555 | parameter "width" is not specified thus resulting in all bins having the same widths |
| 2556 | |
| 2557 | {{{ |
| 2558 | ST_Histogram(rast, 2, FALSE, 5, FALSE) |
| 2559 | }}} |
| 2560 | |
| 2561 | 3. ST_Histogram(rast raster, nband int, exclude_nodata_value boolean, bins int) -> set of records |
| 2562 | |
| 2563 | the parameter "right" is removed and assumed to be FALSE |
| 2564 | |
| 2565 | {{{ |
| 2566 | ST_Histogram(rast, 2, FALSE, 5) |
| 2567 | }}} |
| 2568 | |
| 2569 | 4. ST_Histogram(rast raster, nband int, exclude_nodata_value boolean) -> set of records |
| 2570 | |
| 2571 | the parameter "bins" is removed and set to NULL. The function will compute the number of bins to use |
| 2572 | |
| 2573 | 5. ST_Histogram(rast raster, nband int) -> set of records |
| 2574 | |
| 2575 | exclude_nodata_value is assumed to be TRUE |
| 2576 | |
| 2577 | 6. ST_Histogram(rast raster) -> set of records |
| 2578 | |
| 2579 | assumes that nband is 1. |
| 2580 | |
| 2581 | 7. ST_Histogram(rast raster, nband int, bins int, width double precision[], right boolean) -> set of records |
| 2582 | |
| 2583 | exclude_nodata_value is assumed to be TRUE |
| 2584 | |
| 2585 | 8. ST_Histogram(rast raster, nband int, bins int, right boolean) -> set of records |
| 2586 | |
| 2587 | all bins will have equal widths |
| 2588 | |
| 2589 | 9. ST_Histogram(rast raster, nband int, bins int) -> set of records |
| 2590 | |
| 2591 | right is assumed to be FALSE |
| 2592 | |
| 2593 | ST_ApproxHistogram should have the following variations. |
| 2594 | |
| 2595 | 1. ST_ApproxHistogram(rast raster, nband int, exclude_nodata_value boolean, sample_percent double precision, bins int, width double precision[], right boolean) -> set of record |
| 2596 | |
| 2597 | sample_percent: a value between 0 and 1 indicating the percentage of the raster band's pixels to consider when generating the histogram. |
| 2598 | |
| 2599 | {{{ |
| 2600 | ST_Histogram(rast, 2, FALSE, 0.1, NULL, NULL, FALSE) |
| 2601 | |
| 2602 | ST_Histogram(rast, 1, TRUE, 1, 100, NULL, FALSE) |
| 2603 | |
| 2604 | ST_Histogram(rast, 2, FALSE, 0.2, NULL, ARRAY[100, 50], FALSE) |
| 2605 | |
| 2606 | ST_Histogram(rast, 2, FALSE, 0.25, 9, ARRAY[1000], TRUE) |
| 2607 | |
| 2608 | ST_Histogram(rast, 2, FALSE, 0.05, 20, ARRAY[100, 200, 300], TRUE) |
| 2609 | }}} |
| 2610 | |
| 2611 | 2. ST_ApproxHistogram(rast raster, nband int, exclude_nodata_value boolean, sample_percent double precision, bins int, right boolean) -> set of records |
| 2612 | |
| 2613 | parameter "width" is not specified thus resulting in all bins having the same widths |
| 2614 | |
| 2615 | 3. ST_ApproxHistogram(rast raster, nband int, exclude_nodata_value boolean, sample_percent double precision, bins int) -> set of records |
| 2616 | |
| 2617 | the parameter "right" is removed and assumed to be FALSE |
| 2618 | |
| 2619 | {{{ |
| 2620 | ST_ApproxHistogram(rast, 2, FALSE, 5) |
| 2621 | }}} |
| 2622 | |
| 2623 | 4. ST_ApproxHistogram(rast raster, nband int, exclude_nodata_value boolean, sample_percent double precision) -> set of records |
| 2624 | |
| 2625 | the parameter "bins" is removed and set to NULL so that function can compute the number of bins to use |
| 2626 | |
| 2627 | 5. ST_ApproxHistogram(rast raster, nband int, sample_percent double precision) -> set of records |
| 2628 | |
| 2629 | exclude_nodata_value is assumed to be TRUE |
| 2630 | |
| 2631 | 6. ST_ApproxHistogram(rast raster, nband int) -> set of records |
| 2632 | |
| 2633 | assumes that sample_percent is 0.1 |
| 2634 | |
| 2635 | 7. ST_ApproxHistogram(rast raster, sample_percent double_precision) -> set of records |
| 2636 | |
| 2637 | assumes that nband is 1 |
| 2638 | |
| 2639 | 8. ST_ApproxHistogram(rast raster) -> set of records |
| 2640 | |
| 2641 | assumes that nband is 1 and sample_percent is 0.1 |
| 2642 | |
| 2643 | 9. ST_ApproxHistogram(rast raster, nband int, sample_percent double precision, bins int, width double precision[], right boolean) -> set of records |
| 2644 | |
| 2645 | exclude_nodata_value is assumed to be TRUE |
| 2646 | |
| 2647 | 10. ST_ApproxHistogram(rast raster, nband int, sample_percent double precision, bins int, right boolean) -> set of records |
| 2648 | |
| 2649 | all bins will have equal widths |
| 2650 | |
| 2651 | 11. ST_ApproxHistogram(rast raster, nband int, sample_percent double precision, bins int) -> set of records |
| 2652 | |
| 2653 | right is assumed to be FALSE |
| 2654 | |
| 2655 | The following set of function are for coverages. |
| 2656 | |
| 2657 | 1. ST_Histogram(rastertable text, rastercolumn text, nband int DEFAULT 1, exclude_nodata_value boolean DEFAULT TRUE, bins int default 0, width double precision[] DEFAULT NULL, right boolean DEFAULT FALSE) -> set of records |
| 2658 | |
| 2659 | rastertable: name of table with raster column |
| 2660 | |
| 2661 | rastercolumn: name of column of data type raster |
| 2662 | |
| 2663 | {{{ |
| 2664 | ST_Histogram('tmax_2010', 'rast') |
| 2665 | |
| 2666 | ST_Histogram('precip_2011', 'rast', 1) |
| 2667 | |
| 2668 | ST_Histogram('precip_2011', 'rast', 1, FALSE) |
| 2669 | |
| 2670 | ST_Histogram('precip_2011', 'rast', 1, FALSE, 5) |
| 2671 | |
| 2672 | ST_Histogram('precip_2011', 'rast', 1, FALSE, 10, NULL) |
| 2673 | |
| 2674 | ST_Histogram('precip_2011', 'rast', 1, FALSE, 10, NULL, TRUE) |
| 2675 | }}} |
| 2676 | |
| 2677 | 2. ST_Histogram(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean, bins int, right boolean) -> set of records |
| 2678 | |
| 2679 | {{{ |
| 2680 | ST_Histogram('tmin_2010', 'rast', 2, FALSE, 5, FALSE) |
| 2681 | }}} |
| 2682 | |
| 2683 | 3. ST_Histogram(rastertable text, rastercolumn text, nband int, bins int, width double precision[] DEFAULT NULL, right boolean DEFAULT FALSE) -> set of records |
| 2684 | |
| 2685 | {{{ |
| 2686 | ST_Histogram('ndvi_2010', 'rast', 1, 5) |
| 2687 | |
| 2688 | ST_Histogram('ndvi_2010', 'rast', 1, 0, ARRAY[0.5]::double precision[]) |
| 2689 | |
| 2690 | ST_Histogram('ndvi_2010', 'rast', 1, 5, NULL, TRUE) |
| 2691 | }}} |
| 2692 | |
| 2693 | 4. ST_Histogram(rastertable text, rastercolumn text, nband int, bins int, right boolean) -> set of records |
| 2694 | |
| 2695 | {{{ |
| 2696 | ST_Histogram('veg_2009', 'rast', 2, 3, FALSE) |
| 2697 | |
| 2698 | ST_Histogram('veg_2009', 'rast', 2, 3, TRUE) |
| 2699 | }}} |
| 2700 | |
| 2701 | A set of functions of ST_ApproxHistogram for coverage tables: |
| 2702 | |
| 2703 | 1. ST_ApproxHistogram(rastertable text, rastercolumn text, nband int DEFAULT 1, exclude_nodata_value boolean DEFAULT TRUE, sample_percent double precision DEFAULT 0.1, bins int DEFAULT 0, width double precision[] DEFAULT NULL, right boolean DEFAULT FALSE) -> set of records |
| 2704 | |
| 2705 | {{{ |
| 2706 | ST_ApproxHistogram('precip_2010', 'rast') |
| 2707 | |
| 2708 | ST_ApproxHistogram('precip_2010', 'rast', 1) |
| 2709 | |
| 2710 | ST_ApproxHistogram('precip_2010', 'rast', 2, FALSE) |
| 2711 | |
| 2712 | ST_ApproxHistogram('precip_2010', 'rast', 1, TRUE, 0.25) |
| 2713 | |
| 2714 | ST_ApproxHistogram('precip_2010', 'rast', 3, FALSE, 0.2, 10) |
| 2715 | |
| 2716 | ST_ApproxHistogram('precip_2010', 'rast', 1, TRUE, 0.1, 0, ARRAY[1]::double precision[]) |
| 2717 | |
| 2718 | ST_ApproxHistogram('precip_2010', 'rast', 1, TRUE, 0.1, 0, ARRAY[1]::double precision[], FALSE) |
| 2719 | }}} |
| 2720 | |
| 2721 | 2. ST_ApproxHistogram(rastertable text, rastercolumn text, nband int, exclude_nodata_value boolean, sample_percent double precision, bins int, right boolean) |
| 2722 | |
| 2723 | 3. ST_ApproxHistogram(rastertable text, rastercolumn text, nband int, sample_percent double precision) |
| 2724 | |
| 2725 | 4. ST_ApproxHistogram(rastertable text, rastercolumn text, sample_percent double precision) |
| 2726 | |
| 2727 | 5. ST_ApproxHistogram(rastertable text, rastercolumn text, nband int, sample_percent double precision, bins int, width double precision[] DEFAULT NULL, right boolean DEFAULT FALSE) |
| 2728 | |
| 2729 | 6. ST_ApproxHistogram(rastertable text, rastercolumn text, nband int, sample_percent double precision, bins int, right boolean) |
| 2730 | |
| 2731 | ---- |
| 2732 | '''ST_Quantile(raster, nband) -> set of records'''[[BR]] |
| 2733 | In addition to determining the histogram of a raster, providing the ability to compute quantiles permits a user to reference a value in the context of the sample or population. Thus, a value could be examined to be at the raster's 25%, 50%, 75% percentile. |
| 2734 | |
| 2735 | http://en.wikipedia.org/wiki/Quantile |
| 2736 | |
| 2737 | ST_Quantile variations: |
| 2738 | |
| 2739 | 1. ST_Quantile(rast raster, nband int, exclude_nodata_value boolean, quantiles double precision[]) -> set of records |
| 2740 | |
| 2741 | each row returned is of (quantile double precision, value double precision) |
| 2742 | |
| 2743 | nband: index of band to process on |
| 2744 | |
| 2745 | exclude_nodata_value: if FALSE, nodata values in band are included. if TRUE, nodata values are not included. |
| 2746 | |
| 2747 | quantiles: array of percentages to compute values for |
| 2748 | |
| 2749 | {{{ |
| 2750 | ST_Quantile(rast, 1, FALSE, ARRAY[0.1, 0.3, 0.7]) |
| 2751 | |
| 2752 | ST_Quantile(rast, 1, TRUE, ARRAY[0.2]) |
| 2753 | |
| 2754 | ST_Quantile(rast, 1, FALSE, ARRAY[0, 1]) |
| 2755 | }}} |
| 2756 | |
| 2757 | 2. ST_Quantile(rast raster, nband int, quantiles double precision[]) -> set of records |
| 2758 | |
| 2759 | "exclude_nodata_value" is assumed to be TRUE |
| 2760 | |
| 2761 | {{{ |
| 2762 | ST_Quantile(rast, 1, ARRAY[0.1, 0.3, 0.7]) |
| 2763 | }}} |
| 2764 | |
| 2765 | 3. ST_Quantile(rast raster, nband int, exclude_nodata_value boolean) -> set of records |
| 2766 | |
| 2767 | "quantiles" assumed to be ARRAY[0, 0.25, 0.5, 0.75, 1] |
| 2768 | |
| 2769 | 4. ST_Quantile(rast raster, nband int) -> set of records |
| 2770 | |
| 2771 | "exclude_nodata_value" is assumed to be TRUE and "quantiles" assumed to be ARRAY[0, 0.25, 0.5, 0.75, 1] |
| 2772 | |
| 2773 | 5. ST_Quantile(rast raster, quantiles double precision[]) -> set of records |
| 2774 | |
| 2775 | "nband" is assumed to be 1 and "exclude_nodata_value" is TRUE |
| 2776 | |
| 2777 | 6. ST_Quantile(rast raster) -> set of records |
| 2778 | |
| 2779 | "nband" is assumed to be 1 and "quantiles" assumed to be ARRAY[0, 0.25, 0.5, 0.75, 1] |
| 2780 | |
| 2781 | 7. ST_Quantile(rast raster, nband int, exclude_nodata_value boolean, quantile double precision) -> record |
| 2782 | |
| 2783 | quantile: the single percentile to compute |
| 2784 | |
| 2785 | 8. ST_Quantile(rast raster, nband int, quantile double precision) -> record |
| 2786 | |
| 2787 | "exclude_nodata_value" is assumed to be TRUE |
| 2788 | |
| 2789 | 9. ST_Quantile(rast raster, exclude_nodata_value boolean, quantile double precision) -> record |
| 2790 | |
| 2791 | "nband" is assumed to be 1 |
| 2792 | |
| 2793 | 10. ST_Quantile(rast raster, quantile double precision) -> record |
| 2794 | |
| 2795 | "nband" is assumed to be 1 and "exclude_nodata_value" is assumed to be TRUE |
| 2796 | |
| 2797 | ST_ApproxQuantile adds a "sample_percent" indicating the percentage of the raster to sample |
| 2798 | |
| 2799 | 1. ST_ApproxQuantile(rast raster, nband int, exclude_nodata_value boolean, sample_percent double precision, quantiles double precision[]) -> set of records |
| 2800 | |
| 2801 | nband: index of band to process on |
| 2802 | |
| 2803 | exclude_nodata_value: if FALSE, nodata values in band are included. if TRUE, nodata values are not included. |
| 2804 | |
| 2805 | sample_percent: a value between 0 and 1 indicating the percentage of the raster band's pixels to consider when computing the quantiles |
| 2806 | |
| 2807 | quantiles: array of percentages to compute values for |
| 2808 | |
| 2809 | {{{ |
| 2810 | ST_ApproxQuantile(rast, 1, FALSE, 0.1, ARRAY[0.1, 0.3, 0.7]) |
| 2811 | |
| 2812 | ST_ApproxQuantile(rast, 1, TRUE, .2, ARRAY[0.2]) |
| 2813 | |
| 2814 | ST_ApproxQuantile(rast, 1, FALSE, 0.3, ARRAY[0, 1]) |
| 2815 | }}} |
| 2816 | |
| 2817 | 2. ST_ApproxQuantile(rast raster, nband int, sample_percent double precision, quantiles double precision[]) -> set of records |
| 2818 | |
| 2819 | "exclude_nodata_value" is assumed to be TRUE |
| 2820 | |
| 2821 | {{{ |
| 2822 | ST_ApproxQuantile(rast, 1, .05, ARRAY[0.1, 0.3, 0.7]) |
| 2823 | }}} |
| 2824 | |
| 2825 | 3. ST_ApproxQuantile(rast raster, nband int, sample_percent double precision) -> set of records |
| 2826 | |
| 2827 | "exclude_nodata_value" is assumed to be TRUE and "quantiles" assumed to be ARRAY[0, 0.25, 0.5, 0.75, 1] |
| 2828 | |
| 2829 | 4. ST_ApproxQuantile(rast raster, sample_percent double precision, quantiles double precision[]) -> set of records |
| 2830 | |
| 2831 | "nband" is assumed to be 1 |
| 2832 | |
| 2833 | 5. ST_ApproxQuantile(rast raster, nband int, sample_percent double precision, quantile double precision) -> record |
| 2834 | |
| 2835 | quantile: the single percentile to compute |
| 2836 | |
| 2837 | 6. ST_ApproxQuantile(rast raster, sample_percent double precision, quantile double precision) -> record |
| 2838 | |
| 2839 | "nband" is assumed to be 2 |
| 2840 | |
| 2841 | 7. ST_ApproxQuantile(rast raster, sample_percent double precision) -> set of records |
| 2842 | |
| 2843 | "nband" is assumed to be 1 and "quantiles" assumed to be ARRAY[0, 0.25, 0.5, 0.75, 1] |
| 2844 | |
| 2845 | 8. ST_ApproxQuantile(rast raster, nband int, quantile double precision) -> record |
| 2846 | |
| 2847 | "sample_percent" assumed to be 0.1 |
| 2848 | |
| 2849 | 9. ST_ApproxQuantile(rast raster, quantiles double precision[]) -> set of records |
| 2850 | |
| 2851 | "nband" is assumed to be 1 and "sample_percent" assumed to be 0.1 |
| 2852 | |
| 2853 | 10. ST_ApproxQuantile(rast raster, quantile double precision) -> record |
| 2854 | |
| 2855 | "nband" assumed to be 1 and "sample_percent" assumed to be 0.1 |
| 2856 | |
| 2857 | 11. ST_ApproxQuantile(rast raster, nband int) -> set of records |
| 2858 | |
| 2859 | "quantiles" assumed to be ARRAY[0, 0.25, 0.5, 0.75, 1] and "sample_percent" assumed to be 0.1 |
| 2860 | |
| 2861 | 12. ST_ApproxQuantile(rast raster) -> set of records |
| 2862 | |
| 2863 | "nband" is assumed to be 1, "quantiles" assumed to be ARRAY[0, 0.25, 0.5, 0.75, 1] and "sample_percent" assumed to be 0.1 |
| 2864 | |
| 2865 | ---- |
| 2866 | == '''Objective FV.03 - Implement all the necessary versions of ST_MapAlgebra''' == |
| 2867 | |
| 2868 | '''ST_SameAlignment(raster, raster) -> boolean''' |
| 2869 | |
| 2870 | This function returns true if both rasters' grids are aligned. |
| 2871 | |
| 2872 | Two rasters grid are aligned if: |
| 2873 | |
| 2874 | * They share the same pixel scales and skews |
| 2875 | |
| 2876 | * At least one of any of the four corner of any pixel of one raster fall on any corner of the grid of the other raster. |
| 2877 | |
| 2878 | Alignment is not the same concept as georeference. Two rasters can be aligned but not have the same georeference. |
| 2879 | |
| 2880 | Rotation is important here since two rasters grid might look perfectly aligned but are not if their rotated are different. |
| 2881 | |
| 2882 | Knowing if two rasters share the same alignment is useful when it is time to decide if one of them must be resampled before doing other operations (like ST_MapAlgebra on two rasters). |
| 2883 | |
| 2884 | The variants of ST_SameAlignment are: |
| 2885 | |
| 2886 | 1. ST_SameAlignment(rast1 raster, rast2 raster) |
| 2887 | |
| 2888 | 2. ST_SameAlignment(ulx1, uly1, scalex1, scaley1, skewx1, skewy1, ulx2, uly2, scalex2, scaley2, skewx2, skewy2) |
| 2889 | |
| 2890 | ~~The first variant is useful to PL/pgSQL function which have already get the values of the parameters. |
| 2891 | |
| 2892 | ~~'''Implementation Details''' |
| 2893 | |
| 2894 | ~~Only the first variant should be implemented in C. The second one is a PL/pgSQL variants. The C implementation should follow the PL/pgSQL version implemented in http://trac.osgeo.org/postgis/browser/trunk/raster/scripts/plpgsql/st_mapalgebra.sql |
| 2895 | |
| 2896 | ~~It is not clear if this PL/pgSQL implementation works when raster are rotated. To verify. |
| 2897 | |
| 2898 | ~~See discussion in http://trac.osgeo.org/postgis/ticket/589 |
| 2899 | |
| 2900 | ~~Bborie: |
| 2901 | |
| 2902 | ~~The variant that should be developed in C is (2) as it is more likely that someone will have two rasters instead of that large set of raster elements. Instead, (1) should be a pl/pgsql function calling (2). |
| 2903 | |
| 2904 | ---- |
| 2905 | == '''Objective FV.05 - Being able to reproject a raster. - ''Done''''' == |
| 2906 | |
| 2907 | |
| 2908 | '''ST_Transform(raster|geometry, SRID) -> same type as input''' |
| 2909 | |
| 2910 | ST_Transform enables the end-user to reproject a raster to a new projection. Unlike the ST_Transform function for geometries, ST_Transform for rasters depends upon the specificiation of a resampling algorithm and an error tolerance. In addition, reprojecting a raster will probably change the scale of the pixels. Therefore, ST_Transform for rasters can be more involved than the ST_Transform for geometries. |
| 2911 | |
| 2912 | ''If a skewed raster is provided to ST_Transform, the output raster will be deskewed (zero skew in X and Y axes thus "north up"). To preserve the skew, use ST_Resample.'' |
| 2913 | |
| 2914 | 1. ST_Transform(rast raster, srid integer, algorithm text DEFAULT '!NearestNeighbour', maxerr double precision DEFAULT 0.125, scalex double precision DEFAULT 0, scaley double precision DEFAULT 0) |
| 2915 | |
| 2916 | returns a new raster in the projection specified by "srid" |
| 2917 | |
| 2918 | srid: the SRID of the projection to use when reprojecting the raster |
| 2919 | |
| 2920 | algorithm: the resampling algorithm to use when reprojecting the raster. default is '!NearestNeighbour'. possible algorithms are: |
| 2921 | |
| 2922 | {{{ |
| 2923 | NearestNeighbour (default. fastest performance but worst interpolation) |
| 2924 | |
| 2925 | NearestNeighbor (for those wanting to use the American spelling) |
| 2926 | |
| 2927 | Bilinear |
| 2928 | |
| 2929 | Cubic |
| 2930 | |
| 2931 | CubicSpline |
| 2932 | |
| 2933 | Lanczos |
| 2934 | }}} |
| 2935 | |
| 2936 | maxerr: the threshold for transformation approximation by the resampling algorithm (in pixel units). default is 0.125, which is the same value used in GDAL gdalwarp utility. if set to zero, no approximation takes place. |
| 2937 | |
| 2938 | scalex: the reprojected raster's scale in the X axis. default is 0 indicating that the user isn't specifying the reprojected raster's scale |
| 2939 | |
| 2940 | scaley: the reprojected raster's scale in the Y axis. default is 0 indicating that the user isn't specifying the reprojected raster's scale |
| 2941 | |
| 2942 | {{{ |
| 2943 | ST_Transform(rast, 3310) |
| 2944 | |
| 2945 | ST_Transform(rast, 3310, 'Bilinear') |
| 2946 | |
| 2947 | ST_Transform(rast, 3310, 'Lanczos', 0) |
| 2948 | |
| 2949 | ST_Transform(rast, 3310, 'Lanczos', 0.5) |
| 2950 | |
| 2951 | ST_Transform(rast, 3310, 'Lanczos', 0.125, 1000) |
| 2952 | |
| 2953 | ST_Transform(rast, 3310, 'Lanczos', 0.125, 1000, 1000) |
| 2954 | }}} |
| 2955 | |
| 2956 | 2. ST_Transform(rast raster, srid integer, scalex double precision, scaley double precision, algorithm text DEFAULT '!NearestNeighbour', maxerr double precision DEFAULT 0.125) |
| 2957 | |
| 2958 | {{{ |
| 2959 | ST_Transform(rast, 4326, 500, 500) |
| 2960 | |
| 2961 | ST_Transform(rast, 4326, 500, 500, 'Cubic') |
| 2962 | |
| 2963 | ST_Transform(rast, 4326, 500, 500, 'CubicSpline', 0) |
| 2964 | }}} |
| 2965 | |
| 2966 | 3. ST_Transform(rast raster, srid integer, scalexy double precision, algorithm text DEFAULT '!NearestNeighbour', maxerr double precision DEFAULT 0.125) |
| 2967 | |
| 2968 | scalexy: the reprojected raster's scale in the X and Y axes. default is 0 indicating that the user isn't specifying the reprojected raster's scale |
| 2969 | |
| 2970 | {{{ |
| 2971 | ST_Transform(rast, 4326, 250) |
| 2972 | |
| 2973 | ST_Transform(rast, 4326, 250, 'Cubic') |
| 2974 | |
| 2975 | ST_Transform(rast, 4326, 100, 'CubicSpline', 0) |
| 2976 | }}} |
| 2977 | |
| 2978 | ---- |
| 2979 | == '''Objective FV.06 - Being able to do some base raster operations. - ''Done Partially''''' == |
| 2980 | |
| 2981 | |
| 2982 | '''ST_ValueCount(raster, value) -> integer'''[[BR]] |
| 2983 | |
| 2984 | ST_ValueCount provides the ability to count the number of times that a user-provided value is present in a raster. To handle floating point values, a rounding argument is provided. |
| 2985 | |
| 2986 | A set of functions for one or more search values: |
| 2987 | |
| 2988 | ''If NULL is passed for "searchvalues" to any of the ST_ValueCount variations with "searchvalues", the function returns the counts for all unique values'' |
| 2989 | |
| 2990 | 1. ST_ValueCount(rast raster, nband integer, exclude_nodata_value boolean, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, count) |
| 2991 | |
| 2992 | returns the number of times that each value in searchvalues is present in the raster |
| 2993 | |
| 2994 | exclude_nodata_value: if FALSE, nodata values in band are considered in the count. if TRUE, nodata values are not considered |
| 2995 | |
| 2996 | searchvalues: the set of values to count in the raster |
| 2997 | |
| 2998 | roundto: the decimal position to round a pixel value to. Originally intended for use with 32BF and 64BF pixel types, it can also be used with integers when round to the tens, hundreds or higher place. |
| 2999 | |
| 3000 | examples are... |
| 3001 | |
| 3002 | {{{ |
| 3003 | roundto < 0: no rounding |
| 3004 | |
| 3005 | 0: no rounding |
| 3006 | |
| 3007 | 0.1: round to the tenths place |
| 3008 | |
| 3009 | 0.01: round to the hundredths place |
| 3010 | |
| 3011 | 0.001: round to the thousandths place |
| 3012 | |
| 3013 | 1: round to the ones place |
| 3014 | |
| 3015 | 10: round to the tens place |
| 3016 | |
| 3017 | 100: round to the hundreds place |
| 3018 | }}} |
| 3019 | |
| 3020 | {{{ |
| 3021 | ST_ValueCount(rast, 1, TRUE, ARRAY[23], 0) |
| 3022 | |
| 3023 | ST_ValueCount(rast, 5, FALSE, ARRAY[3.14], 0.01) |
| 3024 | |
| 3025 | ST_ValueCount(rast, 2, TRUE, ARRAY[100], 100) |
| 3026 | |
| 3027 | ST_ValueCount(rast, 1, FALSE, ARRAY[-9999, 0], 1) |
| 3028 | |
| 3029 | ST_ValueCount(rast, 1, FALSE, NULL::double precision[], 1) |
| 3030 | }}} |
| 3031 | |
| 3032 | 2. ST_ValueCount(rast raster, nband integer, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, count) |
| 3033 | |
| 3034 | exclude_nodata_value is assumed to be TRUE |
| 3035 | |
| 3036 | {{{ |
| 3037 | ST_ValueCount(rast, 5, ARRAY[3.14], 0.01) |
| 3038 | |
| 3039 | ST_ValueCount(rast, 2, NULL::double precision[], 100) |
| 3040 | }}} |
| 3041 | |
| 3042 | 3. ST_ValueCount(rast raster, nband integer, searchvalues double precision[]) -> setof record (searchvalue, count) |
| 3043 | |
| 3044 | roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE |
| 3045 | |
| 3046 | {{{ |
| 3047 | ST_ValueCount(rast, 1, ARRAY[-9999]) |
| 3048 | |
| 3049 | ST_ValueCount(rast, 1, NULL::double precision[]) |
| 3050 | }}} |
| 3051 | |
| 3052 | 4. ST_ValueCount(rast raster, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, count) |
| 3053 | |
| 3054 | nband is assumed to be 1. exclude_nodata_value is assumed to be TRUE. |
| 3055 | |
| 3056 | 5. ST_ValueCount(rast raster, searchvalues double precision[]) -> setof record (searchvalue, count) |
| 3057 | |
| 3058 | nband is assumed to be 1. roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE. |
| 3059 | |
| 3060 | A set of functions for a single search value: |
| 3061 | |
| 3062 | 1. ST_ValueCount(rast raster, nband integer, exclude_nodata_value boolean, searchvalue double precision, roundto double precision) -> integer |
| 3063 | |
| 3064 | returns the number of times that searchvalue is present in the raster |
| 3065 | |
| 3066 | searchvalue: the value to count in the raster |
| 3067 | |
| 3068 | {{{ |
| 3069 | ST_ValueCount(rast, 1, TRUE, 23, 0) |
| 3070 | |
| 3071 | ST_ValueCount(rast, 5, FALSE, 3.14, 0.01) |
| 3072 | |
| 3073 | ST_ValueCount(rast, 2, TRUE, 100, 100) |
| 3074 | |
| 3075 | ST_ValueCount(rast, 1, FALSE, -9999, 1) |
| 3076 | }}} |
| 3077 | |
| 3078 | 2. ST_ValueCount(rast raster, nband integer, searchvalue double precision, roundto double precision) -> integer |
| 3079 | |
| 3080 | exclude_nodata_value is assumed to be TRUE |
| 3081 | |
| 3082 | {{{ |
| 3083 | ST_ValueCount(rast, 5, 3.14, 0.01) |
| 3084 | |
| 3085 | ST_ValueCount(rast, 2, 100, 100) |
| 3086 | }}} |
| 3087 | |
| 3088 | 3. ST_ValueCount(rast raster, nband integer, searchvalue double precision) -> integer |
| 3089 | |
| 3090 | roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE |
| 3091 | |
| 3092 | {{{ |
| 3093 | ST_ValueCount(rast, 1, -9999) |
| 3094 | }}} |
| 3095 | |
| 3096 | 4. ST_ValueCount(rast raster, searchvalue double precision, roundto double precision) -> integer |
| 3097 | |
| 3098 | nband is assumed to be 1. exclude_nodata_value is assumed to be TRUE. |
| 3099 | |
| 3100 | 5. ST_ValueCount(rast raster, searchvalue double precision) -> integer |
| 3101 | |
| 3102 | nband is assumed to be 1. roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE. |
| 3103 | |
| 3104 | The set of functions for processing coverages return "bigint" instead of "integer". |
| 3105 | |
| 3106 | A set of functions for one or more search values: |
| 3107 | |
| 3108 | 1. ST_ValueCount(rastertable text, rastercolumn text, nband integer, exclude_nodata_value boolean, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, count) |
| 3109 | |
| 3110 | rastertable: name of the table with a raster column |
| 3111 | |
| 3112 | rastercolumn: name of the raster column |
| 3113 | |
| 3114 | {{{ |
| 3115 | ST_ValueCount('test', 'rast', 1, TRUE, ARRAY[23], 0) |
| 3116 | |
| 3117 | ST_ValueCount('test', 'rast', 5, FALSE, ARRAY[3.14], 0.01) |
| 3118 | |
| 3119 | ST_ValueCount('test', 'rast', 2, TRUE, ARRAY[100], 100) |
| 3120 | |
| 3121 | ST_ValueCount('test', 'rast', 1, FALSE, ARRAY[-9999, 0], 1) |
| 3122 | |
| 3123 | ST_ValueCount('test', 'rast', 1, FALSE, NULL::double precision[], 1) |
| 3124 | }}} |
| 3125 | |
| 3126 | 2. ST_ValueCount(rastertable text, rastercolumn text, nband integer, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, count) |
| 3127 | |
| 3128 | exclude_nodata_value is assumed to be TRUE |
| 3129 | |
| 3130 | {{{ |
| 3131 | ST_ValueCount('test', 'rast', 5, ARRAY[3.14], 0.01) |
| 3132 | |
| 3133 | ST_ValueCount('test', 'rast', 2, NULL::double precision[], 100) |
| 3134 | }}} |
| 3135 | |
| 3136 | 3. ST_ValueCount(rastertable text, rastercolumn text, nband integer, searchvalues double precision[]) -> setof record (searchvalue, count) |
| 3137 | |
| 3138 | roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE |
| 3139 | |
| 3140 | {{{ |
| 3141 | ST_ValueCount('test', 'rast', 1, ARRAY[-9999]) |
| 3142 | |
| 3143 | ST_ValueCount('test', 'rast', 1, NULL::double precision[]) |
| 3144 | }}} |
| 3145 | |
| 3146 | 4. ST_ValueCount(rastertable text, rastercolumn text, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, count) |
| 3147 | |
| 3148 | nband is assumed to be 1. exclude_nodata_value is assumed to be TRUE. |
| 3149 | |
| 3150 | 5. ST_ValueCount(rastertable text, rastercolumn text, searchvalues double precision[]) -> setof record (searchvalue, count) |
| 3151 | |
| 3152 | nband is assumed to be 1. roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE. |
| 3153 | |
| 3154 | A set of functions for a single search value: |
| 3155 | |
| 3156 | 1. ST_ValueCount(rastertable text, rastercolumn text, nband integer, exclude_nodata_value boolean, searchvalue double precision, roundto double precision) -> bigint |
| 3157 | |
| 3158 | searchvalue: the value to count in the raster |
| 3159 | |
| 3160 | {{{ |
| 3161 | ST_ValueCount('test', 'rast', 1, TRUE, 23, 0) |
| 3162 | |
| 3163 | ST_ValueCount('test', 'rast', 5, FALSE, 3.14, 0.01) |
| 3164 | |
| 3165 | ST_ValueCount('test', 'rast', 2, TRUE, 100, 100) |
| 3166 | |
| 3167 | ST_ValueCount('test', 'rast', 1, FALSE, -9999, 1) |
| 3168 | }}} |
| 3169 | |
| 3170 | 2. ST_ValueCount(rastertable text, rastercolumn text, nband integer, searchvalue double precision, roundto double precision) -> bigint |
| 3171 | |
| 3172 | exclude_nodata_value is assumed to be TRUE |
| 3173 | |
| 3174 | {{{ |
| 3175 | ST_ValueCount('test', 'rast', 5, 3.14, 0.01) |
| 3176 | |
| 3177 | ST_ValueCount('test', 'rast', 2, 100, 100) |
| 3178 | }}} |
| 3179 | |
| 3180 | 3. ST_ValueCount(rastertable text, rastercolumn text, nband integer, searchvalue double precision) -> bigint |
| 3181 | |
| 3182 | roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE |
| 3183 | |
| 3184 | {{{ |
| 3185 | ST_ValueCount('test', 'rast', 1, -9999) |
| 3186 | }}} |
| 3187 | |
| 3188 | 4. ST_ValueCount(rastertable text, rastercolumn text, searchvalue double precision, roundto double precision) -> bigint |
| 3189 | |
| 3190 | nband is assumed to be 1. exclude_nodata_value is assumed to be TRUE. |
| 3191 | |
| 3192 | 5. ST_ValueCount(rastertable text, rastercolumn text, searchvalue double precision) -> bigint |
| 3193 | |
| 3194 | nband is assumed to be 1. roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE. |
| 3195 | |
| 3196 | ---- |
| 3197 | |
| 3198 | '''ST_ValuePercent(raster, value) -> double precision'''[[BR]] |
| 3199 | |
| 3200 | ST_ValuePercent is the sibling of ST_ValueCount and returns the percentage of a raster's band that is of a specified value. To handle floating point values, a rounding argument is provided. |
| 3201 | |
| 3202 | A set of functions for one or more search values: |
| 3203 | |
| 3204 | ''If NULL is passed for "searchvalues" to any of the ST_ValuePercent variations with "searchvalues", the function returns the percents for all unique values'' |
| 3205 | |
| 3206 | 1. ST_ValuePercent(rast raster, nband integer, exclude_nodata_value boolean, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, percent) |
| 3207 | |
| 3208 | returns the percentage of a raster's band that each value in searchvalues is found |
| 3209 | |
| 3210 | exclude_nodata_value: if FALSE, nodata values in band are considered in the percents. if TRUE, nodata values are not considered |
| 3211 | |
| 3212 | searchvalues: the set of values to get percents for in the raster |
| 3213 | |
| 3214 | roundto: the decimal position to round a pixel value to. Originally intended for use with 32BF and 64BF pixel types, it can also be used with integers when round to the tens, hundreds or higher place. |
| 3215 | |
| 3216 | examples are... |
| 3217 | |
| 3218 | {{{ |
| 3219 | roundto < 0: no rounding |
| 3220 | |
| 3221 | 0: no rounding |
| 3222 | |
| 3223 | 0.1: round to the tenths place |
| 3224 | |
| 3225 | 0.01: round to the hundredths place |
| 3226 | |
| 3227 | 0.001: round to the thousandths place |
| 3228 | |
| 3229 | 1: round to the ones place |
| 3230 | |
| 3231 | 10: round to the tens place |
| 3232 | |
| 3233 | 100: round to the hundreds place |
| 3234 | }}} |
| 3235 | |
| 3236 | {{{ |
| 3237 | ST_ValuePercent(rast, 1, TRUE, ARRAY[23], 0) |
| 3238 | |
| 3239 | ST_ValuePercent(rast, 5, FALSE, ARRAY[3.14], 0.01) |
| 3240 | |
| 3241 | ST_ValuePercent(rast, 2, TRUE, ARRAY[100], 100) |
| 3242 | |
| 3243 | ST_ValuePercent(rast, 1, FALSE, ARRAY[-9999, 0], 1) |
| 3244 | |
| 3245 | ST_ValuePercent(rast, 1, FALSE, NULL::double precision[], 1) |
| 3246 | }}} |
| 3247 | |
| 3248 | 2. ST_ValuePercent(rast raster, nband integer, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, percent) |
| 3249 | |
| 3250 | exclude_nodata_value is assumed to be TRUE |
| 3251 | |
| 3252 | {{{ |
| 3253 | ST_ValuePercent(rast, 5, ARRAY[3.14], 0.01) |
| 3254 | |
| 3255 | ST_ValuePercent(rast, 2, NULL::double precision[], 100) |
| 3256 | }}} |
| 3257 | |
| 3258 | 3. ST_ValuePercent(rast raster, nband integer, searchvalues double precision[]) -> setof record (searchvalue, percent) |
| 3259 | |
| 3260 | roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE |
| 3261 | |
| 3262 | {{{ |
| 3263 | ST_ValuePercent(rast, 1, ARRAY[-9999]) |
| 3264 | |
| 3265 | ST_ValuePercent(rast, 1, NULL::double precision[]) |
| 3266 | }}} |
| 3267 | |
| 3268 | 4. ST_ValuePercent(rast raster, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, percent) |
| 3269 | |
| 3270 | nband is assumed to be 1. exclude_nodata_value is assumed to be TRUE. |
| 3271 | |
| 3272 | 5. ST_ValuePercent(rast raster, searchvalues double precision[]) -> setof record (searchvalue, percent) |
| 3273 | |
| 3274 | nband is assumed to be 1. roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE. |
| 3275 | |
| 3276 | A set of functions for a single search value: |
| 3277 | |
| 3278 | 1. ST_ValuePercent(rast raster, nband integer, exclude_nodata_value boolean, searchvalue double precision, roundto double precision) -> integer |
| 3279 | |
| 3280 | searchvalue: the value to get a percent for in the raster |
| 3281 | |
| 3282 | {{{ |
| 3283 | ST_ValuePercent(rast, 1, TRUE, 23, 0) |
| 3284 | |
| 3285 | ST_ValuePercent(rast, 5, FALSE, 3.14, 0.01) |
| 3286 | |
| 3287 | ST_ValuePercent(rast, 2, TRUE, 100, 100) |
| 3288 | |
| 3289 | ST_ValuePercent(rast, 1, FALSE, -9999, 1) |
| 3290 | }}} |
| 3291 | |
| 3292 | 2. ST_ValuePercent(rast raster, nband integer, searchvalue double precision, roundto double precision) -> integer |
| 3293 | |
| 3294 | exclude_nodata_value is assumed to be TRUE |
| 3295 | |
| 3296 | {{{ |
| 3297 | ST_ValuePercent(rast, 5, 3.14, 0.01) |
| 3298 | |
| 3299 | ST_ValuePercent(rast, 2, 100, 100) |
| 3300 | }}} |
| 3301 | |
| 3302 | 3. ST_ValuePercent(rast raster, nband integer, searchvalue double precision) -> integer |
| 3303 | |
| 3304 | roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE |
| 3305 | |
| 3306 | {{{ |
| 3307 | ST_ValuePercent(rast, 1, -9999) |
| 3308 | }}} |
| 3309 | |
| 3310 | 4. ST_ValuePercent(rast raster, searchvalue double precision, roundto double precision) -> integer |
| 3311 | |
| 3312 | nband is assumed to be 1. exclude_nodata_value is assumed to be TRUE. |
| 3313 | |
| 3314 | 5. ST_ValuePercent(rast raster, searchvalue double precision) -> integer |
| 3315 | |
| 3316 | nband is assumed to be 1. roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE. |
| 3317 | |
| 3318 | The set of functions for processing coverages return "bigint" instead of "integer". |
| 3319 | |
| 3320 | A set of functions for one or more search values: |
| 3321 | |
| 3322 | 1. ST_ValuePercent(rastertable text, rastercolumn text, nband integer, exclude_nodata_value boolean, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, percent) |
| 3323 | |
| 3324 | rastertable: name of the table with a raster column |
| 3325 | |
| 3326 | rastercolumn: name of the raster column |
| 3327 | |
| 3328 | {{{ |
| 3329 | ST_ValuePercent('test', 'rast', 1, TRUE, ARRAY[23], 0) |
| 3330 | |
| 3331 | ST_ValuePercent('test', 'rast', 5, FALSE, ARRAY[3.14], 0.01) |
| 3332 | |
| 3333 | ST_ValuePercent('test', 'rast', 2, TRUE, ARRAY[100], 100) |
| 3334 | |
| 3335 | ST_ValuePercent('test', 'rast', 1, FALSE, ARRAY[-9999, 0], 1) |
| 3336 | |
| 3337 | ST_ValuePercent('test', 'rast', 1, FALSE, NULL::double precision[], 1) |
| 3338 | }}} |
| 3339 | |
| 3340 | 2. ST_ValuePercent(rastertable text, rastercolumn text, nband integer, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, percent) |
| 3341 | |
| 3342 | exclude_nodata_value is assumed to be TRUE |
| 3343 | |
| 3344 | {{{ |
| 3345 | ST_ValuePercent('test', 'rast', 5, ARRAY[3.14], 0.01) |
| 3346 | |
| 3347 | ST_ValuePercent('test', 'rast', 2, NULL::double precision[], 100) |
| 3348 | }}} |
| 3349 | |
| 3350 | 3. ST_ValuePercent(rastertable text, rastercolumn text, nband integer, searchvalues double precision[]) -> setof record (searchvalue, percent) |
| 3351 | |
| 3352 | roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE |
| 3353 | |
| 3354 | {{{ |
| 3355 | ST_ValuePercent('test', 'rast', 1, ARRAY[-9999]) |
| 3356 | |
| 3357 | ST_ValuePercent('test', 'rast', 1, NULL::double precision[]) |
| 3358 | }}} |
| 3359 | |
| 3360 | 4. ST_ValuePercent(rastertable text, rastercolumn text, searchvalues double precision[], roundto double precision) -> setof record (searchvalue, percent) |
| 3361 | |
| 3362 | nband is assumed to be 1. exclude_nodata_value is assumed to be TRUE. |
| 3363 | |
| 3364 | 5. ST_ValuePercent(rastertable text, rastercolumn text, searchvalues double precision[]) -> setof record (searchvalue, percent) |
| 3365 | |
| 3366 | nband is assumed to be 1. roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE. |
| 3367 | |
| 3368 | A set of functions for a single search value: |
| 3369 | |
| 3370 | 1. ST_ValuePercent(rastertable text, rastercolumn text, nband integer, exclude_nodata_value boolean, searchvalue double precision, roundto double precision) -> bigint |
| 3371 | |
| 3372 | searchvalue: the value to get a percent for in the raster |
| 3373 | |
| 3374 | {{{ |
| 3375 | ST_ValuePercent('test', 'rast', 1, TRUE, 23, 0) |
| 3376 | |
| 3377 | ST_ValuePercent('test', 'rast', 5, FALSE, 3.14, 0.01) |
| 3378 | |
| 3379 | ST_ValuePercent('test', 'rast', 2, TRUE, 100, 100) |
| 3380 | |
| 3381 | ST_ValuePercent('test', 'rast', 1, FALSE, -9999, 1) |
| 3382 | }}} |
| 3383 | |
| 3384 | 2. ST_ValuePercent(rastertable text, rastercolumn text, nband integer, searchvalue double precision, roundto double precision) -> bigint |
| 3385 | |
| 3386 | exclude_nodata_value is assumed to be TRUE |
| 3387 | |
| 3388 | {{{ |
| 3389 | ST_ValuePercent('test', 'rast', 5, 3.14, 0.01) |
| 3390 | |
| 3391 | ST_ValuePercent('test', 'rast', 2, 100, 100) |
| 3392 | }}} |
| 3393 | |
| 3394 | 3. ST_ValuePercent(rastertable text, rastercolumn text, nband integer, searchvalue double precision) -> bigint |
| 3395 | |
| 3396 | roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE |
| 3397 | |
| 3398 | {{{ |
| 3399 | ST_ValuePercent('test', 'rast', 1, -9999) |
| 3400 | }}} |
| 3401 | |
| 3402 | 4. ST_ValuePercent(rastertable text, rastercolumn text, searchvalue double precision, roundto double precision) -> bigint |
| 3403 | |
| 3404 | nband is assumed to be 1. exclude_nodata_value is assumed to be TRUE. |
| 3405 | |
| 3406 | 5. ST_ValuePercent(rastertable text, rastercolumn text, searchvalue double precision) -> bigint |
| 3407 | |
| 3408 | nband is assumed to be 1. roundto is assumed to be 0, so no rounding takes place. exclude_nodata_value is assumed to be TRUE. |
| 3409 | |
| 3410 | ---- |
| 3411 | |
| 3412 | '''ST_Resample(raster, method, originx, originy, pixelsizex, pixelsizey) -> raster''' |
| 3413 | |
| 3414 | ST_Resample is the main function underlying the ST_Transform, ST_Rescale, ST_Reskew and ST_SnapToGrid functions. ST_Resample provides the ability to change a raster's projection, adjust the scale of the raster within its extent, change the skew (or deskew) and "dissolve" the raster to a grid. |
| 3415 | |
| 3416 | ''If a skewed raster is provided to ST_Resample and skewx and/or skewy are not provided, the output raster will be deskewed (zero skew in X and Y axes thus "north up")'' |
| 3417 | |
| 3418 | 1. ST_Resample( |
| 3419 | rast raster, |
| 3420 | srid integer DEFAULT NULL, |
| 3421 | scalex double precision DEFAULT 0, scaley double precision DEFAULT 0, |
| 3422 | gridx double precision DEFAULT NULL, gridy double precision DEFAULT NULL, |
| 3423 | skewx double precision DEFAULT 0, skewy double precision DEFAULT 0, |
| 3424 | algorithm text DEFAULT 'NearestNeighbour', maxerr double precision DEFAULT 0.125 |
| 3425 | ) -> raster |
| 3426 | |
| 3427 | srid: the SRID that the function will use to reproject the raster to. If NULL, the raster's SRID will be used. |
| 3428 | |
| 3429 | scalex: the scale/pixel size in the X axis of the resampled raster. If scalex and scaley are zero (0), the resampled raster's scale will be autocomputed. If provided, scaley must also be provided. |
| 3430 | |
| 3431 | scaley: the scale/pixel size in the Y axis of the resampled raster. If scalex and scaley are zero (0), the resampled raster's scale will be autocomputed. If provided, scalex must also be provided. |
| 3432 | |
| 3433 | gridx: the X coordinate of a point on the grid to which the raster will be aligned. Value is in the resampled raster's world coordinates. If provided, gridy must also be provided. |
| 3434 | |
| 3435 | gridy: the Y coordinate of a point on the grid to which the raster will be aligned. Value is in the resampled raster's world coordinates. If provided, gridx must also be provided. |
| 3436 | |
| 3437 | skewx: the skew along the X axis of the resampled raster. If skewx and skewy are zero (0), the resampled raster will be "north up". |
| 3438 | |
| 3439 | skewy: the skew along the Y axis of the resampled raster. If skewx and skewy are zero (0), the resampled raster will be "north up". |
| 3440 | |
| 3441 | algorithm: the algorithm to use when resampling the raster. default is 'NearestNeighbour'. possible algorithms are: |
| 3442 | |
| 3443 | {{{ |
| 3444 | NearestNeighbour (default. fastest performance but worst interpolation) |
| 3445 | |
| 3446 | NearestNeighbor (for those wanting to use the American spelling) |
| 3447 | |
| 3448 | Bilinear |
| 3449 | |
| 3450 | Cubic |
| 3451 | |
| 3452 | CubicSpline |
| 3453 | |
| 3454 | Lanczos |
| 3455 | }}} |
| 3456 | |
| 3457 | maxerr: the threshold for approximation by the resampling algorithm (in pixel units). default is 0.125, which is the same value used in GDAL gdalwarp utility. if set to zero, no approximation takes place. |
| 3458 | |
| 3459 | 2. ST_Resample( |
| 3460 | rast raster, |
| 3461 | ref raster, |
| 3462 | algorithm text DEFAULT 'NearestNeighbour', maxerr double precision DEFAULT 0.125 |
| 3463 | ) -> raster |
| 3464 | |
| 3465 | ref: the reference raster to which rast will copy the scalex, scaley, skewx, skewy and srid. In addition, the upperleft corner of ref will be used as a grid point to align rast. |
| 3466 | |
| 3467 | ---- |
| 3468 | |
| 3469 | '''ST_Rescale(raster, scalex, scaley) -> raster''' |
| 3470 | |
| 3471 | ST_Rescale is a focused function of ST_Resample for changing the X and Y scale without affecting the extent of the raster. |
| 3472 | |
| 3473 | ''If a skewed raster is provided to ST_Rescale, the output raster will be deskewed (zero skew in X and Y axes thus "north up"). To preserve the skew, use ST_Resample.'' |
| 3474 | |
| 3475 | 1. ST_Rescale(rast raster, scalex double precision, scaley double precision, algorithm text DEFAULT 'NearestNeighbour', maxerr double precision DEFAULT 0.125) -> raster |
| 3476 | |
| 3477 | scalex: the scale/pixel size in the X axis of the resampled raster |
| 3478 | |
| 3479 | scaley: the scale/pixel size in the Y axis of the resampled raster |
| 3480 | |
| 3481 | 2. ST_Rescale(rast raster, scalexy double precision, algorithm text DEFAULT 'NearestNeighbour', maxerr double precision DEFAULT 0.125) -> raster |
| 3482 | |
| 3483 | scalexy: the scale/pixel size in the X and Y axes of the resampled raster. |
| 3484 | |
| 3485 | ---- |
| 3486 | |
| 3487 | '''ST_Reskew(raster, skewx, skewy) -> raster''' |
| 3488 | |
| 3489 | ST_Reskew is a focused function of ST_Resample for changing the skew along the X and Y axes. |
| 3490 | |
| 3491 | 1. ST_Reskew(rast raster, skewx double precision, skewy double precision, algorithm text DEFAULT 'NearestNeighbour', maxerr double precision DEFAULT 0.125) -> raster |
| 3492 | |
| 3493 | skewx: the skew along the X axis of the resampled raster. If skewx and skewy are zero (0), the resampled raster will be "north up". |
| 3494 | |
| 3495 | skewy: the skew along the Y axis of the resampled raster. If skewx and skewy are zero (0), the resampled raster will be "north up". |
| 3496 | |
| 3497 | 2. ST_Reskew(rast raster, skewxy double precision, algorithm text DEFAULT 'NearestNeighbour', maxerr double precision DEFAULT 0.125) -> raster |
| 3498 | |
| 3499 | skewxy: the skew along both X and Y axes of the resampled raster. If skewxy is zero (0), the resampled raster will be "north up". |
| 3500 | |
| 3501 | ---- |
| 3502 | |
| 3503 | '''ST_SnapToGrid(raster, gridx, gridy)''' |
| 3504 | |
| 3505 | ST_SnapToGrid provides the ability to align a raster to grid (possibly that of a coverage). The returned raster has its upper-left corner placed at the closest valid grid point to the source raster's upper-left corner without losing a data. The same is done for the lower-right corner. |
| 3506 | |
| 3507 | [[Image(snaptogrid.png)]] |
| 3508 | |
| 3509 | ''If a skewed raster is provided to ST_SnapToGrid, the output raster will be deskewed (zero skew in X and Y axes thus "north up"). To preserve the skew, use ST_Resample.'' |
| 3510 | |
| 3511 | 1. ST_SnapToGrid( |
| 3512 | rast raster, |
| 3513 | gridx double precision, gridy double precision, |
| 3514 | algorithm text DEFAULT 'NearestNeighbour', maxerr double precision DEFAULT 0.125, |
| 3515 | scalex double precision DEFAULT 0, scaley double precision DEFAULT 0 |
| 3516 | ) -> raster |
| 3517 | |
| 3518 | gridx: the X coordinate of a point on the grid to which the raster will be aligned. Value is in the raster's world coordinates. |
| 3519 | |
| 3520 | gridy: the Y coordinate of a point on the grid to which the raster will be aligned. Value is in the raster's world coordinates. |
| 3521 | |
| 3522 | scalex: the scale/pixel size in the X axis of the resampled raster. This is also the scale of the grid to which the raster is being "snapped". If provided, scaley must be provided. If scalex and scaley are zero, the input raster's scale will be used. |
| 3523 | |
| 3524 | scaley: the scale/pixel size in the Y axis of the resampled raster. This is also the scale of the grid to which the raster is being "snapped" If provided, scalex must be provided. If scalex and scaley are zero, the input raster's scale will be used. |
| 3525 | |
| 3526 | 2. ST_SnapToGrid( |
| 3527 | rast raster, |
| 3528 | gridx double precision, gridy double precision, |
| 3529 | scalex double precision, scaley double precision, |
| 3530 | algorithm text DEFAULT 'NearestNeighbour', maxerr double precision DEFAULT 0.125 |
| 3531 | ) -> raster |
| 3532 | |
| 3533 | 3. ST_SnapToGrid( |
| 3534 | rast raster, |
| 3535 | gridx double precision, gridy double precision, |
| 3536 | scalexy double precision, |
| 3537 | algorithm text DEFAULT 'NearestNeighbour', maxerr double precision DEFAULT 0.125 |
| 3538 | ) -> raster |
| 3539 | |
| 3540 | scalexy: the scale/pixel size in the X and Y axes of the resampled raster. |
| 3541 | |
| 3542 | ~~ * Implemented as a wrapper around GDAL like done for ST_DumpAsPolygons()~~ |
| 3543 | ~~ * Resampling methods are the same as the one priovided by GDAL~~ |
| 3544 | |
| 3545 | ~~ '''Variants'''~~ |
| 3546 | |
| 3547 | ~~ * The '''first series of variants''' only change the pixelsize of the raster.~~ |
| 3548 | |
| 3549 | ~~ 1) ST_Resample(raster, pixelsize) - modify pixelsize only and resample using the default method~~ |
| 3550 | |
| 3551 | ~~ 2) ST_Resample(raster, method, pixelsize) - modify pixelsize and resample using the specified method~~ |
| 3552 | |
| 3553 | ~~ 3) ST_Resample(raster, pixelsizex, pixelsizey) - modify pixelsize with different values for x and y using the default method~~ |
| 3554 | |
| 3555 | ~~ 4) ST_Resample(raster, method, pixelsizex, pixelsizey) - modify pixelsize with different values for x and y using the specified method~~ |
| 3556 | |
| 3557 | ~~ * The '''second series of variants''' realign the raster and change the pixelsize~~ |
| 3558 | |
| 3559 | ~~ 5) ST_Resample(raster, x, y, pixelsize) - realign and modify pixelsize using the default method~~ |
| 3560 | |
| 3561 | ~~ 6) ST_Resample(raster, method, x, y, pixelsize) - realign and modify pixelsize using the specified method~~ |
| 3562 | |
| 3563 | ~~ 7) ST_Resample(raster, x, y, pixelsizex, pixelsizey) - realign and modify pixelsize with different values for x and y using the default method~~ |
| 3564 | |
| 3565 | ~~ 8) ST_Resample(raster, method, x, y, pixelsizex, pixelsizey) - realign and modify pixelsize with different values for x and y using the specified method~~ |
| 3566 | |
| 3567 | ~~ 9) ST_Resample(raster, x, y, pixelsizex, pixelsizey, skewx, skewy) - realign and modify pixelsize and skew with different values for x and y using the default method~~ |
| 3568 | |
| 3569 | ~~ 10) ST_Resample(raster, method, x, y, pixelsizex, pixelsizey, skewx, skewy) - realign and modify pixelsize and skew with different values for x and y using the specified method~~ |
| 3570 | |
| 3571 | ~~ * The '''third series of variants''' align and resample the raster to match the alignment, pixelsize and skew of an existing raster.~~ |
| 3572 | |
| 3573 | ~~ 11) ST_Resample(destraster, sourceraster)~~ |
| 3574 | |
| 3575 | ~~ '''Questions'''~~ |
| 3576 | |
| 3577 | ~~ * Should there be a band parameter?~~ |
| 3578 | |
| 3579 | ~~ * How does GDAL allow resampling?~~ |
| 3580 | |
| 3581 | ~~ * Which methods GDAL supports? ArcGIS supports NEAREST | BILINEAR | CUBIC | MAJORITY~~ |
| 3582 | |
| 3583 | ~~ * Does GDAL support change in skew?~~ |
| 3584 | |
| 3585 | ---- |
| 3586 | == '''Objective FV.22 - Making raster_columns and raster_overview as views''' == |
| 3587 | |
| 3588 | raster_columns and raster_overviews are now constraint-based views. The structure of the raster_columns views is below. |
| 3589 | |
| 3590 | {{{ |
| 3591 | #!html |
| 3592 | <TABLE BORDER=1> |
| 3593 | <THEAD> |
| 3594 | <TR> |
| 3595 | <TD ALIGN=LEFT style="font-weight: bold; font-style: italic;">Column</TD> |
| 3596 | <TD ALIGN=LEFT style="font-weight: bold; font-style: italic;">PostgreSQL Type</TD> |
| 3597 | <TD ALIGN=LEFT style="font-weight: bold; font-style: italic;">Description</TD> |
| 3598 | </TR> |
| 3599 | </THEAD> |
| 3600 | <TBODY> |
| 3601 | <TR> |
| 3602 | <TD ALIGN=LEFT>r_table_catalog</TD> |
| 3603 | <TD ALIGN=LEFT>name</TD> |
| 3604 | <TD ALIGN=LEFT>Name of the database containing the table with the raster column.</TD> |
| 3605 | </TR> |
| 3606 | <TR> |
| 3607 | <TD ALIGN=LEFT>r_table_schema</TD> |
| 3608 | <TD ALIGN=LEFT>name</TD> |
| 3609 | <TD ALIGN=LEFT>Name of the schema containing the table with the raster column.</TD> |
| 3610 | </TR> |
| 3611 | <TR> |
| 3612 | <TD ALIGN=LEFT>r_table_name</TD> |
| 3613 | <TD ALIGN=LEFT>name</TD> |
| 3614 | <TD ALIGN=LEFT>Name of the table containing a column of type raster.</TD> |
| 3615 | </TR> |
| 3616 | <TR> |
| 3617 | <TD ALIGN=LEFT>r_raster_column</TD> |
| 3618 | <TD ALIGN=LEFT>name</TD> |
| 3619 | <TD ALIGN=LEFT>Name of the raster column in the table. All attribute columns following this column apply to the rasters in this column. <span style="font-style: italic; font-weight: bold;">This column was previously known as r_column.</span></TD> |
| 3620 | </TR> |
| 3621 | <TR> |
| 3622 | <TD ALIGN=LEFT>srid</TD> |
| 3623 | <TD ALIGN=LEFT>integer</TD> |
| 3624 | <TD ALIGN=LEFT>ID of the spatial reference system of the rasters in this column. Value is extracted from the ST_SRID constraint on this raster column. <span style="font-style: italic;">The constraint is typically named enforce_srid_<r_raster_column>.</span></TD> |
| 3625 | </TR> |
| 3626 | <TR> |
| 3627 | <TD ALIGN=LEFT>scale_x</TD> |
| 3628 | <TD ALIGN=LEFT>double precision</TD> |
| 3629 | <TD ALIGN=LEFT>The scale on the X-axis of the rasters in this column. Value is extracted from the ST_ScaleX constraint on this raster column. <span style="font-style: italic;">The constraint is typically named enforce_scalex_<r_raster_column>.</span></TD> |
| 3630 | </TR> |
| 3631 | <TR> |
| 3632 | <TD ALIGN=LEFT>scale_y</TD> |
| 3633 | <TD ALIGN=LEFT>double precision</TD> |
| 3634 | <TD ALIGN=LEFT>The scale on the Y-axis of the rasters in this column. Value is extracted from the ST_ScaleY constraint on this raster column. <span style="font-style: italic;">The constraint is typically named enforce_scaley_<r_raster_column>.</span></TD> |
| 3635 | </TR> |
| 3636 | <TR> |
| 3637 | <TD ALIGN=LEFT>blocksize_x</TD> |
| 3638 | <TD ALIGN=LEFT>integer</TD> |
| 3639 | <TD ALIGN=LEFT>The width of the rasters in this column. Value is extracted from the ST_Width constraint on this raster column. <span style="font-style: italic;">The constraint is typically named enforce_width_<r_raster_column>.</span></TD> |
| 3640 | </TR> |
| 3641 | <TR> |
| 3642 | <TD ALIGN=LEFT>blocksize_y</TD> |
| 3643 | <TD ALIGN=LEFT>integer</TD> |
| 3644 | <TD ALIGN=LEFT>The height of the rasters in this column. Value is extracted from the ST_Height constraint on this raster column. <span style="font-style: italic;">The constraint is typically named enforce_height_<r_raster_column>.</span></TD> |
| 3645 | </TR> |
| 3646 | <TR> |
| 3647 | <TD ALIGN=LEFT>same_alignment</TD> |
| 3648 | <TD ALIGN=LEFT>boolean</TD> |
| 3649 | <TD ALIGN=LEFT>If TRUE, all rasters in this column are aligned. State is extracted from the ST_SameAlignment constraint comparing the rasters in this column against coordinates known to be on the grid. <span style="font-style: italic;">The constraint is typically named enforce_same_alignment_<r_raster_column>.</span></TD> |
| 3650 | </TR> |
| 3651 | <TR> |
| 3652 | <TD ALIGN=LEFT>regular_blocking</TD> |
| 3653 | <TD ALIGN=LEFT>boolean</TD> |
| 3654 | <TD ALIGN=LEFT>If TRUE, all rasters in this column are regularly blocked. <span style="color: red; font-weight: bold;">Though this column is technically based upon a constraint, the constraint is purely information and does NO actual constraining. Therefore if this column is TRUE, a user explicitly specified that the rasters in this column are regularly blocked.</span> <span style="font-style: italic;">The constraint is typically named enforce_regular_blocking_<r_raster_column>.</span></TD> |
| 3655 | </TR> |
| 3656 | <TR> |
| 3657 | <TD ALIGN=LEFT>num_bands</TD> |
| 3658 | <TD ALIGN=LEFT>integer</TD> |
| 3659 | <TD ALIGN=LEFT>The number bands within each raster of this column. Value is extracted from the ST_NumBands constraint on this raster column. <span style="font-style: italic;">The constraint is typically named enforce_num_bands_< r_raster_column>.</span></TD> |
| 3660 | </TR> |
| 3661 | <TR> |
| 3662 | <TD ALIGN=LEFT>pixel_types</TD> |
| 3663 | <TD ALIGN=LEFT>text[]</TD> |
| 3664 | <TD ALIGN=LEFT>Text array of the pixel types of the bands within each raster of this column. Value is extracted from a special function that creates an array of the band pixel types of the rasters in this column. <span style="font-style: italic;">The constraint is typically named enforce_pixel_types_<r_raster_column>.</span></TD> |
| 3665 | </TR> |
| 3666 | <TR> |
| 3667 | <TD ALIGN=LEFT>nodata_values</TD> |
| 3668 | <TD ALIGN=LEFT>double precision[]</TD> |
| 3669 | <TD ALIGN=LEFT>Double precision array of the NODATA values of the bands within each raster of this column. Value is extracted from a special function that creates an array of the band NODATA values of the rasters in this column. <span style="font-style: italic;">The constraint is typically named enforce_nodata_values_<r_raster_column>.</span></TD> |
| 3670 | </TR> |
| 3671 | <TR> |
| 3672 | <TD ALIGN=LEFT>out_db</TD> |
| 3673 | <TD ALIGN=LEFT>boolean[]</TD> |
| 3674 | <TD ALIGN=LEFT>Boolean array of the out-of-database flag of the bands within each raster of this column. Value is extracted from a special function that creates an array of the band out-of-database flags of the rasters in this column. <span style="font-style: italic;">The constraint is typically named enforce_out_db_<r_raster_column>.</span></TD> |
| 3675 | </TR> |
| 3676 | <TR> |
| 3677 | <TD ALIGN=LEFT>extent</TD> |
| 3678 | <TD ALIGN=LEFT>geometry</TD> |
| 3679 | <TD ALIGN=LEFT>The maximum extent within which all rasters of this column must be covered by. The maximum extent is computed by ST_ConvexHull(ST_Collect(ST_ConvexHull(raster))) of all rasters in this column at the time that the extent constraint was added.. Value is extracted from the ST_CoveredBy(ST_ConvexHull(raster)) constraint on this raster column. <span style="font-style: italic;">The constraint is typically named enforce_max_extent_<r_raster_column>.</span></TD> |
| 3680 | </TR> |
| 3681 | </TBODY> |
| 3682 | </TABLE> |
| 3683 | |
| 3684 | }}} |
| 3685 | |
| 3686 | Raster constraints can be set using one of the !AddRasterConstraints functions. |
| 3687 | |
| 3688 | 1. !AddRasterConstraints ( |
| 3689 | rastschema name,[[BR]] |
| 3690 | rasttable name,[[BR]] |
| 3691 | rastcolumn name,[[BR]] |
| 3692 | VARIADIC constraints text[] |
| 3693 | ) |
| 3694 | |
| 3695 | constraints: keywords indicating constraint to attempt to add. possible keywords are: |
| 3696 | |
| 3697 | {{{ |
| 3698 | srid |
| 3699 | scale_x or scalex |
| 3700 | scale_y or scaley |
| 3701 | scale |
| 3702 | blocksize_x or blocksizex or width |
| 3703 | blocksize_y or blocksizey or height |
| 3704 | blocksize |
| 3705 | same_alignment or samealignment or alignment |
| 3706 | regular_blocking or regularblocking |
| 3707 | num_bands or numbands |
| 3708 | pixel_types or pixeltypes |
| 3709 | nodata_values or nodatavalues or nodata |
| 3710 | out_db or outdb |
| 3711 | extent |
| 3712 | }}} |
| 3713 | |
| 3714 | {{{ |
| 3715 | SELECT AddRasterConstraints('schema', 'table', 'rast', 'srid', 'extent') |
| 3716 | }}} |
| 3717 | |
| 3718 | 2. !AddRasterConstraints ( |
| 3719 | rasttable name,[[BR]] |
| 3720 | rastcolumn name,[[BR]] |
| 3721 | VARIADIC constraints text[] |
| 3722 | ) |
| 3723 | |
| 3724 | 3. !AddRasterConstraints ( |
| 3725 | rastschema name,[[BR]] |
| 3726 | rasttable name,[[BR]] |
| 3727 | rastcolumn name,[[BR]] |
| 3728 | srid boolean DEFAULT TRUE,[[BR]] |
| 3729 | scale_x boolean DEFAULT TRUE,[[BR]] |
| 3730 | scale_y boolean DEFAULT TRUE,[[BR]] |
| 3731 | blocksize_x boolean DEFAULT TRUE,[[BR]] |
| 3732 | blocksize_y boolean DEFAULT TRUE,[[BR]] |
| 3733 | same_alignment boolean DEFAULT TRUE,[[BR]] |
| 3734 | regular_blocking boolean DEFAULT FALSE,[[BR]] |
| 3735 | num_bands boolean DEFAULT TRUE,[[BR]] |
| 3736 | pixel_types boolean DEFAULT TRUE,[[BR]] |
| 3737 | nodata_values boolean DEFAULT TRUE,[[BR]] |
| 3738 | out_db boolean DEFAULT TRUE,[[BR]] |
| 3739 | extent boolean DEFAULT TRUE |
| 3740 | ) |
| 3741 | |
| 3742 | 4. !AddRasterConstraints ( |
| 3743 | rasttable name,[[BR]] |
| 3744 | rastcolumn name,[[BR]] |
| 3745 | srid boolean DEFAULT TRUE,[[BR]] |
| 3746 | scale_x boolean DEFAULT TRUE,[[BR]] |
| 3747 | scale_y boolean DEFAULT TRUE,[[BR]] |
| 3748 | blocksize_x boolean DEFAULT TRUE,[[BR]] |
| 3749 | blocksize_y boolean DEFAULT TRUE,[[BR]] |
| 3750 | same_alignment boolean DEFAULT TRUE,[[BR]] |
| 3751 | regular_blocking boolean DEFAULT FALSE,[[BR]] |
| 3752 | num_bands boolean DEFAULT TRUE,[[BR]] |
| 3753 | pixel_types boolean DEFAULT TRUE,[[BR]] |
| 3754 | nodata_values boolean DEFAULT TRUE,[[BR]] |
| 3755 | out_db boolean DEFAULT TRUE,[[BR]] |
| 3756 | extent boolean DEFAULT TRUE |
| 3757 | ) |
| 3758 | |
| 3759 | Though users can manually remove raster constraints, it is easier to use one of the !DropRasterConstraints functions |
| 3760 | |
| 3761 | 1. !DropRasterConstraints ( |
| 3762 | rastschema name,[[BR]] |
| 3763 | rasttable name,[[BR]] |
| 3764 | rastcolumn name,[[BR]] |
| 3765 | VARIADIC constraints text[] |
| 3766 | ) |
| 3767 | |
| 3768 | constraints: the same keywords as function !#1 for !AddRasterConstraints |
| 3769 | |
| 3770 | 2. !DropRasterConstraints ( |
| 3771 | rasttable name,[[BR]] |
| 3772 | rastcolumn name,[[BR]] |
| 3773 | VARIADIC constraints text[] |
| 3774 | ) |
| 3775 | |
| 3776 | 3. !DropRasterConstraints ( |
| 3777 | rastschema name,[[BR]] |
| 3778 | rasttable name,[[BR]] |
| 3779 | rastcolumn name,[[BR]] |
| 3780 | srid boolean DEFAULT TRUE,[[BR]] |
| 3781 | scale_x boolean DEFAULT TRUE,[[BR]] |
| 3782 | scale_y boolean DEFAULT TRUE,[[BR]] |
| 3783 | blocksize_x boolean DEFAULT TRUE,[[BR]] |
| 3784 | blocksize_y boolean DEFAULT TRUE,[[BR]] |
| 3785 | same_alignment boolean DEFAULT TRUE,[[BR]] |
| 3786 | regular_blocking boolean DEFAULT TRUE,[[BR]] |
| 3787 | num_bands boolean DEFAULT TRUE,[[BR]] |
| 3788 | pixel_types boolean DEFAULT TRUE,[[BR]] |
| 3789 | nodata_values boolean DEFAULT TRUE,[[BR]] |
| 3790 | out_db boolean DEFAULT TRUE,[[BR]] |
| 3791 | extent boolean DEFAULT TRUE |
| 3792 | ) |
| 3793 | |
| 3794 | 4. !DropRasterConstraints ( |
| 3795 | rasttable name,[[BR]] |
| 3796 | rastcolumn name,[[BR]] |
| 3797 | srid boolean DEFAULT TRUE,[[BR]] |
| 3798 | scale_x boolean DEFAULT TRUE,[[BR]] |
| 3799 | scale_y boolean DEFAULT TRUE,[[BR]] |
| 3800 | blocksize_x boolean DEFAULT TRUE,[[BR]] |
| 3801 | blocksize_y boolean DEFAULT TRUE,[[BR]] |
| 3802 | same_alignment boolean DEFAULT TRUE,[[BR]] |
| 3803 | regular_blocking boolean DEFAULT TRUE,[[BR]] |
| 3804 | num_bands boolean DEFAULT TRUE,[[BR]] |
| 3805 | pixel_types boolean DEFAULT TRUE,[[BR]] |
| 3806 | nodata_values boolean DEFAULT TRUE,[[BR]] |
| 3807 | out_db boolean DEFAULT TRUE,[[BR]] |
| 3808 | extent boolean DEFAULT TRUE |
| 3809 | ) |
| 3810 | |
| 3811 | |
| 3812 | |
| 3813 | The raster_overviews view is structured as the following: |
| 3814 | |
| 3815 | {{{ |
| 3816 | #!html |
| 3817 | <TABLE BORDER=1> |
| 3818 | <THEAD> |
| 3819 | <TR> |
| 3820 | <TD ALIGN=LEFT style="font-weight: bold; font-style: italic;">Column</TD> |
| 3821 | <TD ALIGN=LEFT style="font-weight: bold; font-style: italic;">PostgreSQL Type</TD> |
| 3822 | <TD ALIGN=LEFT style="font-weight: bold; font-style: italic;">Description</TD> |
| 3823 | </TR> |
| 3824 | </THEAD> |
| 3825 | <TBODY> |
| 3826 | <TR> |
| 3827 | <TD ALIGN=LEFT>o_table_catalog</TD> |
| 3828 | <TD ALIGN=LEFT>name</TD> |
| 3829 | <TD ALIGN=LEFT>Name of the database containing the table with the overview column.</TD> |
| 3830 | </TR> |
| 3831 | <TR> |
| 3832 | <TD ALIGN=LEFT>o_table_schema</TD> |
| 3833 | <TD ALIGN=LEFT>name</TD> |
| 3834 | <TD ALIGN=LEFT>Name of the schema containing the table with the overview column.</TD> |
| 3835 | </TR> |
| 3836 | <TR> |
| 3837 | <TD ALIGN=LEFT>o_table_name</TD> |
| 3838 | <TD ALIGN=LEFT>name</TD> |
| 3839 | <TD ALIGN=LEFT>Name of the table containing a column of type raster considered an overview.</TD> |
| 3840 | </TR> |
| 3841 | <TR> |
| 3842 | <TD ALIGN=LEFT>o_raster_column</TD> |
| 3843 | <TD ALIGN=LEFT>name</TD> |
| 3844 | <TD ALIGN=LEFT>Name of the overview column in the table. All attribute columns following this column apply to the rasters in this column. <span style="font-weight: bold; font-style: italic;">This column was previously known as o_column.</span></TD> |
| 3845 | </TR> |
| 3846 | <TR> |
| 3847 | <TD ALIGN=LEFT>r_table_catalog</TD> |
| 3848 | <TD ALIGN=LEFT>name</TD> |
| 3849 | <TD ALIGN=LEFT>Name of the database containing the table with the raster column from which this overview column was derived.</TD> |
| 3850 | </TR> |
| 3851 | <TR> |
| 3852 | <TD ALIGN=LEFT>r_table_schema</TD> |
| 3853 | <TD ALIGN=LEFT>name</TD> |
| 3854 | <TD ALIGN=LEFT>Name of the schema containing the table with the raster column from which this overview column was derived.</TD> |
| 3855 | </TR> |
| 3856 | <TR> |
| 3857 | <TD ALIGN=LEFT>r_table_name</TD> |
| 3858 | <TD ALIGN=LEFT>name</TD> |
| 3859 | <TD ALIGN=LEFT>Name of the table containing a column of type raster from which this overview column was derived.</TD> |
| 3860 | </TR> |
| 3861 | <TR> |
| 3862 | <TD ALIGN=LEFT>r_raster_column</TD> |
| 3863 | <TD ALIGN=LEFT>name</TD> |
| 3864 | <TD ALIGN=LEFT>Name of the raster column in the table from which this overview column was derived. <span style="font-weight: bold; font-style: italic;">This column was previously known as r_column.</span></TD> |
| 3865 | </TR> |
| 3866 | <TR> |
| 3867 | <TD ALIGN=LEFT>overview_factor</TD> |
| 3868 | <TD ALIGN=LEFT>integer</TD> |
| 3869 | <TD ALIGN=LEFT>The factor used to compute the overviews in this column. If the factor is 2, the overviews' scale is 2x of the reference rasters. </TD> |
| 3870 | </TR> |
| 3871 | </TBODY> |
| 3872 | </TABLE> |
| 3873 | }}} |
| 3874 | |
| 3875 | '''One column has been removed from the raster_overviews views: out_db.''' |
| 3876 | |
| 3877 | As all overviews are rasters, overviews will have have a record in raster_columns and another record in raster_overviews. |
| 3878 | |
| 3879 | The distinguishing factor that makes a raster be treated as an overview is the ''enforce_overview_<o_raster_column>'' constraint. The constraint can be applied using one of the !AddOverviewConstraints functions. '''The overview constraint checks that the reference raster column and table exists. If the reference raster column does not exist, the constraint is violated.''' |
| 3880 | |
| 3881 | 1. !AddOverviewConstraints ( |
| 3882 | ovschema name, ovtable name, ovcolumn name,[[BR]] |
| 3883 | refschema name, reftable name, refcolumn name,[[BR]] |
| 3884 | ovfactor int |
| 3885 | ) |
| 3886 | |
| 3887 | 2. !AddOverviewConstraints ( |
| 3888 | ovtable name, ovcolumn name,[[BR]] |
| 3889 | reftable name, refcolumn name,[[BR]] |
| 3890 | ovfactor int |
| 3891 | ) |
| 3892 | |
| 3893 | To drop an overview constraint, use !DropOverviewConstraints. |
| 3894 | |
| 3895 | 1. !DropOverviewConstraints ( |
| 3896 | ovschema name,[[BR]] |
| 3897 | ovtable name,[[BR]] |
| 3898 | ovcolumn name |
| 3899 | ) |
| 3900 | |
| 3901 | 2. !DropOverviewConstraints ( |
| 3902 | ovtable name,[[BR]] |
| 3903 | ovcolumn name |
| 3904 | ) |
| 3905 | |
| 3906 | |
| 3907 | ~~Following the conversion of geometry_columns to a view in PostGIS, it is planned to do the same with raster_column and raster_overview for the raster part. Converting to a view has a number of advantages: |
| 3908 | |
| 3909 | ~~ * The raster_column view rows will always be in synch with the existing list raster columns. |
| 3910 | |
| 3911 | ~~ * All the information will be trustworthy because it will be enforced by constraints, so people can't change the band types etc... without changing the constraints. The raster_columns information will always be correct or null (if the constraint can not be applied). |
| 3912 | |
| 3913 | ~~ * Idem for the raster_overview table. |
| 3914 | |
| 3915 | ~~PostGIS is using the typmod feature of PostgreSQL to 'store' metadata about a table and then display them in the geometry_column view. Unfortunately the typmod is limited to XXX bytes and there is too much information to 'store' about a raster table to use typmod. PostGIS raster will therefore use another approach consisting of 'storing' metadata about a raster table as constraints on the table. A set of constraints will be applied to a raster table and those constraints will be read and displayed by the raster_column view. |
| 3916 | |
| 3917 | ~~The '''major changes concerning the raster_column table''' are as follow: |
| 3918 | |
| 3919 | ~~ * There will be a flexible !AddRasterConstraint() function trying to add a set of constraint on a table. As for any constraint, each constraint will be successfully applied only when all the rows of the table fulfill this constraint. The list of potential constraint applied by the C loader (using the !AddRasterConstraint function) and hence the list of column available in the raster_column view will be: srid int, samealignment boolean, scalex float8, scaley float8, width int, height int, numberofbands int, pixeltypes text[], nodatavalues float[] in addition to the 'r_table_catalog', 'r_table_schema', 'r_table_name' and 'r_column' columns. There is still discussion about if global extent as a geometry should be added to this list. Comments are welcome. |
| 3920 | |
| 3921 | ~~ * The raster_column view rows will be determined by querying the PostgreSQL catalog. A typical query exists for this. |
| 3922 | |
| 3923 | ~~ * The raster_column view will derive columns of metadata from the constraints applied to each table listed. When a constraint does not exist (because it could not be applied successfully to the table by !AddRasterconstraint()), the column corresponding to this constraint for this table will be null. |
| 3924 | |
| 3925 | ~~The '''major changes concerning the raster_overview table''' are as follow: |
| 3926 | |
| 3927 | ~~ * The raster_overview table will also be replaced by a raster_overview view. |
| 3928 | |
| 3929 | ~~ * We will provide a new function to support the creation of the raster_overview view and application of three additional constraints specific to overviews (!AddOverviewConstraints). These three additional constraints are: 'reference raster table oid', 'overview factor' and 'global extent'. Those constraints will be displayed by the raster_overview view as 'r_table_catalog', 'r_table_schema', 'r_table_name', 'r_column', 'overview_factor' and 'global_extent' in addition to the 'o_table_catalog', 'o_table_schema', 'o_table_name' and 'o_column' columns. |
| 3930 | |
| 3931 | ~~ * We will also provide a SQL function for creating overviews (ST_CreateOverview(schemaname text, tablename teat, columnname, factor int)). |
| 3932 | |
| 3933 | ~~ * The raster_overview view will NOT be created by default by the rtpostgis.sql script. It will be the responsibility of applications to use the !AddOverviewConstraints and ST_CreateOverview() function to create the raster_overviews view and create overviews. |
| 3934 | |
| 3935 | ~~The '''major changes concerning the raster2pgsql loader''' are as follow: |
| 3936 | |
| 3937 | ~~ * We are working on a new C importer to get rid of any Python, Numpy and Python GDAL Binding dependency which is a major obstacle to successful installation of PostGIS 2.0. |
| 3938 | |
| 3939 | ~~ * This new loader will attempt to add the constraints on the loaded table using the !AddRasterConstraint() function. There will be an option to NOT try to add the constraint for applications preferring to have no constraint applied to the tables over having a raster_column view filled with the proper information. |
| 3940 | |
| 3941 | ~~ * This new importer will NOT have any option to create the raster_overview view, nor to create overview tables as we leave this to the application. We also think that it is more important to be able to create overviews in SQL as a post loading process query so overviews can be updated/recreated when rasters tiles are edited, added or deleted. Application wishing to create overview can implement their own overview creation code or just use the future ST_CreateOverview() SQL function. |
| 3942 | |
| 3943 | ~~ * We will stop supporting the old raster2pgsql.py which was creating overview tables and filling the raster_overview table. It will be available in the script/python folder for people wishing to create overviews after a slight addaptation (to the new !AddRasterConstraints() and !AddOverviewConstraints() functions). |