Re: [postgis-users] Dot Density idea

2011-05-27 Thread strk
On Fri, May 27, 2011 at 10:53:58AM -0600, John Abraham wrote:

> create or replace view dot_cnt as 
> select the_geom, polygon_id, (quantity_column/100)::integer as numpoints 
> from original_data;
> 
> select dot_density('dot_cnt',
> 'the_geom',
> 'polygon_id',
> 'numpoints');
> 
> alter table dp rename to save_it_for_future_use;
> 
> And here are the functions:

It'd be nice if you could make your function accessible on the postgis
wiki, so it's easier to find it.

--strk;

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] Dot Density idea

2011-05-27 Thread John Abraham
Just to follow up on this, here is the code we (Abdel-Rahman M. Muhsen and I) 
finally got around to writing.  We found a function called randompoint which 
just creates random points within the bounding box of the geometry from 
Alexandre Sorokine. 
http://sorokine.blogspot.com/2011/05/postgis-function-for-random-point.html (I 
see he's updated it 4 days ago to be better for multi-polygons!  We don't have 
his updates yet.)

Then we wrote a function called dot_density which creates a table called dp 
which has a point geometry for each point in the polygon.  If there are 
negative numbers in the point count, it creates the positive number of points 
but flags them in another column. (We often plot dot density maps with red dots 
for decreases and blue dots for increases.)

There are still a few improvements we'll likely make.  We'd like to create the 
geometry column using the addgeometrycolumn function.  We'd like to specify the 
output table name as a function parameter.  There was also a good idea to use 
Halton sequences or other "pseudo-random" sequences, instead of truly random 
points, and Martin Davis implemented a few of the other "pseudo-random" ideas 
in JTS 
http://lin-ear-th-inking.blogspot.com/2010/05/more-random-points-in-jts.html .  
Other suggestions are welcomed.

This is how we typically use it:

create or replace view dot_cnt as 
select the_geom, polygon_id, (quantity_column/100)::integer as numpoints 
from original_data;

select dot_density('dot_cnt',
'the_geom',
'polygon_id',
'numpoints');

alter table dp rename to save_it_for_future_use;

And here are the functions:


CREATE OR REPLACE FUNCTION randompoint(geom geometry)
  RETURNS geometry AS
-- from Alexandre Sorokine
$BODY$
DECLARE
 maxiter INTEGER := 1000;
 i INTEGER := 0;
 x0 DOUBLE PRECISION;
 dx DOUBLE PRECISION;
 y0 DOUBLE PRECISION;
 dy DOUBLE PRECISION;
 xp DOUBLE PRECISION;
 yp DOUBLE PRECISION;
 rpoint Geometry;
BEGIN
 -- find envelope
 x0 = ST_XMin(geom);
 dx = (ST_XMax(geom) - x0);
 y0 = ST_YMin(geom);
 dy = (ST_YMax(geom) - y0);
 
 WHILE i < maxiter LOOP
  i = i + 1;
  xp = x0 + dx * random();
  yp = y0 + dy * random();
  rpoint = ST_SetSRID( ST_MakePoint( xp, yp ), ST_SRID(geom) );
  EXIT WHEN ST_Within( rpoint, geom );
 END LOOP;
 
 IF i > maxiter THEN
  RAISE NOTICE 'number of interations exceeded max';
 END IF; 
 
 RETURN rpoint;
END; 
$BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100;
ALTER FUNCTION randompoint(geometry) OWNER TO "usrPostgres";

-- Function: dot_density(text, text, text, text)

CREATE OR REPLACE FUNCTION dot_density(geom_table text, geom_col text, zone_col 
text, num_of_points_col text)
  RETURNS SETOF record AS
$BODY$
DECLARE 
 counter integer:=0;
 tazrec record;
 pointrec record;
 result record;

 num_points integer:=0;
 np integer :=0; 
begin

DROP sequence if exists randpnt_id;
CREATE sequence randpnt_id;

DROP TABLE IF EXISTS dp;
CREATE TABLE dp
(
  gid integer PRIMARY KEY,
  ser integer,
  "zone" integer,
  decrease_or_increase integer,
  the_geom geometry
); 

for tazrec in EXECUTE 'SELECT ' || zone_col || ' as geom_col , ' || zone_col || 
' as zone_col, '|| num_of_points_col || ' as num_of_points_col FROM ' || 
geom_table Loop
 RAISE INFO 'Treating zone: %' , tazrec.zone_col;
 num_points = tazrec.num_of_points_col;

 IF num_points !=0 THEN np := num_points/abs(num_points);
 ELSE np=0;
 END IF;
 
 

 EXECUTE 'INSERT INTO dp SELECT nextval(''randpnt_id'') as gid, 
generate_series, '|| tazrec.zone_col ||  ', ' || np ||' , randompoint(the_geom) 
FROM ' || geom_table || ', generate_series(1, '|| abs(num_points) ||') WHERE 
'|| zone_col || '='|| tazrec.zone_col ;
  

END LOOP;

RETURN ; 
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION dot_density(text, text, text, text) OWNER TO postgres;


On 2010-05-06, at 3:10 AM, strk wrote:

> ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
> function indeed. Sounds like a good job for GEOS/JTS.
> 
> --strk;
> 
> On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
>> One of the things I miss about using ESRI's GIS is the ability to do 
>> dot-density maps.  Within a polygon, the number of dots is proportional to a 
>> value, and the dots are randomly placed.  I find it useful to be able to 
>> present several data values at once (e.g. blue dots for population, red dots 
>> for employment).  
>> 
>> I also find that it is a more intuitive way of scaling for zone size than 
>> dividing the value by the area of the zone.  That is, the count of the dots 
>> represents the actual number, but the density of the dots represents the 
>> density of the number.  So I don't have to decide whether to divide the 
>> value by the area of the polygon to plot density: both the absolute number 
>> and the density are easily visible.
>> 
>> Since my open-source GIS viewing systems (mostly QGIS and Mapserver) won't 
>> plot dot-density, I've done without.
>> 
>> But today I realized that I can build these on the 

Re: [postgis-users] Dot Density idea

2010-06-15 Thread Martin Davis

That's a neat idea alright.

I'm not sure that calling it a "repulsive dots pattern" gets the right 
idea across though...   8^)


Francis Markham wrote:

Looks great Martin.

Another way of generating non-clumpy random dots without a grid-like pattern
is to use a "repulsive" function.  See for example,
http://www.statisticsblog.com/2010/06/repulsive-dots-pattern-the-difference-of-distance/

Cheers,

Francis



On 7 May 2010 08:11, Martin Davis  wrote:

  

Check out this blog post for some images of different kinds of random point
fields:


http://lin-ear-th-inking.blogspot.com/2010/05/more-random-points-in-jts.html


Martin Davis wrote:



Sounds like it could work - with maybe a bit of fiddling to deal with
cases where the grid cells overlapped the polygon only slightly?
Random perturbation by cell radius can still result in some points being
very close together.  (And I think this would also be an issue where only a
small part of each grid cell overlapped the polygon).  This may or may not
be desirable.  Perhaps a further check could be made to reduce the radius
for points where this occurs.   Or maybe some sort of simulated annealing
process could be use to push the points into a more even distribution.

M

Paul Ramsey wrote:

  

Even-yet-random :) nice requirement. How about just starting with a
regular grid and then perturbing the elements randomly with a radius
of a cell size? You can use the area of the polygon and number of
needed points to calculate the appropriate cell size and go from
there.

P

On Thu, May 6, 2010 at 10:28 AM, Martin Davis 
wrote:




Good point about the need for even distribution of the points. That
seems
like a whole lot harder to code than simply randomly placing points in a
polygon.  Does anyone have any pointers to algorithms for producing this
effect?

George Silva wrote:


  

The really big problem with dot density is that dots can overlap
themselves,
masking the real number, so if anything will be developed in this area,
the
points should be

A) evenly distributed
or
B) randomly distributed, but with some sort of "colision" tests, so
there
is
no or little overlap.

This is a interesting idea, especially if we could make a materialized
view
with those points, which could be added to GIS software for
presentation.

George

On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley <
ssuffic...@rov.sbcounty.gov> wrote:






Looks nasty, but it might work:

select
st_line_interpolate_point(
 st_intersection(
 the_geom,
 st_makeline(
 st_pointn(st_exteriorring(the_geom), (rand1.rand
*
st_npoints(st_exteriorring(the_geom)))::int),
 st_pointn(st_exteriorring(the_geom), (rand2.rand
*
st_npoints(st_exteriorring(the_geom)))::int)
 )
 )
 ,rand3.rand
)
from insert_your_table_name_here,
(select random() as rand, generate_series(1,1000) as point_number) as
rand1
JOIN (select random() as rand, generate_series(1,1000) as
point_number)
as
rand2
 ON rand1.point_number = rand2.point_number
JOIN (select random() as rand, generate_series(1,1000) as
point_number)
as
rand3
 ON rand2.point_number = rand3.point_number
WHERE st_geometrytype(
 st_intersection(
 the_geom,
 st_makeline(
 st_pointn(st_exteriorring(the_geom), (rand1.rand
*
st_npoints(st_exteriorring(the_geom)))::int),
 st_pointn(st_exteriorring(the_geom), (rand2.rand
*
st_npoints(st_exteriorring(the_geom)))::int)
 )
 )
) = 'ST_LineString'
AND oid = 5030 /* Enter your own OID here */
limit 100






  

-Original Message-
From: postgis-users-boun...@postgis.refractions.net
[mailto:postgis-users-boun...@postgis.refractions.net] On
Behalf Of Martin Davis
Sent: Thursday, May 06, 2010 8:56 AM
To: John Abraham; postgis-users@postgis.refractions.net; Martin
Davis
Subject: Re: [postgis-users] Dot Density idea


I was thinking the same thing!

strk wrote:





ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
function indeed. Sounds like a good job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:




  

One of the things I miss about using ESRI's GIS is the





ability to do
  




dot-density maps.  Within a polygon, the number of dots is
  




proportional to a value, and the dots are randomly placed.  I
  

find it useful to be able to present several data values at
once (e.g. blue dots for population, red dots for employment).





I also find that it is a more intuitive way of scaling for
  




zone size
  




than dividing the value by the area of the zone.  

Re: [postgis-users] Dot Density idea

2010-06-14 Thread Francis Markham
Looks great Martin.

Another way of generating non-clumpy random dots without a grid-like pattern
is to use a "repulsive" function.  See for example,
http://www.statisticsblog.com/2010/06/repulsive-dots-pattern-the-difference-of-distance/

Cheers,

Francis



On 7 May 2010 08:11, Martin Davis  wrote:

