Professional Documents
Culture Documents
pfstyle=wp
Save the layer as a shapef ile so it is easier to reuse without importing again. Right click on the layer and select Save As.
Name the shapef ile as crime.shp. Check the box next to Add saved f ile to map and click OK.
T he new vector ;ayer will be added to the table of content. Remove the older imported layer by right clicking and selecting Remove.
To use the heapmap plugin, we must enable it f irst. Click on Plugins Manage Plugins. Scroll down and make sure the box next to Heatmap is checked.
In the Heatmap plugin dialog the crime layer would be selected as the Input Point Vector. Name the output raster as crime_heatmap. T he Radius is the area around each point that will be used to calculate the heat a pixel received. T he Decay ratio is how f ar a point will inf luence other pixels. Clicking on Help will bring up a more detailed explanation of the algorithm. For our analysis we would like to have a pixels value determined by how many points are within 1 km (1000m) of the location, so we select the radius at 1000 and Decay Ratio as 0. Also set the pixel resolution of the output raster to be 100. Click OK.
We have more than 100,000 points in our layer, so the heatmap processing map take a while. ( In my case about 30 minutes ). Once the heatmap raster is created, you will get a prompt to select the CRS. Select OSGB 1936 British National Grid and click OK.
You will see a gray rectangle covering your layer extents. T his is the heatmap raster, but it doesnt have any styles applied to it.
Under the Style tab, select the Pseudocolor as the Color map and click OK.
Z oom in closer to the area where the points are. Click on the Identif y Features to activate the Identif y tool. Click anywhere on the raster. You will see the Identif y Results dialog pop up with the value of the pixel at that location. T his value represents the total number of points in the 1000 pixel radius that we had specif ied.
Lets do some styling adjustments to view our heatmap better. Right click on the crime_heatmap layer and select Properties. In the Transparency tab, move the slider f or Global transparency to 20%. We also want to make the pixels with 0 values transperant, so click Add Values Manually next to the Transparent pixel list. Add the value 0 to the list. Click OK.
You will now see the underlying points along with the heatmap.
Now lets identif y clusters of crime hotspots. Say you wanted to identif y areas with high crime concentration and deploy more patrol there. Or we may want to use these clusters in some f urther analysis. We will use Raster Calculator to identif y these clusters. Click on Raster Raster calculator.
You will have to decide on a threshold value. For our example, we will use 100 as a threshold to identif y what is a cluster and what is not. In Raster calculator dialog, name the output layer as crime_heatmap_100 and check the box next to Add result to project. Input the expression crime_heatmap@1 >= 100. What this means is that all pixels will values below 100 will be assigned a value of 0 and all other pixels a value of 1. Click OK.
You will see a gray raster like earlier. Right click on the new layer and click Properties. Select Stretch to MinMax under contrast enhancement and click OK.
Now you will be able to see clusters in white pixels. We will convert these to vectors. Click on Raster Conversion Polygonize. ( Enable GdalTools plugin if you do not see this menu ).
Select crime_heatmap_100 as the input f ile. Name the output f ile as crime_clusters.shp. Check the box next to Load into canvas when f inished and click OK.
You will see the vector polygons f rom the crime_clusters layer. You will also notice that this layer contains polygons f or 0 value areas also. We will need to remove these to get a layer with our clusters. Right click on the layer and select Open Attribute Table.
You will see the polygons with 0 values will be selected. Click Toggle Editing button at the bottom. Once editing is enabled click Delete Selected Features button. Click Toggle Editing again and Save.
Go back to the main QGIS canvas and you will see the polygon layer f or your clusters. You can now use this polygon layer in your f urther analysis.
Now let us get to the second method using GRASS. GRASS is another plugin that is built in and has powerf ul analytical capability. I will quickly go through setting up a location and mapset in GRASS. You can ref er to this tutorial f or more details on what they mean. Click on Plugins GRASS New mapset.
Def ine the projection as OSGB 1936 / British National Grid. Click Next.
For Def ault GRASS Region, click Set current QGIS extent. Click Next.
Now that you set an active mapset, many more GRASS menu items will be enabled. Click Plugins GRASS Edit Current Grass Region.
T here are hundreds of analytical modules in GRASS. T hey are organized in dif f erent sections. Click on the Modules Tree tab and f ind the v.in.ogr.qgis module.
Select the crime points layer as input and name the GRASS vector as crime. Click Run. Once the import is f inished, click View Output to load the layer in QGIS canvas.
Open the GRASS tools again and f ind the module v.kernel.
Select the crime layer as input vector and enter 1000 as the Standard deviation. Name the output raster map as crime_heatmap_grass. Click Run. ( A bug in QGIS 1.8 prevents this module f rom running correctly. T his will be f ixed in later versions, but if you encounter an error, f ollow the alternate method below )
T his will open a windows commandline interf ace with relevant variables already set. Type v.kernel and press Enter. T his will launch the native GRASS interf ace f or the module.
Once the processing is f inished, click Plugins GRASS Add GRASS raster layer.
Select the crime_heatmap_grass layer and click OK. You will see a grayscale heatmap. Right click and select Properties.
Select Pseudocolor as the Colormap and click OK. Now the raster will be styled in a f amiliar heatmap style. You can export this raster f rom GRASS to any f ormat you like and use it f urther in your analysis.