[postgis-users] How can I divide up a region into a grid of rectangles?

Roxanne Reid-Bennett rox at tara-lu.com
Thu Nov 10 20:19:54 PST 2011


On 11/10/2011 7:37 PM, MarkW wrote:
> This is kind of a simplistic approach maybe - because a simple grid
> doesn't have to intersect with municipal features. But could you
> simply decide on a rounding level that would give you what you wanted?
> Round the lat/lons to a certain decimal level, then count by / group
> on  those rounded lat/lons? Each one could represent centroid or a
> corner of a grid.
>

Giving a very simplistic overview... Our current application creates "a 
grid" by using
ST_SnapToGrid to collapse multiple points to one "standard" point. It 
then uses a
polygon drawn on a map to create a "boundary".  Given a list of points 
and a polygon, using
point && polygon [with a gist index on each] for speed
and ST_Intersects(point,polygon) for accuracy you can collect
whatever points are "in" the boundary ...

Given a pre-defined grid size...

If you don't want to hassle with boundaries right now, you can artificially
create all the grid points within your lat/lon range, assign them a
neighborhood, then look for "identical"
snapped to grid points in your data with a straight equality test for 
the join
to collect a count "in" a neighborhood.

Make sure you are working with the "right" (or at least same) SRIDs.

Roxanne






More information about the postgis-users mailing list