Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtiSV-0008M9-QO for pgsql-general@arkaria.postgresql.org; Fri, 11 Jan 2013 17:32:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TtiSV-0005Up-Ao for pgsql-general@arkaria.postgresql.org; Fri, 11 Jan 2013 17:31:59 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtiST-0005TI-Ej for pgsql-general@postgresql.org; Fri, 11 Jan 2013 17:31:57 +0000 Received: from mbx.knossos.net.nz ([202.160.48.10]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtiSO-0000s0-7z for pgsql-general@postgresql.org; Fri, 11 Jan 2013 17:31:56 +0000 Received: from [10.1.1.3] (60-234-150-59.bitstream.orcon.net.nz [60.234.150.59]) (authenticated bits=0) by mbx.knossos.net.nz (8.14.4/8.14.4) with ESMTP id r0BHVI6v031534 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 12 Jan 2013 06:31:26 +1300 Message-ID: <50F04C66.50209@archidevsys.co.nz> Date: Sat, 12 Jan 2013 06:31:18 +1300 From: Gavin Flower Organization: ArchiDevSys User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: Stefan Keller CC: Kevin Grittner , PostGIS Users Discussion , pgsql-general List Subject: Re: [postgis-users] Query with LIMIT but as random result set? References: <20130110202824.255780@gmx.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------030002060908010801060509" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org This is a multi-part message in MIME format. --------------030002060908010801060509 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Stefan, Please do not to post! :-) Here, we post replies at the end, so people can see the context before the new stuff. On 11/01/13 11:36, Stefan Keller wrote: > Hi Kevin > > No; I'm thinking about some query (or function) that selects random > points (POIs) with certain characteristics like decreasing density. I > didn't find much theory about how to *create* such random points. > > There seems to be more literature and implementation about measuring > geographic distribution (like in ArcGIS http://bit.ly/13lTFj9 ). > > Under "radial distribution function" I understand a function which > describes how density varies depending on the distance from a > reference point (= the user). > > Yours, Stefan > > > 2013/1/10 Kevin Grittner : >> Stefan Keller wrote: >> >>> "... ORDER BY random() LIMIT 10;" works ok. >>> >>> But with the following option it gets more tricky assume: >>>> And as an option the (limited) resultset should be spatially >>>> distributed (not clustered). >>> I'm thinking about some radial spatial distribution function. >> So, you explicitly *don't* want a random selection? By "spatially >> distributed" you mean that if you have already chosen one >> particular location, other locations which are close to it should >> be less probable (or impossible) to include in the limited result >> set? How would you define the desired result? The one with the >> highest best solution to the "traveling salesman" problem? >> >> -Kevin > Note that even for an even probability distribution,you have to be careful. There are at least 2 ways to distribute points in a circle, both are valid in different contexts. (1) Select (x,y) in a square containing the circle, through away any points outside the circle. This has an even probability density per unit area of the circle. (2) Select (theta, r) at random. This has a greater density of points at the centre reducing lineraly towards the circumference. I think something like the second fits your situation. DROP TABLE IF EXISTS ranpoint; CREATE TABLE ranpoint ( id int, theta float, r float ); -- theta in radians -- for radius = 100 INSERT INTO ranpoint (id, theta, r) VALUES (generate_series(1, 10), pi() * random(), 100 * random()); TABLE ranpoint; Cheers, Gavin --------------030002060908010801060509 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mbx.knossos.net.nz id r0BHVI6v031534
Hi Stefan,

Please do not to post!=C2=A0 :-)
Here, we post replies at the end, so people can see the context before the new stuff.


On 11/01/13 11:36, Stefan Keller wrote:
Hi Kevin

No; I'm thinking about some query (or function) that selects random
points (POIs) with certain characteristics like decreasing density. I
didn't find much theory about how to *create* such random points.

There seems to be more literature and implementation about measuring
geographic distribution (like in ArcGIS http://bit.ly/13lTFj9 ).

Under "radial distribution function" I understand a function which
describes how density varies depending on the distance from a
reference point (=3D the user).

Yours, Stefan


2013/1/10 Kevin Grittner <kgrittn@mail.com>:
Stefan Keller wrote:

"... ORDER BY random() LIMIT 10;" works ok.

But with the following option it gets more tricky assume:
And as an option the (limited) resultset shoul=
d be spatially
distributed (not clustered).
I'm thinking about some radial spatial distribution function.
So, you explicitly *don't* want a random selection?  By "spatially
distributed" you mean that if you have already chosen one
particular location, other locations which are close to it should
be less probable (or impossible) to include in the limited result
set? How would you define the desired result? The one with the
highest best solution to the "traveling salesman" problem?

-Kevin

Note that even for an even probability distribution,you have to be careful.

There are at least 2 ways to distribute points in a circle, both are valid in different contexts.

(1)=C2=A0 Select (x,y) in a square containing the circle, through awa= y any points outside the circle.=C2=A0 This has an even probability den= sity per unit area of the circle.

(2) Select (theta, r) at random.=C2=A0 This has a greater density of points at the centre reducing lineraly towards the circumference.

I think something like the second fits your situation.

DROP TABLE IF EXISTS ranpoint;

CREATE TABLE ranpoint
(
=C2=A0=C2=A0=C2=A0 id=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int,=
=C2=A0=C2=A0=C2=A0 theta=C2=A0=C2=A0 float,
=C2=A0=C2=A0=C2=A0 r=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= float
);

-- theta in radians
-- for radius =3D 100

INSERT INTO ranpoint
=C2=A0=C2=A0=C2=A0 (id, theta, r)
VALUES
=C2=A0=C2=A0=C2=A0 (generate_series(1, 10), pi() * rando= m(), 100 * random());
=C2=A0=C2=A0=C2=A0

TABLE ranpoint;



Cheers,
Gavin


--------------030002060908010801060509--