Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- generate_series(floor(st_xmin($1))::int, ceiling(st_xmax($1))::int,$2) as x
- ,generate_series(floor(st_ymin($1))::int, ceiling(st_ymax($1))::int,$2) as y
- SELECT ST_Collect(st_setsrid(ST_POINT(x/1000000::float,y/1000000::float),st_srid($1))) FROM
- generate_series(floor(st_xmin($1)*1000000)::int, ceiling(st_xmax($1)*1000000)::int,$2) as x ,
- generate_series(floor(st_ymin($1)*1000000)::int, ceiling(st_ymax($1)*1000000)::int,$2) as y
- WHERE st_intersects($1,ST_SetSRID(ST_POINT(x/1000000::float,y/1000000::float),ST_SRID($1)))
- CREATE OR REPLACE FUNCTION makegrid(geometry, integer, integer)
- RETURNS geometry AS
- 'SELECT ST_Collect(st_setsrid(ST_POINT(x,y),$3)) FROM
- generate_series(floor(st_xmin($1))::int, ceiling(st_xmax($1))::int,$2) as x
- ,generate_series(floor(st_ymin($1))::int, ceiling(st_ymax($1))::int,$2) as y
- where st_intersects($1,st_setsrid(ST_POINT(x,y),$3))'
- LANGUAGE sql
- SELECT (ST_Dump(makegrid(the_geom, 1000, 3857))).geom as the_geom from my_polygon_table
- CREATE OR REPLACE FUNCTION makegrid(geometry, integer, integer)
- RETURNS geometry AS
- /*geometry column , integer: distance between points, integer: scale factor for distance (useful for wgs84, e.g. use there 50000 as distance and 1000000 as scale factor*/
- '
- SELECT ST_Collect(st_setsrid(ST_POINT(x/$3::float,y/$3::float),st_srid($1))) FROM
- generate_series(
- (round(floor(st_xmin($1)*$3)::int/$2)*$2)::int,
- (round(ceiling(st_xmax($1)*$3)::int/$2)*$2)::int,
- $2) as x ,
- generate_series(
- (round(floor(st_ymin($1)*$3)::int/$2)*$2)::int,
- (round(ceiling(st_ymax($1)*$3)::int/$2)*$2)::int,
- $2) as y
- WHERE st_intersects($1,ST_SetSRID(ST_POINT(x/$3::float,y/$3::float),ST_SRID($1)))
- '
- LANGUAGE sql
- SELECT (ST_PixelAsCentroids(ST_AsRaster(the_geom,1000.0,1000.0))).geom
- FROM the_polygon
Add Comment
Please, Sign In to add comment