« Previous - Version 2/9 (diff) - Next » - Current version
Anne Ghisla, 11/25/2011 07:27 am
Table reformatting from old wiki import

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). Rpy is no longer supported, in favour of rpy2.


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!). 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 OSGeo4W package (bundle) or 1.0 preview II (standalone) 2.5 + numpy1.1.0 + pywin32-210
2.7.1 up to 2.10.0 rpy2 in OSGeo4W 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

OSGeo4W (http://trac.osgeo.org/osgeo4w/) now provides rpy/rpy2 (rpy available in OSGeo4W is just for R 2.6.2) install options. Under Windows, use the OSGeo4W installer to install Python, numpy, pywin32, rpy or rpy2 libraries. Install separately R with adehabitat and rgdal packages.

Python and numpy, pywin32, rpy (or rpy2) libraries MUST be installed with the OSGeo4W installer!

Also QGIS standalone package is suitable as it contains rpy2 - thanks Jef

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.



- add multithreading support (cfr. branches/threading in SVN)
- upgrade to "adehabitat reloaded" that provides direct use of sp classes, but only when it will be available on CRAN.

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 (259.8 kB) Redmine Admin, 11/23/2011 04:44 pm

Homerange_plugin_screenshot1.png (74.2 kB) Redmine Admin, 11/23/2011 04:44 pm