pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gavin Flower <GavinFlower@archidevsys.co.nz>
To: Stefan Keller <sfkeller@gmail.com>
Cc: Kevin Grittner <kgrittn@mail.com>
Cc: PostGIS Users Discussion <postgis-users@lists.osgeo.org>
Cc: pgsql-general List <pgsql-general@postgresql.org>
Subject: Re: [postgis-users] Query with LIMIT but as random result set?
Date: Sat, 12 Jan 2013 06:31:18 +1300
Message-ID: <50F04C66.50209@archidevsys.co.nz> (raw)
In-Reply-To: <CAFcOn29kUGYvDo3HoTs1YcJj_WugPXpccHG+pf+WLHiopU95PQ@mail.gmail.com>
References: <20130110202824.255780@gmx.com>
	<CAFcOn29kUGYvDo3HoTs1YcJj_WugPXpccHG+pf+WLHiopU95PQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>

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 <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 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

view thread (8+ messages)  latest in thread

Message-ID: <50F04C66.50209@archidevsys.co.nz>
Permalink:  ../50F04C66.50209@archidevsys.co.nz/
Also on:    postgresql.org/message-id/50F04C66.50209@archidevsys.co.nz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: GavinFlower@archidevsys.co.nz, sfkeller@gmail.com, kgrittn@mail.com, postgis-users@lists.osgeo.org
  Subject: Re: [postgis-users] Query with LIMIT but as random result set?
  In-Reply-To: <50F04C66.50209@archidevsys.co.nz>
  References: <20130110202824.255780@gmx.com> <CAFcOn29kUGYvDo3HoTs1YcJj_WugPXpccHG+pf+WLHiopU95PQ@mail.gmail.com> <50F04C66.50209@archidevsys.co.nz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox