3

I have created a hexagonal grid shapefile using MMQGIS and want to use this for hexagonal binning.

I have another point shapefile which contains patient records for three different types of hospital activity (let's call them A,B and C) for two different years.

What would be the best way of quickly generating point counts (via Points in Polygon) for each subset of the activity shapefile so that I ended up with 9 additional columns in my hexagonal grid shapefile?

  1. Year 1, activity A
  2. Year 2, activity A
  3. Difference between years 1 and 2 for activity A

  4. Year 1, activity B

  5. Year 2, activity B
  6. Difference between years 1 and 2 for activity B

  7. Year 1, activity C

  8. Year 2, activity C
  9. Difference between years 1 and 2 for activity C

Is it possible to script this using pyqgis? I've started reading up on pyqgis but I'm a long way off being able to tell if this is possible.

If it is possible, are there any tutorials out there that would cover this sort of processing or at least point me in the right direction to start figuring it out?

I really want to learn scripting in QGIS and this feels like something which would lend itself to getting started.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Dec 4, 2013 at 9:51
2
  • 1
    I'm going to post this in a comment because I'm not sure if this answers your question directly. I blogged about this recently at geospatial.commons.gc.cuny.edu/2013/11/25/hexbinning, and I concluded that doing this in PostGIS is much faster than using the QGIS Points in Polygon tool. But I don't know if pyqgis would do better. Commented Dec 5, 2013 at 9:21
  • Thanks Lee, unfortunately I don't think getting PostGIS up and running in my (fairly restricted) work environment is possible. I do have access to SQL Server 2008 which might be a better way of doing this. I'd still be keen to learn the pyqgis method as I figure it would also allow me to set custom thematic styling. Commented Dec 5, 2013 at 12:02

1 Answer 1

3

I ran across the Lee's (@LeeHachadoorian) blog (described in his comment above) and found the problems that he encountered when trying to perform hexbinning in an open-source GIS, eventually abandoning it and adopting a PostGIS workflow instead. I think that perhaps the issue with the workflow that he adopted was the reliance on point-in-polygon operations to identify which hexagon each data point was enclosed in. Point-in-polygon operations are quite computationally expensive when you have many polygons and many points. I think there is a potentially improved workflow that could be followed for this task.

A hex-grid is essentially the Voronoi diagram for the set of hexagon centre points, meaning that every location within a hexagon grid cell is nearest the hexagon’s centre than another other neighbouring cell centre point. As such, a more efficient way of performing hexbinning would be to enter each hexagon’s centre point into a KD-tree data structure and perform a highly efficient nearest-neighbour operation on each of the data points to identify their enclosing hexagon. This is a fast operation and so the hexbinning tool works well even with massive point sets. In this linked blog, I describe a tool that I developed for another open-source GIS for hexbinning and an application in which I was able to bin 7.7 million LiDAR points very quickly using this workflow. Notice as well that this tool is completely automated and does not require any scripting on the part of the user.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Sep 10, 2014 at 15:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.