> Check out this blog post for some images of different kinds of random point
> fields:
>
>
> http://lin-ear-th-inking.blogspot.com/2010/05/more-random-points-in-jts.html
>
>
> Martin Davis wrote:
>
>> Sounds like it could work - with maybe a bit of fiddling to deal with
>> cases where the grid cells overlapped the polygon only slightly?
>> Random perturbation by cell radius can still result in some points being
>> very close together.  (And I think this would also be an issue where only a
>> small part of each grid cell overlapped the polygon).  This may or may not
>> be desirable.  Perhaps a further check could be made to reduce the radius
>> for points where this occurs.   Or maybe some sort of simulated annealing
>> process could be use to push the points into a more even distribution.
>>
>> M
>>
>> Paul Ramsey wrote:
>>
>>> Even-yet-random :) nice requirement. How about just starting with a
>>> regular grid and then perturbing the elements randomly with a radius
>>> of a cell size? You can use the area of the polygon and number of
>>> needed points to calculate the appropriate cell size and go from
>>> there.
>>>
>>> P
>>>
>>> On Thu, May 6, 2010 at 10:28 AM, Martin Davis 
>>> wrote:
>>>
>>>
>>>> Good point about the need for even distribution of the points. That
>>>> seems
>>>> like a whole lot harder to code than simply randomly placing points in a
>>>> polygon.  Does anyone have any pointers to algorithms for producing this
>>>> effect?
>>>>
>>>> George Silva wrote:
>>>>
>>>>
>>>>> The really big problem with dot density is that dots can overlap
>>>>> themselves,
>>>>> masking the real number, so if anything will be developed in this area,
>>>>> the
>>>>> points should be
>>>>>
>>>>> A) evenly distributed
>>>>> or
>>>>> B) randomly distributed, but with some sort of "colision" tests, so
>>>>> there
>>>>> is
>>>>> no or little overlap.
>>>>>
>>>>> This is a interesting idea, especially if we could make a materialized
>>>>> view
>>>>> with those points, which could be added to GIS software for
>>>>> presentation.
>>>>>
>>>>> George
>>>>>
>>>>> On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley <
>>>>> ssuffic...@rov.sbcounty.gov> wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> Looks nasty, but it might work:
>>>>>>
>>>>>> select
>>>>>> st_line_interpolate_point(
>>>>>>  st_intersection(
>>>>>>  the_geom,
>>>>>>  st_makeline(
>>>>>>  st_pointn(st_exteriorring(the_geom), (rand1.rand
>>>>>> *
>>>>>> st_npoints(st_exteriorring(the_geom)))::int),
>>>>>>  st_pointn(st_exteriorring(the_geom), (rand2.rand
>>>>>> *
>>>>>> st_npoints(st_exteriorring(the_geom)))::int)
>>>>>>  )
>>>>>>  )
>>>>>>  ,rand3.rand
>>>>>> )
>>>>>> from insert_your_table_name_here,
>>>>>> (select random() as rand, generate_series(1,1000) as point_number) as
>>>>>> rand1
>>>>>> JOIN (select random() as rand, generate_series(1,1000) as
>>>>>> point_number)
>>>>>> as
>>>>>> rand2
>>>>>>  ON rand1.point_number = rand2.point_number
>>>>>> JOIN (select random() as rand, generate_series(1,1000) as
>>>>>> point_number)
>>>>>> as
>>>>>> rand3
>>>>>>  ON rand2.point_number = rand3.point_number
>>>>>> WHERE st_geometrytype(
>>>>>>  st_intersection(
>>>>>>  the_geom,
>>>>>>  st_makeline(
>>>>>>

Re: [postgis-users] Dot Density idea

2010-05-09 Thread Andrew Sheedy
gt;>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> Looks nasty, but it might work:
>>>>>>>>
>>>>>>>> select
>>>>>>>> st_line_interpolate_point(
>>>>>>>>  st_intersection(
>>>>>>>>  the_geom,
>>>>>>>>  st_makeline(
>>>>>>>>  st_pointn(st_exteriorring(the_geom),
>>>>>>>> (rand1.rand *
>>>>>>>> st_npoints(st_exteriorring(the_geom)))::int),
>>>>>>>>  st_pointn(st_exteriorring(the_geom),
>>>>>>>> (rand2.rand *
>>>>>>>> st_npoints(st_exteriorring(the_geom)))::int)
>>>>>>>>  )
>>>>>>>>  )
>>>>>>>>  ,rand3.rand
>>>>>>>> )
>>>>>>>> from insert_your_table_name_here,
>>>>>>>> (select random() as rand, generate_series(1,1000) as point_number)
>>>>>>>> as
>>>>>>>> rand1
>>>>>>>> JOIN (select random() as rand, generate_series(1,1000) as
>>>>>>>> point_number)
>>>>>>>> as
>>>>>>>> rand2
>>>>>>>>  ON rand1.point_number = rand2.point_number
>>>>>>>> JOIN (select random() as rand, generate_series(1,1000) as
>>>>>>>> point_number)
>>>>>>>> as
>>>>>>>> rand3
>>>>>>>>  ON rand2.point_number = rand3.point_number
>>>>>>>> WHERE st_geometrytype(
>>>>>>>>  st_intersection(
>>>>>>>>  the_geom,
>>>>>>>>  st_makeline(
>>>>>>>>  st_pointn(st_exteriorring(the_geom),
>>>>>>>> (rand1.rand *
>>>>>>>> st_npoints(st_exteriorring(the_geom)))::int),
>>>>>>>>  st_pointn(st_exteriorring(the_geom),
>>>>>>>> (rand2.rand *
>>>>>>>> st_npoints(st_exteriorring(the_geom)))::int)
>>>>>>>>  )
>>>>>>>>  )
>>>>>>>> ) = 'ST_LineString'
>>>>>>>> AND oid = 5030 /* Enter your own OID here */
>>>>>>>> limit 100
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>> -Original Message-
>>>>>>>>> From: postgis-users-boun...@postgis.refractions.net
>>>>>>>>> [mailto:postgis-users-boun...@postgis.refractions.net] On
>>>>>>>>> Behalf Of Martin Davis
>>>>>>>>> Sent: Thursday, May 06, 2010 8:56 AM
>>>>>>>>> To: John Abraham; postgis-users@postgis.refractions.net; Martin
>>>>>>>>> Davis
>>>>>>>>> Subject: Re: [postgis-users] Dot Density idea
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I was thinking the same thing!
>>>>>>>>>
>>>>>>>>> strk wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> ST_RandomPoinsOnSurface(geometry, numpoints) would be an
>>>>>>>>>> interesting
>>>>>>>>>> function indeed. Sounds like a good job for GEOS/JTS.
>>>>>>>>>>
>>>>>>>>>> --strk;
>>>>>>>>>>
>>>>>>>>>> On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>> One of the things I miss about using ESRI's GIS is the
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>

Re: [postgis-users] Dot Density idea

2010-05-08 Thread Jan Hartmann

How about this site?

http://www.johndcook.com/blog/2009/03/16/quasi-random-sequences-in-art-and-integration/

Jan

On 05/07/10 03:59, Ben Madin wrote:

Martin,

Assuming you wanted feedback - from an epidemiologists perspective, I like the 
first one - Complete Spatial Randomness is an important concept to avoid 
engendering a perception of order or clustering, and I'm thinking as long as 
the relative 'dot-density' is correct for each polygon, the CSR approach is 
less like to lead people to think the dots are located on significant points - 
in the context of obscuring actual locations etc this is important.

If you want it more regular, then maybe you don't need to randomise it - or 
maybe this just means the function needs a user parameter to be able to set the 
level of randomisation - From 0 (completely ordered) to 1 (completely Random) 
(... to 2.5 completely clustered?)

Just my thoughts - also for my money, I wouldn't change dot sizes. very 
confusing.

cheers

Ben



On 07/05/2010, at 6:11 , Martin Davis wrote:

   

Check out this blog post for some images of different kinds of random point 
fields:

http://lin-ear-th-inking.blogspot.com/2010/05/more-random-points-in-jts.html

Martin Davis wrote:
 

Sounds like it could work - with maybe a bit of fiddling to deal with cases 
where the grid cells overlapped the polygon only slightly?
Random perturbation by cell radius can still result in some points being very 
close together.  (And I think this would also be an issue where only a small 
part of each grid cell overlapped the polygon).  This may or may not be 
desirable.  Perhaps a further check could be made to reduce the radius for 
points where this occurs.   Or maybe some sort of simulated annealing process 
could be use to push the points into a more even distribution.

M

Paul Ramsey wrote:
   

Even-yet-random :) nice requirement. How about just starting with a
regular grid and then perturbing the elements randomly with a radius
of a cell size? You can use the area of the polygon and number of
needed points to calculate the appropriate cell size and go from
there.

P

On Thu, May 6, 2010 at 10:28 AM, Martin Davis  wrote:

 

Good point about the need for even distribution of the points. That seems
like a whole lot harder to code than simply randomly placing points in a
polygon.  Does anyone have any pointers to algorithms for producing this
effect?

George Silva wrote:

   

The really big problem with dot density is that dots can overlap
themselves,
masking the real number, so if anything will be developed in this area,
the
points should be

A) evenly distributed
or
B) randomly distributed, but with some sort of "colision" tests, so there
is
no or little overlap.

This is a interesting idea, especially if we could make a materialized
view
with those points, which could be added to GIS software for presentation.

George

On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley<
ssuffic...@rov.sbcounty.gov>  wrote:



 

Looks nasty, but it might work:

select
st_line_interpolate_point(
  st_intersection(
  the_geom,
  st_makeline(
  st_pointn(st_exteriorring(the_geom), (rand1.rand *
st_npoints(st_exteriorring(the_geom)))::int),
  st_pointn(st_exteriorring(the_geom), (rand2.rand *
st_npoints(st_exteriorring(the_geom)))::int)
  )
  )
  ,rand3.rand
)
from insert_your_table_name_here,
(select random() as rand, generate_series(1,1000) as point_number) as
rand1
JOIN (select random() as rand, generate_series(1,1000) as point_number)
as
rand2
  ON rand1.point_number = rand2.point_number
JOIN (select random() as rand, generate_series(1,1000) as point_number)
as
rand3
  ON rand2.point_number = rand3.point_number
WHERE st_geometrytype(
  st_intersection(
  the_geom,
  st_makeline(
  st_pointn(st_exteriorring(the_geom), (rand1.rand *
st_npoints(st_exteriorring(the_geom)))::int),
  st_pointn(st_exteriorring(the_geom), (rand2.rand *
st_npoints(st_exteriorring(the_geom)))::int)
  )
  )
) = 'ST_LineString'
AND oid = 5030 /* Enter your own OID here */
limit 100





   

-Original Message-
From: postgis-users-boun...@postgis.refractions.net
[mailto:postgis-users-boun...@postgis.refractions.net] On
Behalf Of Martin Davis
Sent: Thursday, May 06, 2010 8:56 AM
To: John Abraham; postgis-users@postgis.refractions.net; Martin Davis
Subject: Re: [postgis-users] Dot Density idea


I was thinking the same thing!

strk wrote:


 

ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
function indeed. Sounds like a good job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:



   

One of the things I miss about using ESRI's GIS is the


 

Re: [postgis-users] Dot Density idea

2010-05-07 Thread Ben Madin
Martin,

Assuming you wanted feedback - from an epidemiologists perspective, I like the 
first one - Complete Spatial Randomness is an important concept to avoid 
engendering a perception of order or clustering, and I'm thinking as long as 
the relative 'dot-density' is correct for each polygon, the CSR approach is 
less like to lead people to think the dots are located on significant points - 
in the context of obscuring actual locations etc this is important. 

If you want it more regular, then maybe you don't need to randomise it - or 
maybe this just means the function needs a user parameter to be able to set the 
level of randomisation - From 0 (completely ordered) to 1 (completely Random) 
(... to 2.5 completely clustered?)

Just my thoughts - also for my money, I wouldn't change dot sizes. very 
confusing.

cheers

Ben



On 07/05/2010, at 6:11 , Martin Davis wrote:

