| 822 | |
| 823 | ---- |
| 824 | |
| 825 | '''ST_Histogram(raster, nband) -> set of records'''[[BR]] |
| 826 | ST_Histogram and ST_ApproxHistogram provide methods to determine a raster's data distribution. |
| 827 | |
| 828 | The return of ST_Histogram and ST_ApproxHistogram is a set of records where each record is (min, max, count, proportion). |
| 829 | |
| 830 | ST_Histogram has the following variations. |
| 831 | |
| 832 | 1. ST_Histogram(rast raster, nband int, hasnodata boolean, bins int, width double precision[], right boolean) -> set of records |
| 833 | |
| 834 | returns set of records of four columns (min, max, count, proportion) |
| 835 | |
| 836 | nband: index of band to process on |
| 837 | |
| 838 | hasnodata: if FALSE, any pixel who's value is nodata is ignored. |
| 839 | |
| 840 | 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. |
| 841 | |
| 842 | http://en.wikipedia.org/wiki/Histogram#Mathematical_definition |
| 843 | |
| 844 | 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]. |
| 845 | |
| 846 | 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]. |
| 847 | |
| 848 | {{{ |
| 849 | ST_Histogram(rast, 2, FALSE, NULL, NULL, FALSE) |
| 850 | |
| 851 | ST_Histogram(rast, 1, TRUE, 100, NULL, FALSE) |
| 852 | |
| 853 | ST_Histogram(rast, 2, FALSE, NULL, ARRAY[100, 50], FALSE) |
| 854 | |
| 855 | ST_Histogram(rast, 2, FALSE, 9, ARRAY[1000], TRUE) |
| 856 | |
| 857 | ST_Histogram(rast, 2, FALSE, 20, ARRAY[100, 200, 300], TRUE) |
| 858 | }}} |
| 859 | |
| 860 | 2. ST_Histogram(rast raster, nband int, hasnodata boolean, bins int, right boolean) -> set of records |
| 861 | |
| 862 | parameter "width" is not specified thus resulting in all bins having the same widths |
| 863 | |
| 864 | {{{ |
| 865 | ST_Histogram(rast, 2, FALSE, 5, FALSE) |
| 866 | }}} |
| 867 | |
| 868 | 3. ST_Histogram(rast raster, nband int, hasnodata boolean, bins int) -> set of records |
| 869 | |
| 870 | the parameter "right" is removed and assumed to be FALSE |
| 871 | |
| 872 | {{{ |
| 873 | ST_Histogram(rast, 2, FALSE, 5) |
| 874 | }}} |
| 875 | |
| 876 | 4. ST_Histogram(rast raster, nband int, hasnodata boolean) -> set of records |
| 877 | |
| 878 | the parameter "bins" is removed and set to NULL. The function will compute the number of bins to use |
| 879 | |
| 880 | 5. ST_Histogram(rast raster, nband int) -> set of records |
| 881 | |
| 882 | parameter "hasnodata" is removed and assumed to be FALSE |
| 883 | |
| 884 | 6. ST_Histogram(rast raster) -> set of records |
| 885 | |
| 886 | assumes that nband is 1. |
| 887 | |
| 888 | 7. ST_Histogram(rast raster, nband int, bins int, width double precision[], right boolean) -> set of records |
| 889 | |
| 890 | hasnodata is assumed to be FALSE |
| 891 | |
| 892 | 8. ST_Histogram(rast raster, nband int, bins int, right boolean) -> set of records |
| 893 | |
| 894 | all bins will have equal widths |
| 895 | |
| 896 | 9. ST_Histogram(rast raster, nband int, bins int) -> set of records |
| 897 | |
| 898 | right is assumed to be FALSE |
| 899 | |
| 900 | ST_ApproxHistogram should have the following variations. |
| 901 | |
| 902 | 1. ST_ApproxHistogram(rast raster, nband int, hasnodata boolean, sample_percent double precision, bins int, width double precision[], right boolean) -> set of record |
| 903 | |
| 904 | sample_percent: a value between 0 and 1 indicating the percentage of the raster band's pixels to consider when generating the histogram. |
| 905 | |
| 906 | {{{ |
| 907 | ST_Histogram(rast, 2, FALSE, 0.1, NULL, NULL, FALSE) |
| 908 | |
| 909 | ST_Histogram(rast, 1, TRUE, 1, 100, NULL, FALSE) |
| 910 | |
| 911 | ST_Histogram(rast, 2, FALSE, 0.2, NULL, ARRAY[100, 50], FALSE) |
| 912 | |
| 913 | ST_Histogram(rast, 2, FALSE, 0.25, 9, ARRAY[1000], TRUE) |
| 914 | |
| 915 | ST_Histogram(rast, 2, FALSE, 0.05, 20, ARRAY[100, 200, 300], TRUE) |
| 916 | }}} |
| 917 | |
| 918 | 2. ST_ApproxHistogram(rast raster, nband int, hasnodata boolean, sample_percent double precision, bins int, right boolean) -> set of records |
| 919 | |
| 920 | parameter "width" is not specified thus resulting in all bins having the same widths |
| 921 | |
| 922 | 3. ST_ApproxHistogram(rast raster, nband int, hasnodata boolean, sample_percent double precision, bins int) -> set of records |
| 923 | |
| 924 | the parameter "right" is removed and assumed to be FALSE |
| 925 | |
| 926 | {{{ |
| 927 | ST_ApproxHistogram(rast, 2, FALSE, 5) |
| 928 | }}} |
| 929 | |
| 930 | 4. ST_ApproxHistogram(rast raster, nband int, hasnodata boolean, sample_percent double precision) -> set of records |
| 931 | |
| 932 | the parameter "bins" is removed and set to NULL so that function can compute the number of bins to use |
| 933 | |
| 934 | 5. ST_ApproxHistogram(rast raster, nband int, sample_percent double precision) -> set of records |
| 935 | |
| 936 | parameter "hasnodata" is removed and assumed to be FALSE |
| 937 | |
| 938 | 6. ST_ApproxHistogram(rast raster, nband int) -> set of records |
| 939 | |
| 940 | assumes that sample_percent is 0.1 |
| 941 | |
| 942 | 7. ST_ApproxHistogram(rast raster, sample_percent double_precision) -> set of records |
| 943 | |
| 944 | assumes that nband is 1 |
| 945 | |
| 946 | 8. ST_ApproxHistogram(rast raster) -> set of records |
| 947 | |
| 948 | assumes that nband is 1 and sample_percent is 0.1 |
| 949 | |
| 950 | 9. ST_ApproxHistogram(rast raster, nband int, sample_percent double precision, bins int, width double precision[], right boolean) -> set of records |
| 951 | |
| 952 | hasnodata is assumed to be FALSE |
| 953 | |
| 954 | 10. ST_ApproxHistogram(rast raster, nband int, sample_percent double precision, bins int, right boolean) -> set of records |
| 955 | |
| 956 | all bins will have equal widths |
| 957 | |
| 958 | 11. ST_ApproxHistogram(rast raster, nband int, sample_percent double precision, bins int) -> set of records |
| 959 | |
| 960 | right is assumed to be FALSE |