Δημιουργώντας Heatmaps

Προειδοποίηση

This tutorial is now obsolete. A new and updated version is available at Creating Heatmaps (QGIS3)

Οι χάρτες Heatmaps είναι ένα από τα καλύτερα εργαλεία οπτικοποίησης για πυκνά σημειακά δεδομένα. Οι χάρτες Heatmaps χρησιμοποιούνται για να αναγνωρίσουμε εύκολα ομάδες όπου υπάρχει υψηλή συγκέντρωση δραστηριότητας.Επίσης, είναι χρήσιμοι για cluster analysis ή hotspot analysis.

Επισκόπηση του έργου

Θα εργαστούμε σε ένα σύνολο δεδομένων για τις περιοχές εγκλημάτων στην Surrey, UK για το έτος 2011 και θα βρούμε τα hotspots εγκλημάτων στη χώρα.

Other skills you will learn

  • How to perform HotSpot or Cluster analysis on dense point data.

Πάρτε τα δεδομένα

data.police.uk provides street-level crime, outcome, and stop and search data in simple CSV format.

Download the data for Surrey Police and unzip the downloaded archive to extract the CSV file.

For convenience, you may directly download a copy of the dataset from the link below:

2015-08-surrey-street.csv

Data Source [POLICEUK]

Διαδικασία

  1. To start, we will import the CSV file into QGIS. (see Εισαγωγή Φύλλα ή αρχεία CSV. for more details). Click Layer ‣ Add Delimited Text Layer.

../_images/1174.png
  1. Browse to the 2015-08-surrey-street.csv file on your computer and open it. (Your filename maybe different if you downloaded a fresh copy of the dataset). Select CSV (comma separated values) as the file format. You will see the Longitude and Latitude columns automatically selected as X and Y fields. Make sure you check the Use spatial index option as that will speed up your operations on this layer. Click OK.

../_images/2143.png
  1. Πιθανόν να δείτε ορισμένα σφάλματα.Μπορείτε να τα αγνοήσετε για το σκοπό αυτού του tutorials. Κάντε κλικ στο Close.

../_images/385.png
  1. As the data layer is loaded in QGIS, you will see a warning dialog CRS was undefined: defaulting to CRS EPSG:4326 - WGS84. The CSV importer assumes the CRS EPSG:4326 if your coordinates are in Latitude/Longitude. If your X and Y coordinates were in a projected CRS, you will get a dialog prompting you to choose the CRS. As our data is in EPSG:4326, you can ignore the warning.

Σημείωση

If you need to change the automatically assigned CRS, you can use Vector ‣ Data Management Tols ‣ Define Current Projection….

../_images/452.png
  1. Κάντε Zoom-in λίγο πιο κοντά για δείτε καλύτερα τα δεδομένα.Θα παρατηρήσετε ότι τα δεδομένα είναι λίγο πυκνά και είναι δύσκολο να αντιληφθείτε που υπάρχει μεγάλη συγκέντρωση σημείων.Για κάτι τέτοιο ένας χάρτης heatmap θα ήταν εύχρηστος.

../_images/545.png
  1. If you need to create a heatmap for purely visual purpose or for printing - QGIS has a built-in symbology renderer called Heatmap. Let’s try that first. Right-click on the layer 2015-08-surrey-street and select Properties.

../_images/643.png
  1. In the Properties dialog, switch to the Style tab. Select Heatmap as the renderer. You have a lot of choice of color-ramps for the heatmap. Choose the Oranges color-ramp. Leave the other parameters to default and click OK.

../_images/743.png
  1. You will see a nice heatmap of your data and pockets of heat where there is a high concentration of crime. There are quite a few options available in the heatmap renderer to create the most appropriate visualization for your dataset. If you just wanted to create a heatmap for print or visual inspection - you are done! But we will explore another more powerful heatmap creation option where you can use the results in your analysis also.

../_images/842.png
  1. Enable a core plugin named Heatmap. See Χρησιμοποιώντας Πρόσθετες Λειτουργίες to know how to enable built-in plugins. Once you have enabled the plugin, go to Raster ‣ Heatmap ‣ Heatmap.

