Escolar Documentos
Profissional Documentos
Cultura Documentos
1 of 4
http://spatialdbadvisor.com/postgis_tips_tricks/300/generating-a-grid-fi...
SpatialDB Advisor
Simon Greener, Independent GeoSpatial Solutions Architect
Home
Generating a Grid
I wrote an article on Gridding a PostGIS Geometry object a while back.
(fishnet) of points or
polygons for PostGIS I had cause, recently, to use a variation on this for the generation of an array of point objects for a geometry polygon,
so I wrote a version that also allows for the generation of a grid of polygons or points depending on a boolean
ST_Parallel
parameter.
for PostGIS
R based Delaunay
Triangulation Function
for PostGIS using the
deldir package
COGO: Converting
Decimal Degrees to
Degrees Minutes and
Seconds - and back
again (PostGIS)
COGO: Finding
centre and radius of a
curve defined by three
points (PostGIS)
Gridding a geometry
object (PostGIS)
FOSSLIC PostGIS presentations
Vectorization:
Exploding a linestring
or polygon into
individual vectors
in PostGIS
How to apply spatial
constraints to
PostGIS tables
Loading and
Processing GPX 1.1
files using
PostgreSQL XML
Converting Oracle
Optimized Rectangles
to PostGIS
Building polygons
from overlapping
linestrings
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
03-06-2015 18:07
2 of 4
requiring intersection
Loading Point Data
from a CSV File
in PostGIS
DMS2DD
for PostGIS
Implementing
Oracle's GetVertices
function in PostGIS
- ST_DumpPoints
Filtering Rings in
Polygon (PostGIS)
56.
57.
58.
59.
60.
61.
62.
63.
64.
http://spatialdbadvisor.com/postgis_tips_tricks/300/generating-a-grid-fi...
END Loop;
END;
$BODY$
LANGUAGE plpgsql IMMUTABLE
COST 100
ROWS 1000;
-- Assign ownership
ALTER FUNCTION ss.st_regulargrid(geometry, NUMERIC, NUMERIC, BOOLEAN)
OWNER TO postgres;
Result:
Result:
gcol grow
geomWKT
0
0
POLYGON ((0 0,0 20,20 20,20 0,0 0))
0
1
POLYGON ((0 20,0 40,20 40,20 20,0 20))
0
2
POLYGON ((0 40,0 60,20 60,20 40,0 40))
0
3
POLYGON ((0 60,0 80,20 80,20 60,0 60))
0
4
POLYGON ((0 80,0 100,20 100,20 80,0 80))
1
0
POLYGON ((20 0,20 20,40 20,40 0,20 0))
1
1
POLYGON ((20 20,20 40,40 40,40 20,20 20))
1
2
POLYGON ((20 40,20 60,40 60,40 40,20 40))
1
3
POLYGON ((20 60,20 80,40 80,40 60,20 60))
1
4
POLYGON ((20 80,20 100,40 100,40 80,20 80))
2
0
POLYGON ((40 0,40 20,60 20,60 0,40 0))
2
1
POLYGON ((40 20,40 40,60 40,60 20,40 20))
2
2
POLYGON ((40 40,40 60,60 60,60 40,40 40))
03-06-2015 18:07
3 of 4
2
2
3
3
3
3
3
4
4
4
4
4
3
4
0
1
2
3
4
0
1
2
3
4
http://spatialdbadvisor.com/postgis_tips_tricks/300/generating-a-grid-fi...
Visually.
Comment [2]
Hi,
A probably more efficient way of generating a grid (of point or polygons) would be to use the generate_series
postgresql function.
You can find some similar use cases here :
http://gis.stackexchange.com/questions/4663/how-to-create-regular-point-grid-inside-a-polygon-in-postgis
or here :
http://www.bostongis.com/postgis_translate.snippet
The Postgis in Action book includes some great examples of this kind too.
vincent 11 September 2012, 13:42 #
Vincent,
Thanks for your comments.
I am aware of these techniques and have used them myself beforehand.
Sometimes in the spirit of horses for courses I use one or the other.
This technique is useful because it encapsulates the processing inside a function cleaning up the SQL from extraneous
detail that would otherwise complicate a SQLs declarative power in solving a problem.
03-06-2015 18:07