How to create, inside a polygon, a regular grid of point spaced x,y in postgis? Like the example:

|
How to create, inside a polygon, a regular grid of point spaced x,y in postgis? Like the example:
|
||||
|
|
You do that with generate_series. If you don't want to manually write where the grid is to start and stop, the easiest is to create a function. I have not tested the below properly, but I think it should work:
To use it you can do:
where the first argument is the polygon you want the grid in, and the second argument is the distance between the points in the grid. If you want one point per row you just use ST_Dump like:
HTH Nicklas |
||||
|
This algorithm should be fine:
where 'polygon' is the polygon and 'resolution' is the required grid resolution. To implement it in PostGIS, the following functions may be needed:
Good luck! |
||||
|
I have picked up Nicklas Avén makegrid function code and made it a bit more generic by reading and using the srid from the polygon geometry. Otherwise using a polygon with a defined srid, would give an error. The function:
To use the function is done exactly as Nicklas Avén wrote:
or if you want one point per row:
Hope this will be usefull for someone. Alex |
||||
|
|
|
So my fixed version:
Usage:
|
|||
|