../_images/943.png
  1. In the Heatmap Plugin dialog, choose crime_heatmap as the name out the Output raster. Enter 1000 meters as the Radius. Radius is the area around each point that will be used to calculate the i`heat` a pixel received. Check the Advanced so we can specify the output size of our heatmap. Enter 2000 as Rows value. The Columns value will update automatically. Click OK to start the heatmap creation process.

../_images/1050.png
  1. Once the processing is finished, you will see a grayscale layer called crime_heatmap loaded into the canvas. Uncheck the 2015-08-surrey-street layer.

../_images/1175.png
  1. Let’s make our heatmap look more like the traditional heatmap similar to the earlier visualization. Right-click on the heatmap layer and click Properties.

../_images/1252.png
  1. In the Style tab, select Singleband pseudocolor as the Render type. Next, under the section Load min/max values, select the Estimate (faster) as the Accuracy and click Load. This will scan the heatmap and find the minimum and maximum pixel values. These values will be used to generate an appropriate color ramp. In the section Generate new color map, select YlOrRd (Yellow-Orange-Red) as the color ramp, and click Classify. Click OK.

../_images/1350.png
  1. Τώρα θα δείτε μια πιο ελκυστική απόδοση του επιπέδου που μοιάζει με χάρτη heatmap.Μπορείτε να επιλέξετε το εργαλείο : guilabel: Identify και κάντε κλικ σε οποιοδήποτε pixel του χάρτη heatmap. Θα δείτε την τιμή του pixel στο αναδυόμενο παράθυρο αποτελεσμάτων. Αυτή η τιμή pixel είναι ένα μέτρο του πώς πολλά σημεία από το πηγαίο επίπεδο περιέχονται εντός της καθορισμένης ακτίνας (στην περίπτωσή μας - 1000m) γύρω από το pixel.

../_images/1447.png
  1. Now you have your heatmap layer that can be saved for future use. Many times, you want to identify the hotspots where there is high-concentration of points. We will now try to identify such hotspots using this heatmap. Go to Raster ‣ Raster Calculator.

../_images/1543.png
  1. You will have to decide on a threshold value first. All pixel values above that threshold will be considered to be in a cluster. Let’s use a value of 10 for this data. In Raster calculator dialog, name the output layer as crime_hotspots_vector. Double-click on crime_heatmap@1 under the Raster bands section and it will be added to the Raster calculator expression textarea. Complete the expression as shown below. Check the box next to Add result to project and OK.

"crime_heatmap@1" > 10
../_images/1641.png
  1. A new layer called crime_hotspots will be added to QGIS. This layer has pixels with values of either 0 or 1. All pixels in the input layer where the pixel value was larger than 10 now have a value of 1 and all remianing pixels are 0. Click on Raster ‣ Conversion ‣ Polygonize (Raster to Vector).

../_images/1739.png
  1. Name the output file as crime_hotspots_vector. Check the box next to Field name as well as Load into canvas when finished. Click OK.

../_images/1836.png
  1. Once the conversion finishes, you will have yet another layer named crime_hotspots_vector added to QGIS. This is the vector representation of the clusters that were created in the previous step. The layers contain clusters with both 0 and 1 values. Let’s filter out the 0 values, so we get the clusters of hotspots. Right-click on the layer and select Open Attribute Table.

../_images/1927.png
  1. Στο Attribute table, κάντε κλικ στο Select feature using an expression.

../_images/2023.png
  1. Enter the expression as shown below and click Select. Next, click on Close.

"DN" = 0
../_images/2144.png
  1. In the main attribute table window, you will see some features highlighted. These are the features that matched our query. Click the Toggle editing mode button in the toolbar and then click the Delete selected features (DEL) button.

../_images/2225.png
  1. Once the selected features are deleted, click the Save Edits button and then Toggle editing mode again to put the layer in read-only mode. Close the attribute table window.

../_images/2322.png
  1. In the main QGIS window, un-check the crime_hotspots layer. The final layer crime_hotspots_vector contains the cluster extracted from the heatmap. These clusters are the intelligence gathered from the raw data and can provide useful insights as well as serve as an input for further action.

../_images/2422.png

If you want to give feedback or share your experience with this tutorial, please comment below. (requires GitHub account)