2

I have two shapefiles....

  • points containing a number field 'response_time'
  • a polygon grid of square polygons containing fields including 'PNTCNT' with the number of points per polygon, calculated already using the tool 'points in polygon'

There are between 0 and 600 points within the bounds of each polygon in the grid.

I want to add fields to the polygon grid for the mean, min and max response times within each polygon, in addition to the PNTCNT field already there.

I have tried the 'Join attributes by location' tool, making the polygon layer the target and the points the join layer, and vice versa. I've selected 'take summary of interesting features'.

But I can't get the result I want. All I end up with is the polygon grid again but with an extra field 'COUNT' which replicates (or duplicates) the 'PNTCNT' field. No min, max and mean of values from the points layer.

What am I doing wrong? Is there a better way to do this? I have tried this using QGIS 1.7 and 1.8.

1
  • 2
    Tested using QGIS sample data with 1.8 and it seems to work. A possible source for problems are duplicate column names due to Shapefile limitations.
    – underdark
    Feb 14, 2013 at 17:12

3 Answers 3

3

I don't have time to try this out, but in my head it might work...if you have a unique ID for each grid square, and get that ID into a field on each point, then you should be able to get all the statistics you want by using the GroupStats QGIS plugin on the point layer, grouping by the ID. (then save that, join back to the grid and you're in business) Maybe there's something easier still...

2

I feel like there is a glitch in the QGIS > Data Management Tools > Joining by location at QGIS v1.8.0; at least in my test cases of joining points to overlapping polygons, or polygons to internal points (with different CRS). I'd guess that you need to alternately export the shapes to PostGIS and perform SQL spatial queries to get the results you need in QGIS.

1
  • And you might look at Python for processing some of the statistics you need.
    – user12711
    Feb 14, 2013 at 15:26
2

Do you have PostGIS set up? If so, this is a pretty trivial set up an update query once you import your shapefiles.

UPDATE polylayer SET meantime = averageist, mintime = smallest
, maxtime = biggest FROM (
    SELECT y.id, avg(points.responsetime) As averagist, min(responsetime) As smallest
    , max(responsetime) as biggest
    FROM pointlayer x, polylayer y
    WHERE ST_Intersects(pointlayer.geom, polylayer.geom)
    GROUP BY y.id
) t
WHERE polylayer.id = t.id;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.