> Check out this blog post for some images of different kinds of random point 
> fields:
> 
> http://lin-ear-th-inking.blogspot.com/2010/05/more-random-points-in-jts.html
> 
> Martin Davis wrote:
>> Sounds like it could work - with maybe a bit of fiddling to deal with cases 
>> where the grid cells overlapped the polygon only slightly?
>> Random perturbation by cell radius can still result in some points being 
>> very close together.  (And I think this would also be an issue where only a 
>> small part of each grid cell overlapped the polygon).  This may or may not 
>> be desirable.  Perhaps a further check could be made to reduce the radius 
>> for points where this occurs.   Or maybe some sort of simulated annealing 
>> process could be use to push the points into a more even distribution.
>> 
>> M
>> 
>> Paul Ramsey wrote:
>>> Even-yet-random :) nice requirement. How about just starting with a
>>> regular grid and then perturbing the elements randomly with a radius
>>> of a cell size? You can use the area of the polygon and number of
>>> needed points to calculate the appropriate cell size and go from
>>> there.
>>> 
>>> P
>>> 
>>> On Thu, May 6, 2010 at 10:28 AM, Martin Davis  
>>> wrote:
>>> 
>>>> Good point about the need for even distribution of the points. That seems
>>>> like a whole lot harder to code than simply randomly placing points in a
>>>> polygon.  Does anyone have any pointers to algorithms for producing this
>>>> effect?
>>>> 
>>>> George Silva wrote:
>>>>   
>>>>> The really big problem with dot density is that dots can overlap
>>>>> themselves,
>>>>> masking the real number, so if anything will be developed in this area,
>>>>> the
>>>>> points should be
>>>>> 
>>>>> A) evenly distributed
>>>>> or
>>>>> B) randomly distributed, but with some sort of "colision" tests, so there
>>>>> is
>>>>> no or little overlap.
>>>>> 
>>>>> This is a interesting idea, especially if we could make a materialized
>>>>> view
>>>>> with those points, which could be added to GIS software for presentation.
>>>>> 
>>>>> George
>>>>> 
>>>>> On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley <
>>>>> ssuffic...@rov.sbcounty.gov> wrote:
>>>>> 
>>>>> 
>>>>> 
>>>>>> Looks nasty, but it might work:
>>>>>> 
>>>>>> select
>>>>>> st_line_interpolate_point(
>>>>>>  st_intersection(
>>>>>>  the_geom,
>>>>>>  st_makeline(
>>>>>>  st_pointn(st_exteriorring(the_geom), (rand1.rand *
>>>>>> st_npoints(st_exteriorring(the_geom)))::int),
>>>>>>  st_pointn(st_exteriorring(the_geom), (rand2.rand *
>>>>>> st_npoints(st_exteriorring(the_geom)))::int)
>>>>>>  )
>>>>>>  )
>>>>>>  ,rand3.rand
>>>>>> )
>>>>>> from insert_your_table_name_here,
>>>>>> (select random() as rand, generate_series(1,1000) as point_number) as
>>>>>> rand1
>>>>>> JOIN (select random() as rand, generate_series(1,1000) as point_number)
>>>>>> as
>>>>>> rand2
>>>>>>  ON rand1.point_number = rand2.point_number
>>>>>> JOIN (se

Re: [postgis-users] Dot Density idea

2010-05-06 Thread Martin Davis
Check out this blog post for some images of different kinds of random 
point fields:


http://lin-ear-th-inking.blogspot.com/2010/05/more-random-points-in-jts.html

Martin Davis wrote:
Sounds like it could work - with maybe a bit of fiddling to deal with 
cases where the grid cells overlapped the polygon only slightly?
Random perturbation by cell radius can still result in some points 
being very close together.  (And I think this would also be an issue 
where only a small part of each grid cell overlapped the polygon).  
This may or may not be desirable.  Perhaps a further check could be 
made to reduce the radius for points where this occurs.   Or maybe 
some sort of simulated annealing process could be use to push the 
points into a more even distribution.


M

Paul Ramsey wrote:

Even-yet-random :) nice requirement. How about just starting with a
regular grid and then perturbing the elements randomly with a radius
of a cell size? You can use the area of the polygon and number of
needed points to calculate the appropriate cell size and go from
there.

P

On Thu, May 6, 2010 at 10:28 AM, Martin Davis 
 wrote:
 
Good point about the need for even distribution of the points. That 
seems
like a whole lot harder to code than simply randomly placing points 
in a
polygon.  Does anyone have any pointers to algorithms for producing 
this

effect?

George Silva wrote:
   

The really big problem with dot density is that dots can overlap
themselves,
masking the real number, so if anything will be developed in this 
area,

the
points should be

A) evenly distributed
or
B) randomly distributed, but with some sort of "colision" tests, so 
there

is
no or little overlap.

This is a interesting idea, especially if we could make a materialized
view
with those points, which could be added to GIS software for 
presentation.


George

On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley <
ssuffic...@rov.sbcounty.gov> wrote:


 

Looks nasty, but it might work:

select
st_line_interpolate_point(
  st_intersection(
  the_geom,
  st_makeline(
  st_pointn(st_exteriorring(the_geom), 
(rand1.rand *

st_npoints(st_exteriorring(the_geom)))::int),
  st_pointn(st_exteriorring(the_geom), 
(rand2.rand *

st_npoints(st_exteriorring(the_geom)))::int)
  )
  )
  ,rand3.rand
)
from insert_your_table_name_here,
(select random() as rand, generate_series(1,1000) as point_number) as
rand1
JOIN (select random() as rand, generate_series(1,1000) as 
point_number)

as
rand2
  ON rand1.point_number = rand2.point_number
JOIN (select random() as rand, generate_series(1,1000) as 
point_number)

as
rand3
  ON rand2.point_number = rand3.point_number
WHERE st_geometrytype(
  st_intersection(
  the_geom,
  st_makeline(
  st_pointn(st_exteriorring(the_geom), 
(rand1.rand *

st_npoints(st_exteriorring(the_geom)))::int),
  st_pointn(st_exteriorring(the_geom), 
(rand2.rand *

st_npoints(st_exteriorring(the_geom)))::int)
  )
  )
) = 'ST_LineString'
AND oid = 5030 /* Enter your own OID here */
limit 100




   

-Original Message-
From: postgis-users-boun...@postgis.refractions.net
[mailto:postgis-users-boun...@postgis.refractions.net] On
Behalf Of Martin Davis
Sent: Thursday, May 06, 2010 8:56 AM
To: John Abraham; postgis-users@postgis.refractions.net; Martin 
Davis

Subject: Re: [postgis-users] Dot Density idea


I was thinking the same thing!

strk wrote:

 
ST_RandomPoinsOnSurface(geometry, numpoints) would be an 
interesting

function indeed. Sounds like a good job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:


   

One of the things I miss about using ESRI's GIS is the

  

ability to do

 

dot-density maps.  Within a polygon, the number of dots is

  

proportional to a value, and the dots are randomly placed.  I
find it useful to be able to present several data values at
once (e.g. blue dots for population, red dots for employment).

 

I also find that it is a more intuitive way of scaling for

  

zone size

 

than dividing the value by the area of the zone.  That is,

  

the count

 

of the dots represents the actual number, but the density

  

of the dots

 

represents the density of the number.  So I don't have to decide
whether to divide the value by the area of the polygon to plot
density: both the absolute number and the density are

  

easily visible.

 

Since my open-source GIS viewing systems (mostly QGIS and

  

Mapserver)

 

won't plot dot-density, I've done without.

But today I realized that I can build these on the server

  

instead.  I

 

can generate random points within

Re: [postgis-users] Dot Density idea

2010-05-06 Thread Martin Davis

Which is a nice segue into this thread:

http://sourceforge.net/mailarchive/forum.php?thread_name=s2he24c4c271005042228wfff7b9abjadf3eb357fe0c712%40mail.gmail.com&forum_name=jts-topo-suite-user


Norman Vine wrote:

When I have done this before I usually triangulate the polygon
first  then use each triangles area to normalize the number of 
points randomly inserted into each triangle


On May 6, 2010, at 1:51 PM, David William Bitner wrote:

  

If it was the overall density of the dots that mattered and not as much the exact number 
of dots, a representative table could be made with a "random yet even" set of 
dots covering a certain area. To apply to a polygon, you could then Scale the data to the 
appropriate density and translate/compute the intersection to apply to a given polygon.

On Thu, May 6, 2010 at 12:50 PM, Martin Davis  wrote:
Did your algorithm work with irregular polgon extents?


Jan Hartmann wrote:
I did this long ago. Regular points won't work, you'll get all kinds of moire 
patterns. I just computed random x and y values from the origin of the grid 
cell within the x- and y grid-size. Can't remember having any problems with 
overlapping points.

Jan

On 05/06/10 19:35, Paul Ramsey wrote:
Even-yet-random :) nice requirement. How about just starting with a
regular grid and then perturbing the elements randomly with a radius
of a cell size? You can use the area of the polygon and number of
needed points to calculate the appropriate cell size and go from
there.

P

On Thu, May 6, 2010 at 10:28 AM, Martin Davis  wrote:
 
Good point about the need for even distribution of the points. That seems

like a whole lot harder to code than simply randomly placing points in a
polygon.  Does anyone have any pointers to algorithms for producing this
effect?

George Silva wrote:
   
The really big problem with dot density is that dots can overlap

themselves,
masking the real number, so if anything will be developed in this area,
the
points should be

A) evenly distributed
or
B) randomly distributed, but with some sort of "colision" tests, so there
is
no or little overlap.

This is a interesting idea, especially if we could make a materialized
view
with those points, which could be added to GIS software for presentation.

George

On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley<
ssuffic...@rov.sbcounty.gov>  wrote:


 
Looks nasty, but it might work:


select
st_line_interpolate_point(
  st_intersection(
  the_geom,
  st_makeline(
  st_pointn(st_exteriorring(the_geom), (rand1.rand *
st_npoints(st_exteriorring(the_geom)))::int),
  st_pointn(st_exteriorring(the_geom), (rand2.rand *
st_npoints(st_exteriorring(the_geom)))::int)
  )
  )
  ,rand3.rand
)
from insert_your_table_name_here,
(select random() as rand, generate_series(1,1000) as point_number) as
rand1
JOIN (select random() as rand, generate_series(1,1000) as point_number)
as
rand2
  ON rand1.point_number = rand2.point_number
JOIN (select random() as rand, generate_series(1,1000) as point_number)
as
rand3
  ON rand2.point_number = rand3.point_number
WHERE st_geometrytype(
  st_intersection(
  the_geom,
  st_makeline(
  st_pointn(st_exteriorring(the_geom), (rand1.rand *
st_npoints(st_exteriorring(the_geom)))::int),
  st_pointn(st_exteriorring(the_geom), (rand2.rand *
st_npoints(st_exteriorring(the_geom)))::int)
  )
  )
) = 'ST_LineString'
AND oid = 5030 /* Enter your own OID here */
limit 100




   
-Original Message-

From: postgis-users-boun...@postgis.refractions.net
[mailto:postgis-users-boun...@postgis.refractions.net] On
Behalf Of Martin Davis
Sent: Thursday, May 06, 2010 8:56 AM
To: John Abraham; postgis-users@postgis.refractions.net; Martin Davis
Subject: Re: [postgis-users] Dot Density idea


I was thinking the same thing!

strk wrote:

 
ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting

function indeed. Sounds like a good job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:


   
One of the things I miss about using ESRI's GIS is the


  
ability to do


 
dot-density maps.  Within a polygon, the number of dots is


  
proportional to a value, and the dots are randomly placed.  I

