# Assigning values to vector grids using summary statistics QGIS

In QGIS, I have a 500 sqft grid overlaid onto my map. I want to perform summary statistics (sum, mean, median, max/min) on certain vector features under the grid and assign the grid cell that value. I did this before (purple grid image below), but I can NOT remember what I did.

Here's my map with the grid overlaid. Let's say I want to calculate the total linear feet of streets in each cell. Or even the number of intersections.

Here's the example I completed a few weeks ago. BUT I CAN'T REMEMBER HOW.

• What statistic is your purple grid showing? Getting the lineal footage of roads or the number of intersections per grid cell are two different procedures. Generically this could be called zonal statistics. Intersects and spatial joins are potential steps to get the 'by cell' numbers. – Chris W Feb 15 '15 at 20:37
• It is showing the median "convexity index" for parcel data—an experimental metric where I divided the perimeter of the polygon by its area. I calculated this for each parcel in a field operation. Then the operation I performed—whatever it was—let me choose if I wanted a sum, mean, median, etc. – plnnr Feb 16 '15 at 21:50
• Everything you've mentioned so far is either an attribute or geometric property of individual features in a layer (or must be extracted as such). Zonal statistics as a term is usually used in conjunction with raster data. For what you're describing with vector, each cell needs a unique ID, you intersect the grid with the features, and that cuts up and transfers the cell ID to the features. Then you summarize the attribute (GroupStats?) by cell ID and join the result back to the grid. If there is a single tool/plugin in QGIS (or ArcGIS for that matter) that does this, I don't know what it is. – Chris W Feb 16 '15 at 22:01
• Okay, so I did this in ArcGIS instead. It was just a spatial join. But when I do the similar task in QGIS (Vector->Data Management Tools->Join attributes by location), it doesn't seem to work (at least for streets). This would lead me to another question: how do I break the polyline streets along the gridlines? – plnnr Feb 17 '15 at 8:47
• I don't know if the ArcGIS and QGIS spatial joins work in quite the same way, but that is another way to do it. You do have to be cautious of how you set it up, because you can be pulling in values/influence from features outside the cell or possibly not getting all the values within - depends on your join type (1:1 or 1:M) and as you've discovered, if your features are broken at the grid. That's what the Intersect I mentioned is for. Even if they are broken, depending on how it's done attribute values may be copied rather than divided (apportioned) between pieces, again skewing your result. – Chris W Feb 17 '15 at 19:31