by Abel Vázquez
A simple function that brings to PostGIS the classic ESRI's Kernel Density function described at
https://pro.arcgis.com/en/pro-app/tool-reference/spatial-analyst/how-kernel-density-works.htm
and first translated into usable SQL by https://github.com/arredond
NOTE: it only works with points!
How to use it:
WITH
a AS(
	SELECT 
        array_agg(uniqueid) as ids, 
        array_agg(geom) as geoms 
    FROM 
        mydataset
)
SELECT
    b.*
FROM
    a,
    kernel_density(a.ids, a.geoms) b
great
based on https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-statistics/h-how-standard-distance-spatial-statistic-works.htm
i think you should modify it with this
SELECT sqrt( sum((ST_X(g)-ST_X(mc))^2) / c + sum((ST_Y(g)-ST_Y(mc))^2) / c ) ) as standard_distance FROM dist