find it useful to be able to present several data values at
once (e.g. blue dots for population, red dots for employment).

 
I also find that it is a more intuitive way of scaling for


  
zone size


 
than dividing the value by the area of the zone.  That is,


  
the count


 
of the dots represents the actual number, but the density


  
of the dots


 
represents the density of the number.  So I don't have to decide

whether to 

Re: [postgis-users] Dot Density idea

2010-05-06 Thread Norman Vine
When I have done this before I usually triangulate the polygon
first  then use each triangles area to normalize the number of 
points randomly inserted into each triangle

On May 6, 2010, at 1:51 PM, David William Bitner wrote:

> If it was the overall density of the dots that mattered and not as much the 
> exact number of dots, a representative table could be made with a "random yet 
> even" set of dots covering a certain area. To apply to a polygon, you could 
> then Scale the data to the appropriate density and translate/compute the 
> intersection to apply to a given polygon.
> 
> On Thu, May 6, 2010 at 12:50 PM, Martin Davis  wrote:
> Did your algorithm work with irregular polgon extents?
> 
> 
> Jan Hartmann wrote:
> I did this long ago. Regular points won't work, you'll get all kinds of moire 
> patterns. I just computed random x and y values from the origin of the grid 
> cell within the x- and y grid-size. Can't remember having any problems with 
> overlapping points.
> 
> Jan
> 
> On 05/06/10 19:35, Paul Ramsey wrote:
> Even-yet-random :) nice requirement. How about just starting with a
> regular grid and then perturbing the elements randomly with a radius
> of a cell size? You can use the area of the polygon and number of
> needed points to calculate the appropriate cell size and go from
> there.
> 
> P
> 
> On Thu, May 6, 2010 at 10:28 AM, Martin Davis  wrote:
>  
> Good point about the need for even distribution of the points. That seems
> like a whole lot harder to code than simply randomly placing points in a
> polygon.  Does anyone have any pointers to algorithms for producing this
> effect?
> 
> George Silva wrote:
>
> The really big problem with dot density is that dots can overlap
> themselves,
> masking the real number, so if anything will be developed in this area,
> the
> points should be
> 
> A) evenly distributed
> or
> B) randomly distributed, but with some sort of "colision" tests, so there
> is
> no or little overlap.
> 
> This is a interesting idea, especially if we could make a materialized
> view
> with those points, which could be added to GIS software for presentation.
> 
> George
> 
> On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley<
> ssuffic...@rov.sbcounty.gov>  wrote:
> 
> 
>  
> Looks nasty, but it might work:
> 
> select
> st_line_interpolate_point(
>   st_intersection(
>   the_geom,
>   st_makeline(
>   st_pointn(st_exteriorring(the_geom), (rand1.rand *
> st_npoints(st_exteriorring(the_geom)))::int),
>   st_pointn(st_exteriorring(the_geom), (rand2.rand *
> st_npoints(st_exteriorring(the_geom)))::int)
>   )
>   )
>   ,rand3.rand
> )
> from insert_your_table_name_here,
> (select random() as rand, generate_series(1,1000) as point_number) as
> rand1
> JOIN (select random() as rand, generate_series(1,1000) as point_number)
> as
> rand2
>   ON rand1.point_number = rand2.point_number
> JOIN (select random() as rand, generate_series(1,1000) as point_number)
> as
> rand3
>   ON rand2.point_number = rand3.point_number
> WHERE st_geometrytype(
>   st_intersection(
>   the_geom,
>   st_makeline(
>   st_pointn(st_exteriorring(the_geom), (rand1.rand *
> st_npoints(st_exteriorring(the_geom)))::int),
>   st_pointn(st_exteriorring(the_geom), (rand2.rand *
> st_npoints(st_exteriorring(the_geom)))::int)
>   )
>   )
> ) = 'ST_LineString'
> AND oid = 5030 /* Enter your own OID here */
> limit 100
> 
> 
> 
> 
>
> -Original Message-
> From: postgis-users-boun...@postgis.refractions.net
> [mailto:postgis-users-boun...@postgis.refractions.net] On
> Behalf Of Martin Davis
> Sent: Thursday, May 06, 2010 8:56 AM
> To: John Abraham; postgis-users@postgis.refractions.net; Martin Davis
> Subject: Re: [postgis-users] Dot Density idea
> 
> 
> I was thinking the same thing!
> 
> strk wrote:
> 
>  
> ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
> function indeed. Sounds like a good job for GEOS/JTS.
> 
> --strk;
> 
> On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
> 
> 
>
> One of the things I miss about using ESRI's GIS is the
> 
>   
> ability to do
> 
>  
> dot-density maps.  Within a polygon, the number of dots is
> 
>   
> proportional to a value, and the dots are randomly placed.  I
> find it useful to be able to present several data values 

Re: [postgis-users] Dot Density idea

2010-05-06 Thread pcreso
Hi,

We use an application much like this for generating random sample points for 
2-phase random stratified trawl biomass surveys. Specify polygon name, number 
of points, minimum distance from the boundary, minimum distance between points 
in a file, then iterate through the file.

The code has a limit on the number of iterations per stratum to try before 
deciding that we can't actually fit that many points in it with the current 
parameters.

Strata can be polygons or multipolygons, with or without holes.

If anyone is really interested, a paper describing the approach for such survey 
design & analysis is at:

http://www.royalsociety.org.nz/Site/publish/Journals/nzjmfr/1984/8.aspx

This simply makes the assumption that the distribution of sample sites is 
random. 

The application we use is in C++, but I wrote a PostGIS version a few years ago 
as a bash script to demonstrate the functionality from within a db. 

One of the issues we ran into was running repeated iterations then looking at 
the distribution of the points across iterations to check that there was 
genuinely no pattern. Generally most random functions we tested were not truly 
random, there was a trend for coordinates to lie towards the top right or 
bottom left, as random values tended to be < or > 0.5. Not that noticeable with 
a single iteration but statistically present. We wrote our own random() 
function in the program to get around such artifacts.


Cheers,

  Brent Wood


--- On Fri, 5/7/10, Martin Davis  wrote:

> From: Martin Davis 
> Subject: Re: [postgis-users] Dot Density idea
> To: "PostGIS Users Discussion" 
> Date: Friday, May 7, 2010, 5:50 AM
> Did your algorithm work with
> irregular polgon extents?
> 
> Jan Hartmann wrote:
> > I did this long ago. Regular points won't work, you'll
> get all kinds of moire patterns. I just computed random x
> and y values from the origin of the grid cell within the x-
> and y grid-size. Can't remember having any problems with
> overlapping points.
> > 
> > Jan
> > 
> > On 05/06/10 19:35, Paul Ramsey wrote:
> >> Even-yet-random :) nice requirement. How about
> just starting with a
> >> regular grid and then perturbing the elements
> randomly with a radius
> >> of a cell size? You can use the area of the
> polygon and number of
> >> needed points to calculate the appropriate cell
> size and go from
> >> there.
> >> 
> >> P
> >> 
> >> On Thu, May 6, 2010 at 10:28 AM, Martin
> Davis 
> wrote:
> >>   
> >>> Good point about the need for even
> distribution of the points. That seems
> >>> like a whole lot harder to code than simply
> randomly placing points in a
> >>> polygon.  Does anyone have any pointers
> to algorithms for producing this
> >>> effect?
> >>> 
> >>> George Silva wrote:
> >>>     
> >>>> The really big problem with dot density is
> that dots can overlap
> >>>> themselves,
> >>>> masking the real number, so if anything
> will be developed in this area,
> >>>> the
> >>>> points should be
> >>>> 
> >>>> A) evenly distributed
> >>>> or
> >>>> B) randomly distributed, but with some
> sort of "colision" tests, so there
> >>>> is
> >>>> no or little overlap.
> >>>> 
> >>>> This is a interesting idea, especially if
> we could make a materialized
> >>>> view
> >>>> with those points, which could be added to
> GIS software for presentation.
> >>>> 
> >>>> George
> >>>> 
> >>>> On Thu, May 6, 2010 at 1:53 PM, Sufficool,
> Stanley<
> >>>> ssuffic...@rov.sbcounty.gov> 
> wrote:
> >>>> 
> >>>> 
> >>>>       
> >>>>> Looks nasty, but it might work:
> >>>>> 
> >>>>> select
> >>>>> st_line_interpolate_point(
> >>>>>       
> st_intersection(
> >>>>>         
>       the_geom,
> >>>>>         
>       st_makeline(
> >>>>>         
>              
> st_pointn(st_exteriorring(the_geom), (rand1.rand *
> >>>>>
> st_npoints(st_exteriorring(the_geom)))::int),
> >>>>>         
>              
> st_pointn(st_exteriorring(the_geom), (rand2.rand *
> >>>>>
> st_npoints(st_exteriorring(the_geom)))::int)
> >>>>>         
>       )
> >&

Re: [postgis-users] Dot Density idea

2010-05-06 Thread George Silva
Yea, this is very cool indeed.

George

On Thu, May 6, 2010 at 3:33 PM, David Fawcett wrote:

> Doesn't OpenSource suck!!!
>
>
> On Mon, May 3, 2010 at 11:49 PM, John Abraham 
> wrote:
> > One of the things I miss about using ESRI's GIS is the ability to do
> dot-density maps.  Within a polygon, the number of dots is
>
> An then an hour later...
>
>
> http://lin-ear-th-inking.blogspot.com/2010/05/random-points-in-polygon-in-jts.html
>
> Sure, it's not a PostGIS solution and isn't exactly there yet, but not
> bad...
>
> Imagine the converse:
>
> Dear Jack,
>
> There is this useful feature that is missing from your software, when
> do you think that you could get it into a release?...
> ___
> postgis-users mailing list
> postgis-users@postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>



-- 
George R. C. Silva

Desenvolvimento em GIS
http://blog.geoprocessamento.net
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] Dot Density idea

2010-05-06 Thread David Fawcett
Doesn't OpenSource suck!!!


On Mon, May 3, 2010 at 11:49 PM, John Abraham  wrote:
> One of the things I miss about using ESRI's GIS is the ability to do 
> dot-density maps.  Within a polygon, the number of dots is

An then an hour later...

http://lin-ear-th-inking.blogspot.com/2010/05/random-points-in-polygon-in-jts.html

Sure, it's not a PostGIS solution and isn't exactly there yet, but not bad...

Imagine the converse:

Dear Jack,

There is this useful feature that is missing from your software, when
do you think that you could get it into a release?...
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] Dot Density idea

2010-05-06 Thread Jan Hartmann
orring(the_geom), (rand1.rand *

st_npoints(st_exteriorring(the_geom)))::int),
 
st_pointn(st_exteriorring(the_geom), (rand2.rand *

st_npoints(st_exteriorring(the_geom)))::int)
  )
  )
) = 'ST_LineString'
AND oid = 5030 /* Enter your own OID here */
limit 100





-Original Message-
From:
postgis-users-boun...@postgis.refractions.net

<mailto:postgis-users-boun...@postgis.refractions.net>

[mailto:postgis-users-boun...@postgis.refractions.net

<mailto:postgis-users-boun...@postgis.refractions.net>]
On
Behalf Of Martin Davis
Sent: Thursday, May 06, 2010 8:56 AM
To: John Abraham;
postgis-users@postgis.refractions.net
<mailto:postgis-users@postgis.refractions.net>;
            Martin Davis
Subject: Re: [postgis-users] Dot Density idea


