[Qgis-developer] [SoC] problems with R-Python data interchange
Anne Ghisla
a.ghisla at studenti.uninsubria.it
Thu Jul 10 06:47:48 EDT 2008
Hello all,
the progress of my work is being blocked by a data interchange problem
between R and Python.
I succeeded in converting a Python dictionary (containing lists) into a
dataframe and pass it to R. (line 160 of interfaccia.py)
The next step is to apply the function that calculates homeranges.
This function is called HR_cruncher and returns a list of lists, of
class "homerange" (custom class, it is not a standard R object).
Here is the piece of code. Full code is available on the repository [1],
updated right now. pluginProva is the folder of the plugin, just copy it
in QGIS python plugin folder.
r.require('rgdal')
r.require('adehabitat')
## FIXME: set more general import mode. But it runs.
motore = '~/apps/share/qgis/python/plugins/pluginProva/motore.R'
r.source(motore)
exporter =
'~/apps/share/qgis/python/plugins/pluginProva/exporter.R'
r.source(exporter)
print "DEBUG infos about the data dataframe"
print r.str(data) # it works also on no conversion mode. O_o ?!?
#FIXME: not sure if line below works. Sure that the exporter line
doesn't work.
#IDEA: if not easy to run around this problem, consider to source
an entire R script.
set_default_mode(NO_CONVERSION)
# homeranges = r("""HR_cruncher(data, method="mcp")""")
print "###"
print r.str(r("""HR_cruncher(data, method="mcp")""") )
Even if I use NO_CONVERSION mode, this is the output I obtain:
Loading required package: rgdal
Loading required package: sp
Geospatial Data Abstraction Library extensions to R successfully loaded
[...]
Loading required package: adehabitat
Loading required package: ade4
Attaching package: 'ade4'
[...]
Loading required package: gpclib
General Polygon Clipper Library for R (version 1.4-1)
Type 'class ? gpc.poly' for help
DEBUG infos about the data dataframe
'data.frame': 20 obs. of 3 variables:
$ Y : num 5109278 5109277 5109347 5109345 5109276 ...
$ X : num 1560413 1560417 1560477 1560465 1560555 ...
$ ID: Factor w/ 20 levels "CED02","CED03",..: 20 19 18 17 14 13 12 11
10 8 ...
<Robj object at 0xd0e470>
###
chr [1:3] "function" "OptionalFunction" "PossibleMethod"
<Robj object at 0xd0e470>
I guess that this kind of object has no possible conversion for Pyhton.
This is not a problem, because it has to be passed as is to the next R
function.
Any suggestions?
regards,
Anne
[1] svn://home.prea.net/svn/GSoC/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.osgeo.org/pipermail/qgis-developer/attachments/20080710/606b79fc/attachment-0001.bin
More information about the Qgis-developer
mailing list