[postgis-users] Creating a grid purely in SQL

Paragon Corporation lr at pcorp.us
Mon Mar 7 20:50:55 PST 2011


Puneet,

Something like this? This is a bit old.  We have some example in our book
using Common Table Expressions (CTEs) in chapter 8.  You can download the
code to see those as well.  http://www.postgis.us/chapter_08

http://www.bostongis.com/postgis_translate.snippet

As far as storing two geometry columns in one table.  Yes -- Just do it by
creating another column that is geometry (or using AddGeometryColumn
function).  We do it all the time.

Leo
http://www.postgis.us

 

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Mr.
Puneet Kishor
Sent: Monday, March 07, 2011 11:13 PM
To: PostGIS Users Discussion
Subject: [postgis-users] Creating a grid purely in SQL

Given a top-left starting point [ulx, uly], and a cell width 'w' and height
'h', is it possible to create a table entirely in SQL populated with rows
increasing from left to right up to X and top to bottom up to Y. The table
schema would be something like --

CREATE TABLE cells (
  cell_id INTEGER NOT NULL,
  xmid DOUBLE PRECISION,
  ymid DOUBLE PRECISION,
  the_geom GEOMETRY,
  CONSTRAINT cells_pkey PRIMARY KEY (cell_id) );

where xmid = (xmin + xmax) / 2 and ymid = (ymin + ymax) / 2, [xmin, ymin,
xmax, ymax] being the corners of each cell.

A bonus question -- is it possible to store two geometry columns in one
table? For example, if I wanted to store the geometry for both the center
points [xmin, ymid] as well as the box [xmin, ymin, xmax, ymax], would that
be possible? Would that even be recommended (for example, to speed up
queries/drawing, etc.).

Puneet.
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users





More information about the postgis-users mailing list