[postgis-users] Dot Density idea

pcreso at pcreso.com pcreso at pcreso.com
Thu May 6 11:57:59 PDT 2010


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 <mbdavis at refractions.net> wrote:

> From: Martin Davis <mbdavis at refractions.net>
> Subject: Re: [postgis-users] Dot Density idea
> To: "PostGIS Users Discussion" <postgis-users at postgis.refractions.net>
> 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<mbdavis at refractions.net> 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<
> >>>> ssufficool at 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-bounces at postgis.refractions.net
> >>>>>> [mailto:postgis-users-bounces at postgis.refractions.net]
> On
> >>>>>> Behalf Of Martin Davis
> >>>>>> Sent: Thursday, May 06, 2010 8:56
> AM
> >>>>>> To: John Abraham; postgis-users at 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 at 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 at postgis.refractions.net
> >>>>>> http://postgis.refractions.net/mailman/listinfo/postgis-users
> >>>>>> 
> >>>>>> 
> >>>>>>         
>   
> >>>>>
> _______________________________________________
> >>>>> postgis-users mailing list
> >>>>> postgis-users at postgis.refractions.net
> >>>>> http://postgis.refractions.net/mailman/listinfo/postgis-users
> >>>>> 
> >>>>> 
> >>>>>          
> >>>> 
> >>>> 
> >>>>   ------------------------------------------------------------------------
> 
> >>>> 
> >>>>
> _______________________________________________
> >>>> postgis-users mailing list
> >>>> postgis-users at 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 at postgis.refractions.net
> >>> http://postgis.refractions.net/mailman/listinfo/postgis-users
> >>> 
> >>>      
> >> _______________________________________________
> >> postgis-users mailing list
> >> postgis-users at postgis.refractions.net
> >> http://postgis.refractions.net/mailman/listinfo/postgis-users
> >>    
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users at 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 at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
> 



More information about the postgis-users mailing list