如何将 python 中生成的 MultiLineString 转换为 R 对象?

How to transform MultiLineString produced in python to R object?

我正在使用 reticulate 包在 R 代码中集成一个 python 函数,python 中的原始输出是 MultiLineString。 Class Rstudio 中的输出是:

> class(result)
[1] "centerline.geometry.Centerline"                   "shapely.geometry.multilinestring.MultiLineString"
[3] "shapely.geometry.base.BaseMultipartGeometry"      "shapely.geometry.base.BaseGeometry"              
[5] "python.builtin.object"

> typeof(result)
[1] "environment"

Rstudio 中的输出:

> result
MULTILINESTRING ((188.84310143 -25.44115933212567, 189.0883871453183 -25.39224242194983),
(189.34310143 -25.40412148482432, 189.0883871453183 -25.39224242194983))

我是 python 的新手,有什么方法可以在 python 或 R 中传输输出,以便我可以使用它来制作 Spatiallines 或 SF 对象?

#output of python function in R 
> class(result)
[1] "centerline.geometry.Centerline"                   "shapely.geometry.multilinestring.MultiLineString"
[3] "shapely.geometry.base.BaseMultipartGeometry"      "shapely.geometry.base.BaseGeometry"              
[5] "python.builtin.object"

> typeof(result)
[1] "environment"

#Convert from Python to R object 
processed <- reticulate::py_to_r(result)

#change type from environment to character 
result_2<-type.convert(processed,as.is = TRUE)

#read WKT and construct SpatialLines
x<-readWKT(result_2)


> x
class       : SpatialLines 
features    : 1 
extent      : 187.6103, 191.6382, -25.8519, -24.55464  (xmin, xmax, ymin, ymax)
crs         : NA