[postgis-users] Creating a grid purely in SQL

Andreas Forø Tollefsen andreasft at gmail.com
Tue Mar 8 00:55:27 PST 2011


Hi Puneet,

I used Python to create a list of centroid coordinates based on the
specified size of each cell, then i used the ST_Envelope to create the walls
of each grid cell.
Like this:
UPDATE priogrid SET cell=geometry(ST_MakeEnvelope(xcoord-"+str(xhalf)+",
ycoord-"+str(yhalf)+", xcoord+"+str(xhalf)+", ycoord+"+str(yhalf)+", 4326));

2011/3/8 Paragon Corporation <lr at pcorp.us>

> I think uDig still has that problem last we checked, but I don't think QGIS
> does.  QGIS lets you pick the column.
>
> -----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:54 PM
> To: PostGIS Users Discussion
> Subject: Re: [postgis-users] Creating a grid purely in SQL
>
> Thanks Leo, for the code fragment.
>
> Re. storing multiple geometries in one column, I found the following caveat
> --
>
> [http://lists.refractions.net/pipermail/udig-users/2009-March/000553.html]
>
> Briefly, is it possible that programs such as QGIS/uDig, etc. would get
> confused about which column to draw? Does that concern still apply?
>
>
> On Mar 7, 2011, at 11:50 PM, Paragon Corporation wrote:
>
> > 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
> >
> >
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users at postgis.refractions.net
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20110308/81b85d13/attachment.html>


More information about the postgis-users mailing list