2

I am executing the R code in python using rpy2 library where I was able to achieve a data frame that I wanted. The dataframe has column with geometry, now I am trying to read the created R dataframe as Pandas dataframe using ro.conversion.rpy2py, but when I try to do the same it is giving an empty data frame like below.

How do I convert R data frame with geometry column as an pandas data frame/ geo pandas data frame?

Code:-

from rpy2 import robjects
import rpy2.robjects as ro
robjects.r(''' 
  library(osrm)
  iso <- osrmIsochrone(loc = c(12.0878, 55.6419),
                       breaks = seq(from = 0, to = 60, length.out = 2), res = 50)
  print(iso)''')

output:-

Simple feature collection with 1 feature and 3 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 11.10805 ymin: 55.02879 xmax: 13.14378 ymax: 56.08983
Geodetic CRS:  WGS 84
  id isomin isomax                       geometry
1  1      0     60 MULTIPOLYGON (((12.54979 56...

#converting R dataframe to python data frame

r_mat = robjects.globalenv['iso']
pd_dt = ro.conversion.rpy2py(r_mat)
pd_dt

Output:-

R/rpy2 DataFrame (1 x 4)
id  isomin  isomax  geometry
... ... ... ...

enter image description here

Laurent
  • 12,287
  • 7
  • 21
  • 37
data en
  • 431
  • 1
  • 2
  • 9

0 Answers0