CREATE or replace VIEW vw_point_geohash_diffs AS
SELECT *, abs(orig_x-x) diff_x, abs(orig_y-y) diff_y
FROM (
SELECT orig_x, round(st_x(pt),6) x, orig_y, round(st_y(pt),6) y
-- the 6 is "6 decimal digits at LatLong coordinates"
FROM (
SELECT osm_id, st_centroid(ST_GeomFromGeoHash( st_geohash(way,14)
-- here ...9, 10, 11, 12, 13, 14...
)) pt,
round(st_x(way),6) orig_x, round(st_y(way),6) orig_y
FROM planet_osm_point
) t1
) t2;
-- Precision checks:
SELECT n, sum_x, sum_y, round(avg_diffs/2.0,10) as avg_diffs, n_diffs_not0,
round(100.0*n_diffs_not0/n,2)||'%' as perc,
round(avg_diffs_not0/2.0,10) as avg_diffs_not0
FROM (
SELECT count(*) n, sum(diff_x) sum_x, sum(diff_y) sum_y,
avg(diff_x+diff_y) avg_diffs,
count(*) FILTER (WHERE diff_x>0 OR diff_y>0) n_diffs_not0,
avg(diff_x+diff_y) FILTER (WHERE diff_x>0 OR diff_y>0) avg_diffs_not0
FROM vw_point_geohash_diffs
) t;
geohash_len| avg_diffs | n_diffs_not0 | perc | avg_diffs_not0
-----------|--------------|--------------|---------|--------
10 | 0.0000020377 | 1786453 | 97.4% | 0.0000020912
11 | 0.0000003716 | 1111317 | 60.6% | 0.0000006130
12 | 0.0000000756 | 267843 | 14.6% | 0.0000005173
13 | 0.0000000489 | 174916 | 9.5% | 0.0000005127
14 | 0.0000000493 | 176324 | 9.6% | 0.0000005128
Running all with n=1833326 points (OSM Brazil).
The main problem for "reversible precision" seems the float arithmetic error at Geohash-14 or more. Same problem when we change round from 6
decimal places of LatLong to 5
places,
geohash_len| avg_diffs | n_diffs_not0 | perc | avg_diffs_not0
-----------|--------------|--------------|-------|--------
10 | 0.0000020377 | 1786453 | 97.4% | 0.0000020912
11 | 0.0000003716 | 1111317 | 60.6% | 0.0000006130
12 | 0.0000000756 | 267843 | 14.6% | 0.0000005173
13 | 0.0000000489 | 174916 | 9.5% | 0.0000005127
14 | 0.0000000493 | 176324 | 9.6% | 0.0000005128
... seems internal (floating point?) problems after Geohash 13 digits.