Home-range analyses in QGIS using R through Python

Anne Ghisla's Google Summer of Code project, mentored by Timothy H. Keitt

State of the art

Version 2.1.8 is available on user-contributed QGIS plugin repository (see Download section and NEWS file). There are issues with newest versions of rpy2 so it is not working on Windows and in some cases also on Linux.

Future development of QGIS plugin

Two solutions are being examined on Animove mailing list:

  • HomeRange plugin version 3 Sextante plugin that uses R algorithms, without using the problematic rpy2.
    • Pro: few days of work required.
    • Con: depends on R.
  • pyHomeRange plugin Sextante plugin with algorithms rewritten in Python. It is being developed by Francesco Boccacci http://plugins.qgis.org/plugins/sextante_animove/ https://github.com/volterra79/sextante_animove
    • Pro: removes R dependency.
    • Con: the algorithms will not be the same, therefore there will be differences in results for kernels in particular. Bear it in mind when comparing results between Sextante-Animove plugin and HomeRange plugin, or any other.
    • Con: requires more work, skills and testing for algorithm reimplementation.

Anyone interested in working on it is invited to contact me and Animove mailing list for details.

Future development of core functions

More functions are now available in adehabitatHR package. Some work has been done on the R wrapper function by students of University of Insubria. More work is required to have a fully functional wrapper function, that can be easily called in a R script or Sextante plugin.

This amount of work can easily be fitted in a Google Summer of Code project, under R umbrella.

  1. Document work
  2. Write tests that can be easily run by the user
  3. Merge edits from student of Insubria University on public repository such as https://r-forge.r-project.org/projects/hrtools/
  4. Check that all code uses sp classes
  5. Let the user provide a custom grid step and calculate it over the locations bounding box
  6. Update all adehabitat methods to new adehabitatHR, and add all available adehabitatHR methods
  7. Adapt exporter() to the modifications above
  8. Wrap all code in a new R package, see https://r-forge.r-project.org/projects/hrtools/
  9. Optional: create a SEXTANTE plugin
Other good additions:
  1. Improve existing triangulation plugins (it can be another Google SoC)
  2. Translate fractal dimension code from Vilis Nams (Delphi Pascal)
  3. Write a function for incremental analysis

Please contact Damiano Preatoni, Anne Ghisla and/or AniMove mailing list to express interest in the idea.


The code is available on user-contributed QGIS plugin repository. The plugin is named "Home range estimation with R".
In Qgis interface go to Plugins - Fetch Python Plugins - search for "home range" (the list is quite long!).
If the plugin does not appear in the list, enable "QGIS contributed repository" in the Repositories tab of the Plugin installer.
Click on it, then on "Install plugin" button. No need to restart, nor to load it via Plugin Manager: it will be already enabled. If you want to disable it without uninstalling, use Plugin Manager, otherwise Plugin Installer can be used both to upgrade and to uninstall plugins.


A short tutorial is provided via Help button in the interface.

You can find suitable data on AniMove page.

Bug and wishlist

Testing is welcome! Bug reporting and wishlist about the plugin is provided on the QGIS unified bug tracker: http://hub.qgis.org/projects/homerange-plugin/issues .
Thanks to Faunalia for providing trac during the first years of development!

Please prefer filling a ticket instead of sending a mail, as it helps collecting all information in one place and keeping attention on it (whereas I easily lose visibility on emails..). Also, a.ghisla at studenti.uninsubria.it is no more a vaild email - I'm not student there anymore, and my account has been closed recently.

Some discussion aroud HomeRange_plugin can be read on AniMove mailing list

For any other problem relative to plugin's dependencies (R, rpy, numpy, python itself, qgis) please write on AniMove mailing list. If it's not possible to fix the problem in the plugin, it will be redirected to the relevant developers.

Thanks for your feedback!

Installation requirements and tested platforms

