[postgis-tickets] [PostGIS] #2131: Replace regress_lots_of_points.sql data with generated query
PostGIS
trac at osgeo.org
Sat Dec 16 14:00:04 PST 2017
#2131: Replace regress_lots_of_points.sql data with generated query
--------------------------+-----------------------------
Reporter: strk | Owner: pramsey
Type: enhancement | Status: closed
Priority: low | Milestone: PostGIS Fund Me
Component: postgis | Version: trunk
Resolution: wontfix | Keywords:
--------------------------+-----------------------------
Comment (by Mike Toews):
How about we make a deterministic pseudo-random point sequence, based on
[https://en.wikipedia.org/wiki/Linear-feedback_shift_register a linear-
feedback shift register]. This one should generate a uniform distribution
of points between [0, 1000] in both x and y directions. And because it's
based on a `bit(16)` postgres type, I'd expect it to be portable.
{{{
CREATE OR REPLACE FUNCTION
lfsr_point(len integer, start_state integer DEFAULT 6342)
RETURNS SETOF geometry AS
$$
DECLARE
lfsr bit(16);
bt bit(16);
x float8;
y float8;
BEGIN
lfsr := start_state::bit(16);
FOR i IN 1..$1 LOOP
bt := ((lfsr >> 0) # (lfsr >> 2) # (lfsr >> 3) # (lfsr >> 5)) &
(1::bit(16));
lfsr := (lfsr >> 1) | (bt << 15);
x := round(lfsr::integer::numeric / 65536.0 * 1000, 4);
bt := ((lfsr >> 0) # (lfsr >> 2) # (lfsr >> 3) # (lfsr >> 5)) &
(1::bit(16));
lfsr := (lfsr >> 1) | (bt << 15);
y := round(lfsr::integer::numeric / 65536.0 * 1000, 4);
RETURN NEXT ST_MakePoint(x, y);
END LOOP;
RETURN;
END;$$ LANGUAGE plpgsql;
}}}
And then generate the "random" points:
{{{
DROP TABLE IF EXISTS test;
CREATE TABLE test (
"num" serial PRIMARY KEY,
"the_geom" geometry
);
INSERT INTO test(the_geom)
SELECT lfsr_point(50000);
}}}
This is all fine an dandy, until I looked at the points:
https://imgur.com/FgMjyc4
so it just needs a bit of fine tuning...
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/2131#comment:5>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list