I solved my own question a couple weeks ago on how to create percentile breaks in QGIS.
Creating percentile class breaks in vector data QGIS using numpy.percentile
However, this code is unbelievably slow. Does anyone have any recommendations for speeding things up? See code below:
case
when ag_ppm <= q1(ag_ppm)
then '<25th: ' || minimum("ag_ppm") || ' - ' || q1(ag_ppm)
when ag_ppm < median(ag_ppm) AND ag_ppm > q1(ag_ppm)
then '25th to 50th: ' || (q1(ag_ppm)+0.001) || ' - ' || median(ag_ppm)
when ag_ppm <= q3(ag_ppm) AND ag_ppm > median(ag_ppm)
then '50th to 75th: ' || (median(ag_ppm)+0.001) || ' - ' || q3(ag_ppm)
when ag_ppm <= percentile(90,array_agg(ag_ppm,project)) AND ag_ppm > q3(ag_ppm)
then '75th to 90th: ' || (q3(ag_ppm)+0.001) || ' - ' || percentile(90,array_agg(ag_ppm,project))
when ag_ppm <= percentile(95,array_agg(ag_ppm,project)) AND ag_ppm > percentile(90,ag_ppm)
then '90th to 95th: ' || (percentile(90,array_agg(ag_ppm,project))+0.001) || ' - ' || percentile(95,array_agg(ag_ppm,project))
when ag_ppm <= percentile(98,ag_ppm) AND ag_ppm > percentile(95,ag_ppm)
then '95th to 98th: ' || (percentile(95,array_agg(ag_ppm,project))+0.001) || ' - ' || percentile(98,array_agg(ag_ppm,project))
when ag_ppm <= maximum(ag_ppm) AND ag_ppm > percentile(98,array_agg(ag_ppm,project))
then '>98th: ' || (percentile(98,array_agg(ag_ppm,project))+0.001) || ' - ' || maximum(ag_ppm)
else 'NULL'
end
case when
to severalif
statements, then you compute and store the variables that are reused (ex: start by computingvalq1 = q1(ag_ppm)
and then usevalq1
in the comparisons). It should cut the processing time in half at least. Then you can reorder the comparisons, moving away from the median (most likely bin if you have a normal distribution) to avoid computing/comparing stats of outliers firstag_ppm
to static values only so it will be much faster