The plugin depends on:

  • Python
  • R
    • package adehabitat and its dependencies
    • package rgdal and its dependencies
    • package gpclib
    • package shapefiles (until NNCH is exported by adehabitat in its own way)

Note that these requirements, except for R packages, are the same of Carson Farmer's manageR plugin.

Windows Vista/Seven users: Giovanni Manghi kindly provides a screencast with all the steps to install correctly R, the R libraries, QGIS, python libraries and the plugin:




Checked working configurations:

OS QGIS Python R rpy2 R packages
Debian testing 1.x series 2.5 and 2.6 2.8.1 - 2.9.x - 2.10.x python-rpy2 adehabitat 1.8.2 or higher
Ubuntu 9.10 'Karmic' 1.4 trunk r12048 2.6 (current packaged) 2.9.2 python-rpy2 (current package)
Windows XP/Vista/7 QGIS 1.7.3 standalone all bundled 2.7.1 up to 2.11.0 bundled adehabitat (legacy)
OpenSUSE (several versions via
and science Repo)
1.0.2 2.5.2 2.9.1 python-rpy2 2.0.6 adehabitat, rgdal
Fedora 14 1.7 trunk r15016 2.7 (packaged) 2.12.0 rpy 2.1.9
rpy is the name of the package, but it contains rpy2.
Mac OSX 10.6.2 'Snow Leopard' 1.4 trunk r12391 2.6.1 (system python) 2.10.0 (2009-10-26) rpy2 (easy_install package)

{*} Install them with the R command install.packages("<name of the package>", dep = TRUE) _'

<!> R 2.7.0 can't load adehabitat, because its latest version (1.7.2) requires 2.7.1. So R 2.7.0 is not suitable.

Platform notes


Debian Lenny can provide up-to-date R and rpy/rpy2 versions using Sid repositories - see here for detailed instructions.

Thanks to Dylan Beaudette and his team, 1700+ R packages are available via aptitude on cran2deb repository!. For more instructions, see the announcement.

Ubuntu users: have a look at installation steps provided by Tim Sutton. They can easily suit other Ubuntu-like systems, just take care of some slight modifications like using aptitude instead of apt-get.

MS Windows

IMPORTANT: QGIS 1.7.3 or older is required in order to get the plugin work on Windows. Please download it from Old downloads page .

Newer versions of QGIS use Python 2.7, for which no rpy2 package is available. The rpy2 developer has discontinued Windows support, so keeping old versions of Python is the only easy way of having a functional Homerange plugin. There is currently some testing on unofficial packages by Giovanni Manghi, more news will be posted here when relevant.

Here are a list of known problems and solutions. They are known to happen on XP, Vista or Seven.

Vista/7: Giovanni Manghi reported problems related to the security measures introduced by Vista. The plugin is not automatically authorized to call R, but it is possible to convince the OS answering "Yes" to the numerous times it asks if the plugin is going to perform a safe operation.

All - R <=2.9: The plugin reports the error: Unable to locate R.dll. As R installer does not automatically add RHOME to the list of environmental variables, you should do this by hand. Under Windows 2000/XP/2003 you can use `System' in the control panel or the properties of `My Computer' (under the `Advanced' tab). Under Vista, go to `User Accounts' in the Control Panel, and select your account and then `Change my environment variables'. If R RHOME doesn't exist, you can add it easily, specifying the full path to R executable minus /bin/R.exe.

All - R >2.9: If the above solution does not work, it is probably due to a reorganisation of R binaries starting from R 2.10. Sadly, under Windows, no more support nor binary packages are provided by rpy2 team, see here for the official documentation mentioning this. I'll be glad to anyone able to give directions on how to compile rpy2 for R >2.9 on Windows, and explain the procedure here.

R >=2.12: From this version on, the R.dll location has changed, so it isn't found automagically by rpy2. It raises a Unable to locate R.dll error. You can fix that by editing or creating the RHOME variable, pointing to the correct location. See the instructions above, and the thread on the Animove mailing list.