I was thinking the same thing!

strk wrote:


ST_RandomPoinsOnSurface(geometry,
numpoints) would be an interesting
function indeed. Sounds like a good
job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM
-0600, John Abraham wrote:



One of the things I miss about
using ESRI's GIS is the


ability to do


dot-density maps.  Within a
polygon, the number of dots is


proportional to a value, and the dots are
randomly placed.  I
find it useful to be able to present
several data values at
once (e.g. blue dots for population, red
dots for employment).


I also find that it is a more
intuitive way of scaling for


zone size


than dividing the value by the
area of the zone.  That is,


the count


of the dots represents the actual
number, but the density


of the dots


represents the density of the
number.  So I don't have to decide
whether to divide the value by the
area of the polygon to plot
density: both the absolute number
and the density are


easily visible.


Since my open-source GIS viewing
systems (mostly QGIS and


Mapserver)


won't plot dot-density, I've done
without.

But today I realized that I can
build these on the server


instead.  I


can generate random points within
the bounding-box of the polygon,
throwing out those that aren't
contained within the polygon,
repeating until I have enough.
 Then I can save these points as a
separate layer, and display this
layer using almost any desktop or
web based viewer!

Has anyone done this?  Can I do it
in SQL or do I need to write
something in PL/pgsql?

-- 
John Abraham


   

Re: [postgis-users] Dot Density idea

2010-05-06 Thread David William Bitner
If it was the overall density of the dots that mattered and not as much the
exact number of dots, a representative table could be made with a "random
yet even" set of dots covering a certain area. To apply to a polygon, you
could then Scale the data to the appropriate density and translate/compute
the intersection to apply to a given polygon.

On Thu, May 6, 2010 at 12:50 PM, Martin Davis wrote:

> Did your algorithm work with irregular polgon extents?
>
>
> Jan Hartmann wrote:
>
>> I did this long ago. Regular points won't work, you'll get all kinds of
>> moire patterns. I just computed random x and y values from the origin of the
>> grid cell within the x- and y grid-size. Can't remember having any problems
>> with overlapping points.
>>
>> Jan
>>
>> On 05/06/10 19:35, Paul Ramsey wrote:
>>
>>> Even-yet-random :) nice requirement. How about just starting with a
>>> regular grid and then perturbing the elements randomly with a radius
>>> of a cell size? You can use the area of the polygon and number of
>>> needed points to calculate the appropriate cell size and go from
>>> there.
>>>
>>> P
>>>
>>> On Thu, May 6, 2010 at 10:28 AM, Martin Davis
>>>  wrote:
>>>
>>>
>>>> Good point about the need for even distribution of the points. That
>>>> seems
>>>> like a whole lot harder to code than simply randomly placing points in a
>>>> polygon.  Does anyone have any pointers to algorithms for producing this
>>>> effect?
>>>>
>>>> George Silva wrote:
>>>>
>>>>
>>>>> The really big problem with dot density is that dots can overlap
>>>>> themselves,
>>>>> masking the real number, so if anything will be developed in this area,
>>>>> the
>>>>> points should be
>>>>>
>>>>> A) evenly distributed
>>>>> or
>>>>> B) randomly distributed, but with some sort of "colision" tests, so
>>>>> there
>>>>> is
>>>>> no or little overlap.
>>>>>
>>>>> This is a interesting idea, especially if we could make a materialized
>>>>> view
>>>>> with those points, which could be added to GIS software for
>>>>> presentation.
>>>>>
>>>>> George
>>>>>
>>>>> On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley<
>>>>> ssuffic...@rov.sbcounty.gov>  wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> Looks nasty, but it might work:
>>>>>>
>>>>>> select
>>>>>> st_line_interpolate_point(
>>>>>>   st_intersection(
>>>>>>   the_geom,
>>>>>>   st_makeline(
>>>>>>   st_pointn(st_exteriorring(the_geom), (rand1.rand
>>>>>> *
>>>>>> st_npoints(st_exteriorring(the_geom)))::int),
>>>>>>   st_pointn(st_exteriorring(the_geom), (rand2.rand
>>>>>> *
>>>>>> st_npoints(st_exteriorring(the_geom)))::int)
>>>>>>   )
>>>>>>   )
>>>>>>   ,rand3.rand
>>>>>> )
>>>>>> from insert_your_table_name_here,
>>>>>> (select random() as rand, generate_series(1,1000) as point_number) as
>>>>>> rand1
>>>>>> JOIN (select random() as rand, generate_series(1,1000) as
>>>>>> point_number)
>>>>>> as
>>>>>> rand2
>>>>>>   ON rand1.point_number = rand2.point_number
>>>>>> JOIN (select random() as rand, generate_series(1,1000) as
>>>>>> point_number)
>>>>>> as
>>>>>> rand3
>>>>>>   ON rand2.point_number = rand3.point_number
>>>>>> WHERE st_geometrytype(
>>>>>>   st_intersection(
>>>>>>   the_geom,
>>>>>>   st_makeline(
>>>>>>   st_pointn(st_exteriorring(the_geom), (rand1.rand
>>>>>> *
>>>>>> st_npoints(st_exteriorring(the_geom)))::int),
>>>>>>   st_pointn(st_exteriorring(the_geom), (rand2.rand
>>>>>> *
>>>>>>

Re: [postgis-users] Dot Density idea

2010-05-06 Thread Martin Davis

Did your algorithm work with irregular polgon extents?

Jan Hartmann wrote:
I did this long ago. Regular points won't work, you'll get all kinds 
of moire patterns. I just computed random x and y values from the 
origin of the grid cell within the x- and y grid-size. Can't remember 
having any problems with overlapping points.


Jan

On 05/06/10 19:35, Paul Ramsey wrote:

Even-yet-random :) nice requirement. How about just starting with a
regular grid and then perturbing the elements randomly with a radius
of a cell size? You can use the area of the polygon and number of
needed points to calculate the appropriate cell size and go from
there.

P

On Thu, May 6, 2010 at 10:28 AM, Martin 
Davis  wrote:
  
Good point about the need for even distribution of the points. That 
seems
like a whole lot harder to code than simply randomly placing points 
in a
polygon.  Does anyone have any pointers to algorithms for producing 
this

effect?

George Silva wrote:


The really big problem with dot density is that dots can overlap
themselves,
masking the real number, so if anything will be developed in this 
area,

the
points should be

A) evenly distributed
or
B) randomly distributed, but with some sort of "colision" tests, so 
there

is
no or little overlap.

This is a interesting idea, especially if we could make a materialized
view
with those points, which could be added to GIS software for 
presentation.


George

On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley<
ssuffic...@rov.sbcounty.gov>  wrote:


  

Looks nasty, but it might work:

select
st_line_interpolate_point(
   st_intersection(
   the_geom,
   st_makeline(
   st_pointn(st_exteriorring(the_geom), 
(rand1.rand *

st_npoints(st_exteriorring(the_geom)))::int),
   st_pointn(st_exteriorring(the_geom), 
(rand2.rand *

st_npoints(st_exteriorring(the_geom)))::int)
   )
   )
   ,rand3.rand
)
from insert_your_table_name_here,
(select random() as rand, generate_series(1,1000) as point_number) as
rand1
JOIN (select random() as rand, generate_series(1,1000) as 
point_number)

as
rand2
   ON rand1.point_number = rand2.point_number
JOIN (select random() as rand, generate_series(1,1000) as 
point_number)

as
rand3
   ON rand2.point_number = rand3.point_number
WHERE st_geometrytype(
   st_intersection(
   the_geom,
   st_makeline(
   st_pointn(st_exteriorring(the_geom), 
(rand1.rand *

st_npoints(st_exteriorring(the_geom)))::int),
   st_pointn(st_exteriorring(the_geom), 
(rand2.rand *

st_npoints(st_exteriorring(the_geom)))::int)
   )
   )
) = 'ST_LineString'
AND oid = 5030 /* Enter your own OID here */
limit 100






-Original Message-
From: postgis-users-boun...@postgis.refractions.net
[mailto:postgis-users-boun...@postgis.refractions.net] On
Behalf Of Martin Davis
Sent: Thursday, May 06, 2010 8:56 AM
To: John Abraham; postgis-users@postgis.refractions.net; Martin 
Davis

Subject: Re: [postgis-users] Dot Density idea


I was thinking the same thing!

strk wrote:

  
ST_RandomPoinsOnSurface(geometry, numpoints) would be an 
interesting

function indeed. Sounds like a good job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:




One of the things I miss about using ESRI's GIS is the

   

ability to do

  

dot-density maps.  Within a polygon, the number of dots is

   

proportional to a value, and the dots are randomly placed.  I
find it useful to be able to present several data values at
once (e.g. blue dots for population, red dots for employment).

  

I also find that it is a more intuitive way of scaling for

   

zone size

  

than dividing the value by the area of the zone.  That is,

   

the count

  

of the dots represents the actual number, but the density

   

of the dots

  

represents the density of the number.  So I don't have to decide
whether to divide the value by the area of the polygon to plot
density: both the absolute number and the density are

   

easily visible.

  

Since my open-source GIS viewing systems (mostly QGIS and

   

Mapserver)

  

won't plot dot-density, I've done without.

But today I realized that I can build these on the server

   

instead.  I

  

can generate random points within the bounding-box of the polygon,
throwing out those that aren't contained within the polygon,
repeating until I have enough.  Then I can save these points as a
separate layer, and display this layer using almost any desktop or
web based viewer!

Has anyone done this?  Can I do it in SQL or do I need to write
something in PL/pgsql?

--
John Abraha

Re: [postgis-users] Dot Density idea

2010-05-06 Thread Martin Davis
Sounds like it could work - with maybe a bit of fiddling to deal with 
cases where the grid cells overlapped the polygon only slightly? 

Random perturbation by cell radius can still result in some points being 
very close together.  (And I think this would also be an issue where 
only a small part of each grid cell overlapped the polygon).  This may 
or may not be desirable.  Perhaps a further check could be made to 
reduce the radius for points where this occurs.   Or maybe some sort of 
simulated annealing process could be use to push the points into a more 
even distribution.


M

Paul Ramsey wrote:

Even-yet-random :) nice requirement. How about just starting with a
regular grid and then perturbing the elements randomly with a radius
of a cell size? You can use the area of the polygon and number of
needed points to calculate the appropriate cell size and go from
there.

P

On Thu, May 6, 2010 at 10:28 AM, Martin Davis  wrote:
  

Good point about the need for even distribution of the points. That seems
like a whole lot harder to code than simply randomly placing points in a
polygon.  Does anyone have any pointers to algorithms for producing this
effect?

George Silva wrote:


The really big problem with dot density is that dots can overlap
themselves,
masking the real number, so if anything will be developed in this area,
the
points should be

A) evenly distributed
or
B) randomly distributed, but with some sort of "colision" tests, so there
is
no or little overlap.

This is a interesting idea, especially if we could make a materialized
view
with those points, which could be added to GIS software for presentation.

George

On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley <
ssuffic...@rov.sbcounty.gov> wrote:


  

Looks nasty, but it might work:

select
st_line_interpolate_point(
  st_intersection(
  the_geom,
  st_makeline(
  st_pointn(st_exteriorring(the_geom), (rand1.rand *
st_npoints(st_exteriorring(the_geom)))::int),
  st_pointn(st_exteriorring(the_geom), (rand2.rand *
st_npoints(st_exteriorring(the_geom)))::int)
  )
  )
  ,rand3.rand
)
from insert_your_table_name_here,
(select random() as rand, generate_series(1,1000) as point_number) as
rand1
JOIN (select random() as rand, generate_series(1,1000) as point_number)
as
rand2
  ON rand1.point_number = rand2.point_number
