3

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?

underdark
  • 84,148
  • 21
  • 231
  • 413
Tabrez Khan
  • 191
  • 1
  • 10

2 Answers2

2

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
>>>processing.alghelp("saga:kerneldensityestimation")

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>

KERNEL(Kernel)
        0 - [0] quartic kernel
        1 - [1] gaussian kernel
TARGET(Target Grid)
        0 - [0] user defined
Joseph
  • 75,746
  • 7
  • 171
  • 282
  • what should be the parameter number for radius? – Tabrez Khan Jun 08 '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 08 '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 08 '15 at 13:27
  • 1
    @TabrezKhan and Joseph: some resources you might want to take a look at for explanation of parameters: http://gis.stackexchange.com/questions/14374/ and http://docs.qgis.org/2.0/en/docs/user_manual/plugins/plugins_heatmap.html – Chris W Jun 08 '15 at 20:07
  • @ChrisW - Fantastic! Many thanks for finding the information buddy! – Joseph Jun 09 '15 at 09:05
2

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.

KERNEL(Kernel)
    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.

Tabrez Khan
  • 191
  • 1
  • 10