Chao,<div>Depending on how detailed you want your stats to be, it might be easier  run the zonal statistics plugin in qgis or run v.rast.stats in GRASS 70. <br><br><br>Doug</div><div><br><div class="gmail_quote">On Wed, Mar 27, 2013 at 6:38 PM, Jan Heckman <span dir="ltr"><<a href="mailto:jan.heckman@gmail.com" target="_blank">jan.heckman@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Chao,<div><br><div>I may not understand your wish quite well, but I think you need some datastructure which conforms to the elements of the grid and receives addtional information derived from a number of shapes with attributes.</div>


<div>Your output could be another shapefile,  with the summed results as attributes, like the number of fires.</div><div>In the case that the only spatial relationship between shapes and gridelements is whether or not a shape falls inside, you can indeed simplify the polygon shape to pointshapes (centerpoints) which can be converted to a raster of 1's and 0's. Then you could use a dictionary to put the shapeattributes in the right place. I see a problem when several shapes fall into the same grid-element, having different attribute values.</div>


<div>So you would be better off with a way of rasterbuilding, where each attribute is summed per gridelement over all the shapes that fall inside. Such routines exist at least in several programs.</div><div>Alternatively, you can make a polygon shapefile which conforms to the rasterelements, then do a spatial join between your (centerpoint) shapefile and and the rastershape (effectively adding a field to the pointshapes which is the index into the grid), then add the several attribute data per gridelement by e.g. making a pivot table.</div>


<div>If you have to work with shapes that are larger than the gridelements, you would need another solution; there would be a choice between sampling the shapes or distributing shape attributes proportionally to calculated overlap with (polygonal) gridelements.</div>


<div><br></div><div>So, more simply still,  assuming the grid is regular and it is possible to compute the gridindex from pointcoordinates:</div><div><br></div><div>Add an index field to the centerpoint shape which has the attributes;</div>


<div>calculate the gridindex from the coordinates and put this into the index field;</div><div>bring the table e.g. into excel;</div><div>do a pivot table for the attributes (count or sum).</div><div>If necessary, add the centerpoint coordinates to the resulting table;</div>


<div>convert the table into a new point shape with the desired attributes.</div><div><br></div><div>Hope I got you right and this helps,</div><div>Jan<br><br><div class="gmail_quote"><div><div class="h5">On Wed, Mar 27, 2013 at 9:52 PM, Chao YUE <span dir="ltr"><<a href="mailto:chaoyuejoy@gmail.com" target="_blank">chaoyuejoy@gmail.com</a>></span> wrote:<br>


</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">Dear all,<br><br>I am using the python binding of GDAL for reading polygon shapefiles.<br>

<br>I have a polygon shapefile which contains the fire polygon and burned area, with typical fires burning on 10-100ha. <br>
my model simulation result is based on 0.5degree X 0.5degree. So I need to extract from this shapefile on each gridcell<br>
of the 0.5d X 0.5 grid the information about like number of fires and mean fire size etc. <br><br>The approach I am thinking currently is to calculate the center of each of fire polygon, and check which 0.5d X 0.5d gridcell<br>



it falls in, then build a huge dictionary with key as the numpy index of the 0.5dX0.5d array, with the dictionary values as <br>the list(or array or pandas dataframe) which include the information of all the polygons falling within the the same grid cell.<br>



<br>I don't know if there is a better approach than this? I appreciate any comments.<br clear="all"><br>best regards,<br><br>Chao<span><font color="#888888"><br><br>-- <br><div>***********************************************************************************</div>




<div>Chao YUE<br>Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)<br>UMR 1572 CEA-CNRS-UVSQ<br>Batiment 712 - Pe 119<br>91191 GIF Sur YVETTE Cedex</div>
<div>Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16<br></div>

<div>************************************************************************************</div>
</font></span><br></div></div>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></blockquote></div><br></div></div>
<br>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Doug Newcomb</div><div>

USFWS</div><div>Raleigh, NC</div><div>919-856-4520 ext. 14 <a href="mailto:doug_newcomb@fws.gov" target="_blank">doug_newcomb@fws.gov</a></div><div>---------------------------------------------------------------------------------------------------------</div>

<div>The opinions I express are my own and are not representative of the official policy of the U.S.Fish and Wildlife Service or Dept. of the Interior.   Life is too short for undocumented, proprietary data formats.</div>


</div>