[postgis-users] Grid of points inside Polygon

James David Smith james.david.smith at gmail.com
Mon Nov 11 02:30:13 PST 2013


Hi all,

Would appreciate some advice on the best way to accomplish this please.

Our situation is that we have a single polygon which has been created
by buffering all of the major roads in the UK. Projection is OSGB36
(27700). Obviously it's quite a big polygon.

-->  SELECT st_area(geom) FROM roadbufferunion;
     st_area
------------------
 77228753220.8271

What we now want to do is create a regular grid of 20 metre x 20 metre
points instead the polygon area. So we wrote this function (based on
some googling, apologies for not being able to recall the exact person
who originally wrote it):

CREATE OR REPLACE FUNCTION makegrid(geometry, integer, integer)
RETURNS geometry AS
'SELECT ST_Collect(st_setsrid(ST_POINT(x,y),$3)) FROM
  generate_series(53320::int, 667380::int,$2) as x
  ,generate_series(7780::int, 1226580::int,$2) as y
where st_intersects($1,st_setsrid(ST_POINT(x,y),$3))'
LANGUAGE sql

and we then run this by doing the following:

SELECT st_x((ST_Dump(makegrid(geom, 20, 27700))).geom) as x,
st_y((ST_Dump(makegrid(geom, 20, 27700))).geom) as y INTO grid_points
from roadbufferunion;

However after over 2 days of the query running on a pretty powerful
linux cluster, we still have no result.  I'm not sure if it is
actually running or not to be honest.

Does the query look right?
Any ideas how we can make it run quicker?

Thanks

James


More information about the postgis-users mailing list