Tutorial: Spatial Analysis - Points in Polygon

Tutorial Moved to  http://www.qgistutorials.com/en/docs/points_in_polygon.html 

The power of GIS lies in analysing multiple data sources together. Often the answer you are seeking lies in many different layers and you need to do some analysis to extract and compile this information.


One such type of analysis is Points-in-Polygon. When you have a polygon layer and a point layer - and want to know how many or which of the points fall within the bounds of which polygons, you can use this method of analysis. For this tutorial, the question we want to answer is ‘Which country in the world has had the most number of major earthquakes?’



We will be using 2 data sources. For the points layer, we will use NOAAS’s Significant Earthquake Database and import the CSV file as a points layer as described in this tutorial. The countries shapefile will be from the Natural Earth dataset.


  • Load both the 10m_admin_0_countries and earthquake layers in QGIS.The countries layer is a polygon layer and the earthquake layer is the point layer.
  • Click on Vector → Analysis Tools → Point in Polygon
  • In th pop-up window, select the polygon layer and point layer respectively. Browse to a path in your hard drive and name the output layer as earthquake_per_coutry.Click OK. ( Be patient after clicking OK, QGIS may take upto 10 minutes to calculate the results ). When asked whether you want to add the layer to TOC, click ‘Yes’.
  • You will see a new layer is added to the table of content. Open the attribute table by clicking on ‘Attribute Table’ icon as shown.
  • In the attribute table, you will notice a new field named ‘PNTCNT’. This is the count of number of points from the earthquakes layer that fall within each polygon.
  • To get our answer, we can simply sort the table by PNTCNT field and the country with highest count will be our answer. Click 2-times on the PNTCNT columnto get it sorted in descending order.So we have determined from the simple analysis of 2 datasets that China has had the highest number of major earthquakes. You may refine this analysis further by taking into consideration the population as well as the size of the country and determine which is the most adversely affected country by major earthquakes.