[postgis-users] grouing points on a grid

toni hernández toni at sigte.udg.edu
Wed Apr 10 23:29:59 PDT 2013


Thank you.
It worked great.
(sorry for the delay)

On 20/03/2013 13:23, Sandro Santilli wrote:
> On Wed, Mar 20, 2013 at 12:58:08PM +0100, toni hernández wrote:
>> Hello,
>>
>> I have 1 million points and I need to group them on a grid.
>> I also need to know how many of thouse points are on each cell of the grid.
>>
>>
>> My first thought was some SQL like this one:
>>
>> select count(*) as n , st_snaptogrid(geom, size)
>> from myPoints group by st_snaptogrid(geom, size)
>>
>> I thought as well about indexing myPoints table and even do some
>> clustering (Cluster geom on myPoints)
>>
>> Which is the best way to do this query?
> I think the SnapToGrid way is the fastest you can currently run
> to cluster your points. Index won't help as you're going to scan
> the whole table anyway.
>
> With limited performance penalty you may return something nicer
> than the snapped point, for example a convex hull or the centroid
> of the collection (to avoid a "griddy" look).
>
> --strk;
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>



More information about the postgis-users mailing list