JOIN (select random() as rand, generate_series(1,1000) as point_number)
as
rand3
  ON rand2.point_number = rand3.point_number
WHERE st_geometrytype(
  st_intersection(
  the_geom,
  st_makeline(
  st_pointn(st_exteriorring(the_geom), (rand1.rand *
st_npoints(st_exteriorring(the_geom)))::int),
  st_pointn(st_exteriorring(the_geom), (rand2.rand *
st_npoints(st_exteriorring(the_geom)))::int)
  )
  )
) = 'ST_LineString'
AND oid = 5030 /* Enter your own OID here */
limit 100






-Original Message-
From: postgis-users-boun...@postgis.refractions.net
[mailto:postgis-users-boun...@postgis.refractions.net] On
Behalf Of Martin Davis
Sent: Thursday, May 06, 2010 8:56 AM
To: John Abraham; postgis-users@postgis.refractions.net; Martin Davis
Subject: Re: [postgis-users] Dot Density idea


I was thinking the same thing!

strk wrote:

  

ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
function indeed. Sounds like a good job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:




One of the things I miss about using ESRI's GIS is the

  

ability to do

  

dot-density maps.  Within a polygon, the number of dots is

  

proportional to a value, and the dots are randomly placed.  I
find it useful to be able to present several data values at
once (e.g. blue dots for population, red dots for employment).

  

I also find that it is a more intuitive way of scaling for

  

zone size

  

than dividing the value by the area of the zone.  That is,

  

the count

  

of the dots represents the actual number, but the density

  

of the dots

  

represents the density of the number.  So I don't have to decide
whether to divide the value by the area of the polygon to plot
density: both the absolute number and the density are

  

easily visible.

  

Since my open-source GIS viewing systems (mostly QGIS and

  

Mapserver)

  

won't plot dot-density, I've done without.

But today I realized that I can build these on the server

  

instead.  I

  

can generate random points within the bounding-box of the polygon,
throwing out those that aren't contained within the polygon,
repeating until I have enough.  Then I can save these points as a
separate layer, and displ

Re: [postgis-users] Dot Density idea

2010-05-06 Thread Jan Hartmann
I did this long ago. Regular points won't work, you'll get all kinds of 
moire patterns. I just computed random x and y values from the origin of 
the grid cell within the x- and y grid-size. Can't remember having any 
problems with overlapping points.


Jan

On 05/06/10 19:35, Paul Ramsey wrote:

Even-yet-random :) nice requirement. How about just starting with a
regular grid and then perturbing the elements randomly with a radius
of a cell size? You can use the area of the polygon and number of
needed points to calculate the appropriate cell size and go from
there.

P

On Thu, May 6, 2010 at 10:28 AM, Martin Davis  wrote:
   

Good point about the need for even distribution of the points. That seems
like a whole lot harder to code than simply randomly placing points in a
polygon.  Does anyone have any pointers to algorithms for producing this
effect?

George Silva wrote:
 

The really big problem with dot density is that dots can overlap
themselves,
masking the real number, so if anything will be developed in this area,
the
points should be

A) evenly distributed
or
B) randomly distributed, but with some sort of "colision" tests, so there
is
no or little overlap.

This is a interesting idea, especially if we could make a materialized
view
with those points, which could be added to GIS software for presentation.

George

On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley<
ssuffic...@rov.sbcounty.gov>  wrote:


   

Looks nasty, but it might work:

select
st_line_interpolate_point(
   st_intersection(
   the_geom,
   st_makeline(
   st_pointn(st_exteriorring(the_geom), (rand1.rand *
st_npoints(st_exteriorring(the_geom)))::int),
   st_pointn(st_exteriorring(the_geom), (rand2.rand *
st_npoints(st_exteriorring(the_geom)))::int)
   )
   )
   ,rand3.rand
)
from insert_your_table_name_here,
(select random() as rand, generate_series(1,1000) as point_number) as
rand1
JOIN (select random() as rand, generate_series(1,1000) as point_number)
as
rand2
   ON rand1.point_number = rand2.point_number
JOIN (select random() as rand, generate_series(1,1000) as point_number)
as
rand3
   ON rand2.point_number = rand3.point_number
WHERE st_geometrytype(
   st_intersection(
   the_geom,
   st_makeline(
   st_pointn(st_exteriorring(the_geom), (rand1.rand *
st_npoints(st_exteriorring(the_geom)))::int),
   st_pointn(st_exteriorring(the_geom), (rand2.rand *
st_npoints(st_exteriorring(the_geom)))::int)
   )
   )
) = 'ST_LineString'
AND oid = 5030 /* Enter your own OID here */
limit 100




 

-Original Message-
From: postgis-users-boun...@postgis.refractions.net
[mailto:postgis-users-boun...@postgis.refractions.net] On
Behalf Of Martin Davis
Sent: Thursday, May 06, 2010 8:56 AM
To: John Abraham; postgis-users@postgis.refractions.net; Martin Davis
Subject: Re: [postgis-users] Dot Density idea


I was thinking the same thing!

strk wrote:

   

ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
function indeed. Sounds like a good job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:


 

One of the things I miss about using ESRI's GIS is the

   

ability to do

   

dot-density maps.  Within a polygon, the number of dots is

   

proportional to a value, and the dots are randomly placed.  I
find it useful to be able to present several data values at
once (e.g. blue dots for population, red dots for employment).

   

I also find that it is a more intuitive way of scaling for

   

zone size

   

than dividing the value by the area of the zone.  That is,

   

the count

   

of the dots represents the actual number, but the density

   

of the dots

   

represents the density of the number.  So I don't have to decide
whether to divide the value by the area of the polygon to plot
density: both the absolute number and the density are

   

easily visible.

   

Since my open-source GIS viewing systems (mostly QGIS and

   

Mapserver)

   

won't plot dot-density, I've done without.

But today I realized that I can build these on the server

   

instead.  I

   

can generate random points within the bounding-box of the polygon,
throwing out those that aren't contained within the polygon,
repeating until I have enough.  Then I can save these points as a
separate layer, and display this layer using almost any desktop or
web based viewer!

Has anyone done this?  Can I do it in SQL or do I need to write
something in PL/pgsql?

--
John Abraham

PS I just bought the Postgis In Action book; enjoying it so far.
__

Re: [postgis-users] Dot Density idea

2010-05-06 Thread Paul Ramsey
Even-yet-random :) nice requirement. How about just starting with a
regular grid and then perturbing the elements randomly with a radius
of a cell size? You can use the area of the polygon and number of
needed points to calculate the appropriate cell size and go from
there.

P

On Thu, May 6, 2010 at 10:28 AM, Martin Davis  wrote:
> Good point about the need for even distribution of the points. That seems
> like a whole lot harder to code than simply randomly placing points in a
> polygon.  Does anyone have any pointers to algorithms for producing this
> effect?
>
> George Silva wrote:
>>
>> The really big problem with dot density is that dots can overlap
>> themselves,
>> masking the real number, so if anything will be developed in this area,
>> the
>> points should be
>>
>> A) evenly distributed
>> or
>> B) randomly distributed, but with some sort of "colision" tests, so there
>> is
>> no or little overlap.
>>
>> This is a interesting idea, especially if we could make a materialized
>> view
>> with those points, which could be added to GIS software for presentation.
>>
>> George
>>
>> On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley <
>> ssuffic...@rov.sbcounty.gov> wrote:
>>
>>
>>>
>>> Looks nasty, but it might work:
>>>
>>> select
>>> st_line_interpolate_point(
>>>       st_intersection(
>>>               the_geom,
>>>               st_makeline(
>>>                       st_pointn(st_exteriorring(the_geom), (rand1.rand *
>>> st_npoints(st_exteriorring(the_geom)))::int),
>>>                       st_pointn(st_exteriorring(the_geom), (rand2.rand *
>>> st_npoints(st_exteriorring(the_geom)))::int)
>>>               )
>>>       )
>>>       ,rand3.rand
>>> )
>>> from insert_your_table_name_here,
>>> (select random() as rand, generate_series(1,1000) as point_number) as
>>> rand1
>>> JOIN (select random() as rand, generate_series(1,1000) as point_number)
>>> as
>>> rand2
>>>       ON rand1.point_number = rand2.point_number
>>> JOIN (select random() as rand, generate_series(1,1000) as point_number)
>>> as
>>> rand3
>>>       ON rand2.point_number = rand3.point_number
>>> WHERE st_geometrytype(
>>>       st_intersection(
>>>               the_geom,
>>>               st_makeline(
>>>                       st_pointn(st_exteriorring(the_geom), (rand1.rand *
>>> st_npoints(st_exteriorring(the_geom)))::int),
>>>                       st_pointn(st_exteriorring(the_geom), (rand2.rand *
>>> st_npoints(st_exteriorring(the_geom)))::int)
>>>               )
>>>       )
>>> ) = 'ST_LineString'
>>> AND oid = 5030 /* Enter your own OID here */
>>> limit 100
>>>
>>>
>>>
>>>
>>>>
>>>> -Original Message-
>>>> From: postgis-users-boun...@postgis.refractions.net
>>>> [mailto:postgis-users-boun...@postgis.refractions.net] On
>>>> Behalf Of Martin Davis
>>>> Sent: Thursday, May 06, 2010 8:56 AM
>>>> To: John Abraham; postgis-users@postgis.refractions.net; Martin Davis
>>>> Subject: Re: [postgis-users] Dot Density idea
>>>>
>>>>
>>>> I was thinking the same thing!
>>>>
>>>> strk wrote:
>>>>
>>>>>
>>>>> ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
>>>>> function indeed. Sounds like a good job for GEOS/JTS.
>>>>>
>>>>> --strk;
>>>>>
>>>>> On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
>>>>>
>>>>>
>>>>>>
>>>>>> One of the things I miss about using ESRI's GIS is the
>>>>>>
>>>>
>>>> ability to do
>>>>
>>>>>>
>>>>>> dot-density maps.  Within a polygon, the number of dots is
>>>>>>
>>>>
>>>> proportional to a value, and the dots are randomly placed.  I
>>>> find it useful to be able to present several data values at
>>>> once (e.g. blue dots for population, red dots for employment).
>>>>
>>>>>>
>>>>>> I also find that it is a more intuitive way of scaling for
>>>>>>
>>>>
>>>> zone size
>>>>
>>>>>>
>>>>&g

Re: [postgis-users] Dot Density idea

2010-05-06 Thread George Silva
Using St_SnapToGrid is a way to do it. A simple algorithm could calculate
the ideal distance between points depending on the number of resulting
points and then just place them in correct place.

The way to do it is to inform attribute and the value of each dot. On the
same note, a proportional symbols representation could be done, but that can
be very tricky, since building the actual circles could give you extensive
overlap, and they should change according to scale, so I guess that could be
done by software. PostGIS could generate a view using the centroid for
proportional symbols using a point a softwares need to take care of the
representation.

George

On Thu, May 6, 2010 at 2:28 PM, Martin Davis wrote:

