pgLatLon
view create_test_db.data.sql @ 46:3cbce515387f
Added safety margins for distance calculation on index lookups (fixes bug that caused nearest-neighbor search to fail in certain cases); Improved "fair_distance" function
author | jbe |
---|---|
date | Mon Oct 31 13:06:31 2016 +0100 (2016-10-31) |
parents | 684a78d2f9f0 |
children |
line source
2 CREATE OR REPLACE FUNCTION tmp_three_points()
3 RETURNS epoint[]
4 LANGUAGE plpgsql VOLATILE AS $$
5 DECLARE
6 p1 epoint;
7 p2 epoint;
8 p3 epoint;
9 BEGIN
10 p1 := epoint((asin(2*random()-1) / pi()) * 180, (2*random()-1) * 180);
11 p2 := epoint(latitude(p1) + (2*random()-1), longitude(p1) + cos(latitude(p1)/180*pi()) * (2*random()-1));
12 p3 := epoint(latitude(p1) + (2*random()-1), longitude(p1) + cos(latitude(p1)/180*pi()) * (2*random()-1));
13 RETURN ARRAY[p1, p2, p3];
14 END;
15 $$;
17 INSERT INTO "test" ("location", "surrounding", "multipoint", "triangle", "votes") SELECT
18 epoint((asin(2*random()-1) / pi()) * 180, (2*random()-1) * 180),
19 ecircle((asin(2*random()-1) / pi()) * 180, (2*random()-1) * 180, -ln(1-random()) * 1000),
20 ecluster_create_multipoint(tmp_three_points()),
21 ecluster_create_polygon(tmp_three_points()),
22 floor(random()*101)
23 FROM generate_series(1, 10000);
25 DROP FUNCTION tmp_three_points();