Hi Pierre,<br>Thanks for the grid idea last night. I have a problem though, I want to have a 4m by 4m cell sized<br>grid over my buffer geometries which are in SRID = 4326. And then I have another data set of <br>2D points which are also in SRID 4326... wondering how I can figure out from just a given (lat,long) <br>
which cell ID in the buffer grid it would belong to? I am thinking that I might run into "alignment <br>issues" because shouldn't the extent of the grid be exactly the same on the 2D point cloud as well,<br>
so that the grid cell IDs will match? Unless I am missing something here?<br><br>Cheers,<br>Ed<br><br><br><div class="gmail_quote">On Wed, Mar 21, 2012 at 8:46 PM, Pierre Racine <span dir="ltr"><<a href="mailto:Pierre.Racine@sbf.ulaval.ca">Pierre.Racine@sbf.ulaval.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">> I am not sure if this is possible, but I have computed (using ST_Buffer) a sort of<br>

> buffer around several LINESTRINGs. Now I would like to lay some sort of grid of<br>
> say 1m^2 cell size on top of this collection of geometries and then compute the<br>
> intersection... so in the end I would like to for example, know that grid cell ID = 1<br>
> intersects with buffers 1 and 10, grid cell 2 intersects with buffers 7, 10 etc..<br>
><br>
> Is there a simple way of doing this in postgis? Maybe someone could point me to<br>
> some documentation of how I can generate such a grid in postgis and maybe<br>
> then I can use just ST_Intersect once I have these two geometries?<br>
<br>
</div></div>With the raster type you can now easily create a vector grid like this:<br>
<br>
CREATE TABLE vectorgrid AS<br>
SELECT (gvxy).geom, ((gvxy).x - 1) * rwidth + (gvxy).y gridid<br>
FROM (SELECT ST_PixelAsPolygons(rast) gvxy, ST_Width(rast) rwidth<br>
             FROM (SELECT ST_AsRaster(ST_Extent(geom)::geometry, 1.0, 1.0) rast<br>
                          FROM yourbuffertable<br>
                         ) foo1<br>
            ) foo2;<br>
<br>
Make sure a spatial index exist on both tables:<br>
<br>
CREATE INDEX yourbuffertable_geom_idx  ON yourbuffertable USING gist  (geom);<br>
CREATE INDEX vectorgrid _geom_idx  ON vectorgrid USING gist  (geom);<br>
<br>
You can then perform a normal intersect query:<br>
<br>
CREATE TABLE interresult AS<br>
SELECT b.bufferid, g.gridid, ST_Intersection(g.geom, b.geom) geom<br>
FROM vectorgrid g, yourbuffertable b<br>
WHERE ST_Intersects(g.geom, b.geom);<br>
<br>
Pierre<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</blockquote></div><br>