> Good point about the need for even distribution of the points. That seems
> like a whole lot harder to code than simply randomly placing points in a
> polygon.  Does anyone have any pointers to algorithms for producing this
> effect?
>
> George Silva wrote:
>
>> The really big problem with dot density is that dots can overlap
>> themselves,
>> masking the real number, so if anything will be developed in this area,
>> the
>> points should be
>>
>> A) evenly distributed
>> or
>> B) randomly distributed, but with some sort of "colision" tests, so there
>> is
>> no or little overlap.
>>
>> This is a interesting idea, especially if we could make a materialized
>> view
>> with those points, which could be added to GIS software for presentation.
>>
>> George
>>
>> On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley <
>> ssuffic...@rov.sbcounty.gov> wrote:
>>
>>
>>
>>> Looks nasty, but it might work:
>>>
>>> select
>>> st_line_interpolate_point(
>>>   st_intersection(
>>>   the_geom,
>>>   st_makeline(
>>>   st_pointn(st_exteriorring(the_geom), (rand1.rand *
>>> st_npoints(st_exteriorring(the_geom)))::int),
>>>   st_pointn(st_exteriorring(the_geom), (rand2.rand *
>>> st_npoints(st_exteriorring(the_geom)))::int)
>>>   )
>>>   )
>>>   ,rand3.rand
>>> )
>>> from insert_your_table_name_here,
>>> (select random() as rand, generate_series(1,1000) as point_number) as
>>> rand1
>>> JOIN (select random() as rand, generate_series(1,1000) as point_number)
>>> as
>>> rand2
>>>   ON rand1.point_number = rand2.point_number
>>> JOIN (select random() as rand, generate_series(1,1000) as point_number)
>>> as
>>> rand3
>>>   ON rand2.point_number = rand3.point_number
>>> WHERE st_geometrytype(
>>>   st_intersection(
>>>   the_geom,
>>>   st_makeline(
>>>   st_pointn(st_exteriorring(the_geom), (rand1.rand *
>>> st_npoints(st_exteriorring(the_geom)))::int),
>>>   st_pointn(st_exteriorring(the_geom), (rand2.rand *
>>> st_npoints(st_exteriorring(the_geom)))::int)
>>>   )
>>>   )
>>> ) = 'ST_LineString'
>>> AND oid = 5030 /* Enter your own OID here */
>>> limit 100
>>>
>>>
>>>
>>>
>>>
>>>> -Original Message-
>>>> From: postgis-users-boun...@postgis.refractions.net
>>>> [mailto:postgis-users-boun...@postgis.refractions.net] On
>>>> Behalf Of Martin Davis
>>>> Sent: Thursday, May 06, 2010 8:56 AM
>>>> To: John Abraham; postgis-users@postgis.refractions.net; Martin Davis
>>>> Subject: Re: [postgis-users] Dot Density idea
>>>>
>>>>
>>>> I was thinking the same thing!
>>>>
>>>> strk wrote:
>>>>
>>>>
>>>>> ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
>>>>> function indeed. Sounds like a good job for GEOS/JTS.
>>>>>
>>>>> --strk;
>>>>>
>>>>> On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
>>>>>
>>>>>
>>>>>
>>>>>> One of the things I miss about using ESRI's GIS is the
>>>>>>
>>>>>>
>>>>> ability to do
>>>>
>>>>
>>>>> dot-density maps.  Within a polygon, the number of dots is
>>>>>>
>>>>>>
>>>>> proportional to a value, and the dots are randomly placed.  I
>>>> find it usefu

Re: [postgis-users] Dot Density idea

2010-05-06 Thread Martin Davis
Good point about the need for even distribution of the points. That 
seems like a whole lot harder to code than simply randomly placing 
points in a polygon.  Does anyone have any pointers to algorithms for 
producing this effect?


George Silva wrote:

The really big problem with dot density is that dots can overlap themselves,
masking the real number, so if anything will be developed in this area, the
points should be

A) evenly distributed
or
B) randomly distributed, but with some sort of "colision" tests, so there is
no or little overlap.

This is a interesting idea, especially if we could make a materialized view
with those points, which could be added to GIS software for presentation.

George

On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley <
ssuffic...@rov.sbcounty.gov> wrote:

  

Looks nasty, but it might work:

select
st_line_interpolate_point(
   st_intersection(
   the_geom,
   st_makeline(
   st_pointn(st_exteriorring(the_geom), (rand1.rand *
st_npoints(st_exteriorring(the_geom)))::int),
   st_pointn(st_exteriorring(the_geom), (rand2.rand *
st_npoints(st_exteriorring(the_geom)))::int)
   )
   )
   ,rand3.rand
)
from insert_your_table_name_here,
(select random() as rand, generate_series(1,1000) as point_number) as rand1
JOIN (select random() as rand, generate_series(1,1000) as point_number) as
rand2
   ON rand1.point_number = rand2.point_number
JOIN (select random() as rand, generate_series(1,1000) as point_number) as
rand3
   ON rand2.point_number = rand3.point_number
WHERE st_geometrytype(
   st_intersection(
   the_geom,
   st_makeline(
   st_pointn(st_exteriorring(the_geom), (rand1.rand *
st_npoints(st_exteriorring(the_geom)))::int),
   st_pointn(st_exteriorring(the_geom), (rand2.rand *
st_npoints(st_exteriorring(the_geom)))::int)
   )
   )
) = 'ST_LineString'
AND oid = 5030 /* Enter your own OID here */
limit 100





-Original Message-
From: postgis-users-boun...@postgis.refractions.net
[mailto:postgis-users-boun...@postgis.refractions.net] On
Behalf Of Martin Davis
Sent: Thursday, May 06, 2010 8:56 AM
To: John Abraham; postgis-users@postgis.refractions.net; Martin Davis
Subject: Re: [postgis-users] Dot Density idea


I was thinking the same thing!

strk wrote:
  

ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
function indeed. Sounds like a good job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:



One of the things I miss about using ESRI's GIS is the
  

ability to do
  

dot-density maps.  Within a polygon, the number of dots is
  

proportional to a value, and the dots are randomly placed.  I
find it useful to be able to present several data values at
once (e.g. blue dots for population, red dots for employment).
  

I also find that it is a more intuitive way of scaling for
  

zone size
  

than dividing the value by the area of the zone.  That is,
  

the count
  

of the dots represents the actual number, but the density
  

of the dots
  

represents the density of the number.  So I don't have to decide
whether to divide the value by the area of the polygon to plot
density: both the absolute number and the density are
  

easily visible.
  

Since my open-source GIS viewing systems (mostly QGIS and
  

Mapserver)
  

won't plot dot-density, I've done without.

But today I realized that I can build these on the server
  

instead.  I
  

can generate random points within the bounding-box of the polygon,
throwing out those that aren't contained within the polygon,
repeating until I have enough.  Then I can save these points as a
separate layer, and display this layer using almost any desktop or
web based viewer!

Has anyone done this?  Can I do it in SQL or do I need to write
something in PL/pgsql?

--
John Abraham

PS I just bought the Postgis In Action book; enjoying it so far.
___
postgis-users mailing list postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

  


--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

  

___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users






  



___
postgis-users mail

Re: [postgis-users] Dot Density idea

2010-05-06 Thread George Silva
The really big problem with dot density is that dots can overlap themselves,
masking the real number, so if anything will be developed in this area, the
points should be

A) evenly distributed
or
B) randomly distributed, but with some sort of "colision" tests, so there is
no or little overlap.

This is a interesting idea, especially if we could make a materialized view
with those points, which could be added to GIS software for presentation.

George

On Thu, May 6, 2010 at 1:53 PM, Sufficool, Stanley <
ssuffic...@rov.sbcounty.gov> wrote:

> Looks nasty, but it might work:
>
> select
> st_line_interpolate_point(
>st_intersection(
>the_geom,
>st_makeline(
>st_pointn(st_exteriorring(the_geom), (rand1.rand *
> st_npoints(st_exteriorring(the_geom)))::int),
>st_pointn(st_exteriorring(the_geom), (rand2.rand *
> st_npoints(st_exteriorring(the_geom)))::int)
>)
>)
>,rand3.rand
> )
> from insert_your_table_name_here,
> (select random() as rand, generate_series(1,1000) as point_number) as rand1
> JOIN (select random() as rand, generate_series(1,1000) as point_number) as
> rand2
>ON rand1.point_number = rand2.point_number
> JOIN (select random() as rand, generate_series(1,1000) as point_number) as
> rand3
>ON rand2.point_number = rand3.point_number
> WHERE st_geometrytype(
>st_intersection(
>the_geom,
>st_makeline(
>st_pointn(st_exteriorring(the_geom), (rand1.rand *
> st_npoints(st_exteriorring(the_geom)))::int),
>st_pointn(st_exteriorring(the_geom), (rand2.rand *
> st_npoints(st_exteriorring(the_geom)))::int)
>)
>)
> ) = 'ST_LineString'
> AND oid = 5030 /* Enter your own OID here */
> limit 100
>
>
>
> >-Original Message-
> >From: postgis-users-boun...@postgis.refractions.net
> >[mailto:postgis-users-boun...@postgis.refractions.net] On
> >Behalf Of Martin Davis
> >Sent: Thursday, May 06, 2010 8:56 AM
> >To: John Abraham; postgis-users@postgis.refractions.net; Martin Davis
> >Subject: Re: [postgis-users] Dot Density idea
> >
> >
> >I was thinking the same thing!
> >
> >strk wrote:
> >> ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
> >> function indeed. Sounds like a good job for GEOS/JTS.
> >>
> >> --strk;
> >>
> >> On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
> >>
> >>> One of the things I miss about using ESRI's GIS is the
> >ability to do
> >>> dot-density maps.  Within a polygon, the number of dots is
> >proportional to a value, and the dots are randomly placed.  I
> >find it useful to be able to present several data values at
> >once (e.g. blue dots for population, red dots for employment).
> >>>
> >>> I also find that it is a more intuitive way of scaling for
> >zone size
> >>> than dividing the value by the area of the zone.  That is,
> >the count
> >>> of the dots represents the actual number, but the density
> >of the dots
> >>> represents the density of the number.  So I don't have to decide
> >>> whether to divide the value by the area of the polygon to plot
> >>> density: both the absolute number and the density are
> >easily visible.
> >>>
> >>> Since my open-source GIS viewing systems (mostly QGIS and
> >Mapserver)
> >>> won't plot dot-density, I've done without.
> >>>
> >>> But today I realized that I can build these on the server
> >instead.  I
> >>> can generate random points within the bounding-box of the polygon,
> >>> throwing out those that aren't contained within the polygon,
> >>> repeating until I have enough.  Then I can save these points as a
> >>> separate layer, and display this layer using almost any desktop or
> >>> web based viewer!
> >>>
> >>> Has anyone done this?  Can I do it in SQL or do I need to write
> >>> something in PL/pgsql?
> >>>
> >>> --
> >>> John Abraham
> >>>
> >>> PS I just bought the Postgis In Action book; enjoying it so far.
> >>> ___
> >>> postgis-users mailing list postgis-users@postgis.refractions.net
> >>> http://postgis.refractions.net/mailman/listinfo/postgis-users
> >>>
> >>
> >>
> >
> >--
> >Martin Davis
> >Senior Technical Architect
> >Refractions Research, Inc.
> >(250) 383-3022
> >
> >___
> >postgis-users mailing list
> >postgis-users@postgis.refractions.net
> >http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
> ___
> postgis-users mailing list
> postgis-users@postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>



-- 
George R. C. Silva

Desenvolvimento em GIS
http://blog.geoprocessamento.net
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] Dot Density idea

2010-05-06 Thread Sufficool, Stanley
Looks nasty, but it might work:

