| 409 | '''ST_Reclass(rast raster, VARIADIC argset reclassarg[]) -> raster''' |
| 410 | |
| 411 | 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. |
| 412 | |
| 413 | 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. |
| 414 | |
| 415 | 1. ST_Reclass(rast raster, VARIADIC argset reclassarg[]) -> raster |
| 416 | |
| 417 | rast: the raster whose specified bands are to be reclassified |
| 418 | |
| 419 | reclassarg: a new custom type defining the parameters required for reclassifying a band's pixel values. |
| 420 | |
| 421 | {{{ |
| 422 | CREATE TYPE reclassarg AS ( |
| 423 | |
| 424 | nband int, |
| 425 | |
| 426 | reclassexpr text, |
| 427 | |
| 428 | pixeltype text, |
| 429 | |
| 430 | nodata double |
| 431 | |
| 432 | ); |
| 433 | }}} |
| 434 | |
| 435 | nband: index of the band to reclass (1-based) |
| 436 | |
| 437 | 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. |
| 438 | |
| 439 | ''rangefrom:rangeto[, rangefrom:rangeto]'' |
| 440 | |
| 441 | {{{ |
| 442 | 0-100:0-10 |
| 443 | |
| 444 | 0-100:0-10, 101-1000:11-100 |
| 445 | |
| 446 | 0-100:0-10, 101-1000:11-100, 1001-10000:101-1000 |
| 447 | }}} |
| 448 | |
| 449 | In the last example above, the default evaluation of the ranges is |
| 450 | |
| 451 | {{{ |
| 452 | 0 <= x < 100 reclassified to 0 <= y <= 10 |
| 453 | |
| 454 | 101 <= x < 1000 reclassified to 11 <= y <= 100 |
| 455 | |
| 456 | 1001 <= x < 10000 reclassified to 101 <= y <= 1000 |
| 457 | }}} |
| 458 | |
| 459 | To change the evaluation of rangefrom, use square brackets and parentheses. |
| 460 | |
| 461 | {{{ |
| 462 | 1. [a-b] = a <= x <= b |
| 463 | |
| 464 | 2. (a-b] = a < x <= b |
| 465 | |
| 466 | 3. [a-b) = a <= x < b |
| 467 | |
| 468 | 4. (a-b) = a < x < b |
| 469 | }}} |
| 470 | |
| 471 | !#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. |
| 472 | |
| 473 | {{{ |
| 474 | [a-b = a <= x < b |
| 475 | |
| 476 | (a-b = a < x < b |
| 477 | |
| 478 | a-b] = a <= x <= b |
| 479 | |
| 480 | a-b) = a <= x < b |
| 481 | }}} |
| 482 | |
| 483 | pixeltype: the reclassified band's pixel type, e.g. 8BUI, 16BUI, 32BF |
| 484 | |
| 485 | 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. |
| 486 | |
| 487 | {{{ |
| 488 | ST_Reclass(rast, ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', NULL)); |
| 489 | |
| 490 | ST_Reclass(rast, ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001)); |
| 491 | |
| 492 | ST_Reclass(rast, |
| 493 | ROW(1, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001), |
| 494 | ROW(2, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001), |
| 495 | ROW(3, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001), |
| 496 | ROW(5, '0-100:0-10, 101-1000:11-100, 1001-10000:101-1000', '16BUI', 1001) |
| 497 | ) |
| 498 | }}} |
| 499 | |
| 500 | An expanded example |
| 501 | |
| 502 | {{{ |
| 503 | SELECT ST_Reclass( |
| 504 | ST_Band(rast, ARRAY[1,1,1]), |
| 505 | 1, LEAST(covmin, 0)::text || '-0:0,0-' || GREATEST(covmax, 0)::text || ':0-255', '8BUI', |
| 506 | 2, LEAST(covmin, 0)::text || '-0:200,0-' || GREATEST(covmax, 0)::text' || ':0-255','8BUI', |
| 507 | 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') |
| 508 | FROM mycoverage |
| 509 | }}} |
| 510 | |
| 511 | 2. ST_Reclass(rast raster, nband int, reclassexpr text, pixeltype text, nodata double) -> raster |
| 512 | |
| 513 | provides a method to process just one band of a raster |
| 514 | |
| 515 | {{{ |
| 516 | ST_Reclass(rast, 1, '0-100:0-10', '8BUI', 11) |
| 517 | }}} |
| 518 | |
| 519 | 3. ST_Reclass(rast raster, nband int, reclassexpr text, pixeltype text) -> raster |
| 520 | |
| 521 | nodata parameter removed so reclassified band will NOT have a nodata value set |
| 522 | |
| 523 | {{{ |
| 524 | ST_Reclass(rast, 1, '0-100:0-10', '8BUI') |
| 525 | }}} |
| 526 | |
| 527 | 4. ST_Reclass(rast raster, reclassexpr text, pixeltype text) -> raster |
| 528 | |
| 529 | nband parameter removed so reclassified band is assumed to be 1. nodata parameter removed so reclassified band has NO nodata value. |
| 530 | |
| 531 | {{{ |
| 532 | ST_Reclass(rast, '0-100:0-10', '8BUI') |
| 533 | }}} |
| 534 | |
| 535 | 5. ST_Reclass(rast raster, reclassexpr text, pixeltype text, nodata double) -> raster |
| 536 | |
| 537 | nband parameter removed so reclassified band is assumed to be 1 |
| 538 | |
| 539 | {{{ |
| 540 | ST_Reclass(rast, '0-100:0-10', '8BUI', 11) |
| 541 | }}} |
| 542 | |
| 543 | ---- |
| 544 | |