I have been trying to generate heatmap using kernel density estimation from python console in QGIS.

This is command i'm using:

processing.runandload("saga:kerneldensityestimation", "D:/test/Towns.shp", "A_RAIN_MM", radius, 0, "0,1,0,1", 0.00848754, "D:/test/raster.tif")

The result I'm getting is a image with black shade which is totally different from the heatmap i generated using QGIS user interface.

After googling, I found this link: kernel density estimation. This contains the list of parameters which kernel density estimation takes, but it does not contains any description about the parameters. What these parameters are i do not know. Can i anyone tell me what i'm doing wrong? Or is there another way of generating heatmap?

  • Have you tried using Raster > Heatmap? – Joseph Jun 8 '15 at 13:29
  • If you are talking about the user interface of the QGIS, then yes. But i did not tried it in python console. – Tabrez Khan Jun 8 '15 at 13:31

I finally figured it out!

The main problem for me was OUTPUT_EXTENT and RADIUS. Kernel density estimation takes radius in degress only and OUTPUT_EXTENT is the size of the output rater layer and takes input as a string of "xmin,xmax,ymin,ymax".

ALGORITHM: Kernel density estimation
    POINTS <ParameterVector> Takes a vector layer(can be a local path)
    POPULATION <ParameterTableField from POINTS> any field in vector layer which contains weight
    RADIUS <ParameterNumber> raduis(in degree)
    KERNEL <ParameterSelection>
    OUTPUT_EXTENT <ParameterExtent> takes parameter in string "xmin,xmax,ymin,ymax".
    USER_SIZE <ParameterNumber> cell size of the raster image.
    USER_GRID <OutputRaster> output path of raster image.

    0 - [0] quartic kernel
    1 - [1] gaussian kernel

If you want to do it in user interface use Ctrl + Alt + M and type kernel density estimation.

| improve this answer | |
  • Awesome! Glad you found out what the problem was :) – Joseph Jun 10 '15 at 8:54

I think you need to replace your radius parameter with a number.

Incase this might help for future reference, what I usually do when I need to know what parameters I have to set, is to check the "help" details of the algorithm within Python Console (Plugins > Python Console). Type the first 2 lines below:

>>>import processing

ALGORITHM: Kernel density estimation
        POINTS <ParameterVector>
        POPULATION <ParameterTableField from POINTS>
        RADIUS <ParameterNumber>
        KERNEL <ParameterSelection>
        TARGET <ParameterSelection>
        OUTPUT_EXTENT <ParameterExtent>
        USER_SIZE <ParameterNumber>
        USER_GRID <OutputRaster>

        0 - [0] quartic kernel
        1 - [1] gaussian kernel
TARGET(Target Grid)
        0 - [0] user defined
| improve this answer | |
  • what should be the parameter number for radius? – Tabrez Khan Jun 8 '15 at 13:23
  • 1
    Never used this algorithm but I'm guessing it's how large you want the radius of your generated heatmap points to be. You can always play around with the value to see what would be most suitable for you :) – Joseph Jun 8 '15 at 13:25
  • That's what i am giving, but i do not know what output extent is or the target extent. what should be there values? – Tabrez Khan Jun 8 '15 at 13:27
  • 1
    @TabrezKhan and Joseph: some resources you might want to take a look at for explanation of parameters: gis.stackexchange.com/questions/14374 and docs.qgis.org/2.0/en/docs/user_manual/plugins/… – Chris W Jun 8 '15 at 20:07
  • @ChrisW - Fantastic! Many thanks for finding the information buddy! – Joseph Jun 9 '15 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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