select
st_line_interpolate_point(
st_intersection(
the_geom,
st_makeline(
st_pointn(st_exteriorring(the_geom), (rand1.rand * 
st_npoints(st_exteriorring(the_geom)))::int),
st_pointn(st_exteriorring(the_geom), (rand2.rand * 
st_npoints(st_exteriorring(the_geom)))::int)
)
)
,rand3.rand
)
from insert_your_table_name_here,
(select random() as rand, generate_series(1,1000) as point_number) as rand1
JOIN (select random() as rand, generate_series(1,1000) as point_number) as rand2
ON rand1.point_number = rand2.point_number
JOIN (select random() as rand, generate_series(1,1000) as point_number) as rand3
ON rand2.point_number = rand3.point_number
WHERE st_geometrytype(
st_intersection(
the_geom,
st_makeline(
st_pointn(st_exteriorring(the_geom), (rand1.rand * 
st_npoints(st_exteriorring(the_geom)))::int),
st_pointn(st_exteriorring(the_geom), (rand2.rand * 
st_npoints(st_exteriorring(the_geom)))::int)
)
)
) = 'ST_LineString'
AND oid = 5030 /* Enter your own OID here */
limit 100



>-Original Message-
>From: postgis-users-boun...@postgis.refractions.net
>[mailto:postgis-users-boun...@postgis.refractions.net] On
>Behalf Of Martin Davis
>Sent: Thursday, May 06, 2010 8:56 AM
>To: John Abraham; postgis-users@postgis.refractions.net; Martin Davis
>Subject: Re: [postgis-users] Dot Density idea
>
>
>I was thinking the same thing!
>
>strk wrote:
>> ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
>> function indeed. Sounds like a good job for GEOS/JTS.
>>
>> --strk;
>>
>> On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
>>
>>> One of the things I miss about using ESRI's GIS is the
>ability to do
>>> dot-density maps.  Within a polygon, the number of dots is
>proportional to a value, and the dots are randomly placed.  I
>find it useful to be able to present several data values at
>once (e.g. blue dots for population, red dots for employment).
>>>
>>> I also find that it is a more intuitive way of scaling for
>zone size
>>> than dividing the value by the area of the zone.  That is,
>the count
>>> of the dots represents the actual number, but the density
>of the dots
>>> represents the density of the number.  So I don't have to decide
>>> whether to divide the value by the area of the polygon to plot
>>> density: both the absolute number and the density are
>easily visible.
>>>
>>> Since my open-source GIS viewing systems (mostly QGIS and
>Mapserver)
>>> won't plot dot-density, I've done without.
>>>
>>> But today I realized that I can build these on the server
>instead.  I
>>> can generate random points within the bounding-box of the polygon,
>>> throwing out those that aren't contained within the polygon,
>>> repeating until I have enough.  Then I can save these points as a
>>> separate layer, and display this layer using almost any desktop or
>>> web based viewer!
>>>
>>> Has anyone done this?  Can I do it in SQL or do I need to write
>>> something in PL/pgsql?
>>>
>>> --
>>> John Abraham
>>>
>>> PS I just bought the Postgis In Action book; enjoying it so far.
>>> ___
>>> postgis-users mailing list postgis-users@postgis.refractions.net
>>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>>
>>
>>
>
>--
>Martin Davis
>Senior Technical Architect
>Refractions Research, Inc.
>(250) 383-3022
>
>___
>postgis-users mailing list
>postgis-users@postgis.refractions.net
>http://postgis.refractions.net/mailman/listinfo/postgis-users
>
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] Dot Density idea

2010-05-06 Thread Martin Davis

I was thinking the same thing!

strk wrote:

ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
function indeed. Sounds like a good job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
  
One of the things I miss about using ESRI's GIS is the ability to do dot-density maps.  Within a polygon, the number of dots is proportional to a value, and the dots are randomly placed.  I find it useful to be able to present several data values at once (e.g. blue dots for population, red dots for employment).  


I also find that it is a more intuitive way of scaling for zone size than 
dividing the value by the area of the zone.  That is, the count of the dots 
represents the actual number, but the density of the dots represents the 
density of the number.  So I don't have to decide whether to divide the value 
by the area of the polygon to plot density: both the absolute number and the 
density are easily visible.

Since my open-source GIS viewing systems (mostly QGIS and Mapserver) won't plot 
dot-density, I've done without.

But today I realized that I can build these on the server instead.  I can 
generate random points within the bounding-box of the polygon, throwing out 
those that aren't contained within the polygon, repeating until I have enough.  
Then I can save these points as a separate layer, and display this layer using 
almost any desktop or web based viewer!

Has anyone done this?  Can I do it in SQL or do I need to write something in 
PL/pgsql?

--
John Abraham

PS I just bought the Postgis In Action book; enjoying it so far.
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



  


--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] Dot Density idea

2010-05-06 Thread Ben Madin
I have used an R function before (using maptools package) to do something 
similar, but I can't remember the details, so I would be considering looking at 
PL/R.

cheers

Ben



On 06/05/2010, at 15:40 , strk wrote:

> On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
>> One of the things I miss about using ESRI's GIS is the ability to do 
>> dot-density maps.  Within a polygon, the number of dots is proportional to a 
>> value, and the dots are randomly placed.  I find it useful to be able to 
>> present several data values at once (e.g. blue dots for population, red dots 
>> for employment).  
>> 
>> I also find that it is a more intuitive way of scaling for zone size than 
>> dividing the value by the area of the zone.  That is, the count of the dots 
>> represents the actual number, but the density of the dots represents the 
>> density of the number.  So I don't have to decide whether to divide the 
>> value by the area of the polygon to plot density: both the absolute number 
>> and the density are easily visible.
>> 
>> Since my open-source GIS viewing systems (mostly QGIS and Mapserver) won't 
>> plot dot-density, I've done without.
>> 
>> But today I realized that I can build these on the server instead.  I can 
>> generate random points within the bounding-box of the polygon, throwing out 
>> those that aren't contained within the polygon, repeating until I have 
>> enough.  Then I can save these points as a separate layer, and display this 
>> layer using almost any desktop or web based viewer!
>> 
>> Has anyone done this?  Can I do it in SQL or do I need to write something in 
>> PL/pgsql?
> 
> PL/pgsql would be easier than SQL at the minimum.
> Still, a C implementation would likely be better, for speed reasons.
> 
> --strk; 
> 
>  ()   Free GIS & Flash consultant/developer
>  /\   http://strk.keybit.net/services.html
> ___
> postgis-users mailing list
> postgis-users@postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users

___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] Dot Density idea

2010-05-06 Thread David Fawcett
Not quite the same, but Carson Farmer's fTools plugins for QGIS
include the functionality to create random points (by count or
density) inside of a polygon.

http://www.ftools.ca/plugins.html  Nothing specific about this
functionality on this page, you need to look at the actual plugins in
QGIS.

David.



On Thu, May 6, 2010 at 4:10 AM, strk  wrote:
> ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
> function indeed. Sounds like a good job for GEOS/JTS.
>
> --strk;
>
> On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
>> One of the things I miss about using ESRI's GIS is the ability to do 
>> dot-density maps.  Within a polygon, the number of dots is proportional to a 
>> value, and the dots are randomly placed.  I find it useful to be able to 
>> present several data values at once (e.g. blue dots for population, red dots 
>> for employment).
>>
>> I also find that it is a more intuitive way of scaling for zone size than 
>> dividing the value by the area of the zone.  That is, the count of the dots 
>> represents the actual number, but the density of the dots represents the 
>> density of the number.  So I don't have to decide whether to divide the 
>> value by the area of the polygon to plot density: both the absolute number 
>> and the density are easily visible.
>>
>> Since my open-source GIS viewing systems (mostly QGIS and Mapserver) won't 
>> plot dot-density, I've done without.
>>
>> But today I realized that I can build these on the server instead.  I can 
>> generate random points within the bounding-box of the polygon, throwing out 
>> those that aren't contained within the polygon, repeating until I have 
>> enough.  Then I can save these points as a separate layer, and display this 
>> layer using almost any desktop or web based viewer!
>>
>> Has anyone done this?  Can I do it in SQL or do I need to write something in 
>> PL/pgsql?
>>
>> --
>> John Abraham
>>
>> PS I just bought the Postgis In Action book; enjoying it so far.
>> ___
>> postgis-users mailing list
>> postgis-users@postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> --
>
>  ()   Free GIS & Flash consultant/developer
>  /\   http://strk.keybit.net/services.html
> ___
> postgis-users mailing list
> postgis-users@postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] Dot Density idea

2010-05-06 Thread strk
ST_RandomPoinsOnSurface(geometry, numpoints) would be an interesting
function indeed. Sounds like a good job for GEOS/JTS.

--strk;

On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
> One of the things I miss about using ESRI's GIS is the ability to do 
> dot-density maps.  Within a polygon, the number of dots is proportional to a 
> value, and the dots are randomly placed.  I find it useful to be able to 
> present several data values at once (e.g. blue dots for population, red dots 
> for employment).  
> 
> I also find that it is a more intuitive way of scaling for zone size than 
> dividing the value by the area of the zone.  That is, the count of the dots 
> represents the actual number, but the density of the dots represents the 
> density of the number.  So I don't have to decide whether to divide the value 
> by the area of the polygon to plot density: both the absolute number and the 
> density are easily visible.
> 
> Since my open-source GIS viewing systems (mostly QGIS and Mapserver) won't 
> plot dot-density, I've done without.
> 
> But today I realized that I can build these on the server instead.  I can 
> generate random points within the bounding-box of the polygon, throwing out 
> those that aren't contained within the polygon, repeating until I have 
> enough.  Then I can save these points as a separate layer, and display this 
> layer using almost any desktop or web based viewer!
> 
> Has anyone done this?  Can I do it in SQL or do I need to write something in 
> PL/pgsql?
> 
> --
> John Abraham
> 
> PS I just bought the Postgis In Action book; enjoying it so far.
> ___
> postgis-users mailing list
> postgis-users@postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users

-- 

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users


Re: [postgis-users] Dot Density idea

2010-05-06 Thread strk
On Mon, May 03, 2010 at 10:49:32PM -0600, John Abraham wrote:
> One of the things I miss about using ESRI's GIS is the ability to do 
> dot-density maps.  Within a polygon, the number of dots is proportional to a 
> value, and the dots are randomly placed.  I find it useful to be able to 
> present several data values at once (e.g. blue dots for population, red dots 
> for employment).  
> 
> I also find that it is a more intuitive way of scaling for zone size than 
> dividing the value by the area of the zone.  That is, the count of the dots 
> represents the actual number, but the density of the dots represents the 
> density of the number.  So I don't have to decide whether to divide the value 
> by the area of the polygon to plot density: both the absolute number and the 
> density are easily visible.
> 
> Since my open-source GIS viewing systems (mostly QGIS and Mapserver) won't 
> plot dot-density, I've done without.
> 
> But today I realized that I can build these on the server instead.  I can 
> generate random points within the bounding-box of the polygon, throwing out 
> those that aren't contained within the polygon, repeating until I have 
> enough.  Then I can save these points as a separate layer, and display this 
> layer using almost any desktop or web based viewer!
> 
> Has anyone done this?  Can I do it in SQL or do I need to write something in 
> PL/pgsql?

PL/pgsql would be easier than SQL at the minimum.
Still, a C implementation would likely be better, for speed reasons.

--strk; 

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html
___
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users