All If you run the plugin and get R error like package ade4 cannot be loaded, it means that the package is installed, but the location of the installed packages is not found by rpy2. If you load the package in R, it works. Please copy the contents of


(or similar, please check your R version number, and that the folder contains ade4 or the packages mentioned in the error) to


, where rpy2 looks for. If the folder does not exist, it is safe to create it.

Mac OSX Snow Leopard

- Download R binary installer from the R site :


(install all the optonal packages : tcltk, gfortran).

- Install Rpy2 using easy_install :

 sudo easy_install rpy2

- Install the dependence avaiable as frameworks from :


- download untar and install wget : http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz

 tar xzf wget-latest.tar.gz
 cd wget-latest
 sudo make install

- download rgdal :

 wget http://rm.mirror.garr.it/mirrors/CRAN/src/contrib/rgdal_0.6-23.tar.gz

install rgdal :

 R64 CMD install rgdal_0.6-23.tar.gz --configure-args='--with-gdal-config=/Library/Frameworks/GDAL.framework/unix/bin/gdal-config --with-proj-include=/Library/Frameworks/PROJ.framework/unix/include --with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'

- Install R packages adehabitat, shapefiles and gpclib via the R GUI.

That's all! Fetch and enable HomeRange_plugin, grab data and run analysis!



A SVN repository contains trunk and branches of the development. Contributors: please contact a.ghisla at gmail.com to ask for write access. It is important that you send patches against the current trunk, to spare time and energies... maybe the bug has already been fixed.


Future development

Contact Animove list or me directly to suggest improvements for HomeRange plugin.

  • add multithreading support (cfr. branches/threading in GDAL plugin)
  • upgrade to "adehabitat reloaded" that provides direct use of sp classes, but only when it will be available on CRAN.
  • homerange asymptotes - see ABODE manual at http://fishwild.vt.edu/abode/ (suggestion by Max Ringler)
  • if there are no point layers available, the warning dialog is shown twice. One is enough
  • write a better error message than "At least 5 relocations are required to fit an home range"
  • First Time Passage and Areas of Restricted Search (proposed by Pedro Rodrigues on Animove list in August 2010)

GSoC 2008 log

Into the code: List of available layers

6th week report is about combobox population with all available point layers. It is possible to get the layer list from MapCanvas, i.e. the part of the main window where checked layers are shown. If no layer is checked, nothing is displayed in MapCanvas, and the retrieved list is empty.

I solved this retrieving the list of loaded layers from an instance of QgsMapLayerRegistry. This list contains all layers shown in Legend, both checked and unchecked. This way, the point layer named "samplepoints" is present in the box even if absent from the Canvas.

I guess it's a better implementation, because there is no need of displaying data when using my plugin. If the layers I'm working on are large, checking them in order to add them to the list of available layers could be a long and unuseful operation.


Week Planned Done? Report
1 - from 26.5 polish R code, refactor, test (./) none
2 - from 2.6 set up repo and work on R code (./) link
3 - from 9.6 (prepare Java exam) (./) link
4 - from 16.6 set up the GUI (./) link
5 - from 23.6 work on GUI (./) link
6 - from 30.6 connected to R and QGIS Legend (./) link
7 - from 7.7 MCP analysis complete (./) link
8 - from 14.7 refactorisation /) link
9 - from 21.7 merged python files into plugin.py, deep interface refactoring /) link
10 - from 28.7 beta version, further functionality, testing /) link
11 - from 4.8 improvements (./) link
12 - from 11.8 documentation (./) link
13 - from 18.8 (holiday in Belgium) [link]
14 - from 25.8 [link]


Homerange_plugin_screenshot2.png (260 KB) Redmine Admin, 2011-11-23 04:44 PM

Homerange_plugin_screenshot1.png (74.2 KB) Redmine Admin, 2011-11-23 04:44 PM