[gdal-dev] extract information from polygon shapefile based on raster grid?

Newcomb, Doug doug_newcomb at fws.gov
Thu Mar 28 05:39:37 PDT 2013


Chao,
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.


Doug

On Wed, Mar 27, 2013 at 6:38 PM, Jan Heckman <jan.heckman at gmail.com> wrote:

> Hello Chao,
>
> 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.
> Your output could be another shapefile,  with the summed results as
> attributes, like the number of fires.
> 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.
> 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.
> 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.
> 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.
>
> So, more simply still,  assuming the grid is regular and it is possible to
> compute the gridindex from pointcoordinates:
>
> Add an index field to the centerpoint shape which has the attributes;
> calculate the gridindex from the coordinates and put this into the index
> field;
> bring the table e.g. into excel;
> do a pivot table for the attributes (count or sum).
> If necessary, add the centerpoint coordinates to the resulting table;
> convert the table into a new point shape with the desired attributes.
>
> Hope I got you right and this helps,
> Jan
>
> On Wed, Mar 27, 2013 at 9:52 PM, Chao YUE <chaoyuejoy at gmail.com> wrote:
>
>> Dear all,
>>
>> I am using the python binding of GDAL for reading polygon shapefiles.
>>
>> I have a polygon shapefile which contains the fire polygon and burned
>> area, with typical fires burning on 10-100ha.
>> my model simulation result is based on 0.5degree X 0.5degree. So I need
>> to extract from this shapefile on each gridcell
>> of the 0.5d X 0.5 grid the information about like number of fires and
>> mean fire size etc.
>>
>> 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
>> 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
>> the list(or array or pandas dataframe) which include the information of
>> all the polygons falling within the the same grid cell.
>>
>> I don't know if there is a better approach than this? I appreciate any
>> comments.
>>
>> best regards,
>>
>> Chao
>>
>> --
>>
>> ***********************************************************************************
>> Chao YUE
>> Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
>> UMR 1572 CEA-CNRS-UVSQ
>> Batiment 712 - Pe 119
>> 91191 GIF Sur YVETTE Cedex
>> Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
>>
>> ************************************************************************************
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>



-- 
Doug Newcomb
USFWS
Raleigh, NC
919-856-4520 ext. 14 doug_newcomb at fws.gov
---------------------------------------------------------------------------------------------------------
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20130328/4bf9ee6a/attachment.html>


More information about the gdal-dev mailing list