Guest User

Untitled

a guest
Dec 10th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. generate_series(floor(st_xmin($1))::int, ceiling(st_xmax($1))::int,$2) as x
  2. ,generate_series(floor(st_ymin($1))::int, ceiling(st_ymax($1))::int,$2) as y
  3.  
  4. SELECT ST_Collect(st_setsrid(ST_POINT(x/1000000::float,y/1000000::float),st_srid($1))) FROM
  5. generate_series(floor(st_xmin($1)*1000000)::int, ceiling(st_xmax($1)*1000000)::int,$2) as x ,
  6. generate_series(floor(st_ymin($1)*1000000)::int, ceiling(st_ymax($1)*1000000)::int,$2) as y
  7. WHERE st_intersects($1,ST_SetSRID(ST_POINT(x/1000000::float,y/1000000::float),ST_SRID($1)))
  8.  
  9. CREATE OR REPLACE FUNCTION makegrid(geometry, integer, integer)
  10. RETURNS geometry AS
  11. 'SELECT ST_Collect(st_setsrid(ST_POINT(x,y),$3)) FROM
  12. generate_series(floor(st_xmin($1))::int, ceiling(st_xmax($1))::int,$2) as x
  13. ,generate_series(floor(st_ymin($1))::int, ceiling(st_ymax($1))::int,$2) as y
  14. where st_intersects($1,st_setsrid(ST_POINT(x,y),$3))'
  15. LANGUAGE sql
  16.  
  17. SELECT (ST_Dump(makegrid(the_geom, 1000, 3857))).geom as the_geom from my_polygon_table
  18.  
  19. CREATE OR REPLACE FUNCTION makegrid(geometry, integer, integer)
  20. RETURNS geometry AS
  21.  
  22.  
  23.  
  24. /*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*/
  25.  
  26. '
  27. SELECT ST_Collect(st_setsrid(ST_POINT(x/$3::float,y/$3::float),st_srid($1))) FROM
  28. generate_series(
  29. (round(floor(st_xmin($1)*$3)::int/$2)*$2)::int,
  30. (round(ceiling(st_xmax($1)*$3)::int/$2)*$2)::int,
  31. $2) as x ,
  32. generate_series(
  33. (round(floor(st_ymin($1)*$3)::int/$2)*$2)::int,
  34. (round(ceiling(st_ymax($1)*$3)::int/$2)*$2)::int,
  35. $2) as y
  36. WHERE st_intersects($1,ST_SetSRID(ST_POINT(x/$3::float,y/$3::float),ST_SRID($1)))
  37. '
  38.  
  39. LANGUAGE sql
  40.  
  41. SELECT (ST_PixelAsCentroids(ST_AsRaster(the_geom,1000.0,1000.0))).geom
  42. FROM the_polygon
Add Comment
Please, Sign In to add comment