简体   繁体   English

如何在 rpy2 的 python 中使用光栅 package

[英]How to use raster package in python with rpy2

Working with R in Python using rpy2 on windows 7. I need to open some rasters as RasterLayer using the function raster() from the raster package. Working with R in Python using rpy2 on windows 7. I need to open some rasters as RasterLayer using the function raster() from the raster package. I manage to install the package, but not to use its function.我设法安装了 package,但没有使用它的 function。

I install the packages that I need (rgdal, sp, raster, lidR, io) using我使用安装了我需要的包(rgdal、sp、raster、lidR、io)

utils.install_packages(StrVector(names_to_install))

names_to_install is a list of the packages that are still not installed. names_to_install是仍未安装的软件包的列表。 This works fine.这工作正常。

I know how to try the "basic" functions, like sum, and it works:我知道如何尝试“基本”函数,比如 sum,它可以工作:

import rpy2.robjects as robjects
function_sum = robjects.r['sum']

But the same doesn't seem to work with the raster function from the raster package:但同样的方法似乎不适用于来自光栅 package 的光栅 function:

function_raster = robjects.r['raster']

since I get the error:因为我收到错误:

LookupError: 'raster' not found

I also tried the following:我还尝试了以下方法:

raster_package = importr('raster')

with the intention to be able to run the next and load my raster file:为了能够运行下一个并加载我的光栅文件:

raster_package.raster(my_raster_file)

but the first line (import('raster')) causes the crash of python and I get the error:但第一行 (import('raster')) 导致 python 崩溃,我收到错误:

Process finished with exit code -1073741819 (0xC0000005)

This doesn't happen with other loaded packages like rgdal, but with the raster package and with the lidR package I get the error.这不会发生在其他加载的包(如 rgdal)中,但是使用光栅 package 和 lidR package 我得到错误。

I looked up this error, seems to be access violation, but I don't know what I can do about it and why it only happens with certain packages.我查了这个错误,似乎是访问冲突,但我不知道我能做些什么以及为什么它只发生在某些包上。

I expect to be able to call the raster function from the package raster.我希望能够从 package 栅格中调用栅格 function。

Edit编辑

I tried it on a computer with windows 10 and the error doesn't show anymore when running我在 windows 10 的计算机上尝试过,运行时不再显示错误

raster_package = importr('raster')

Still would be nice to know what is the problem with Windows 7 and if there is any solution.仍然很高兴知道 Windows 7 有什么问题以及是否有任何解决方案。

rpy2 does not currently have Windows support. rpy2目前不支持 Windows。 This is not a final situation, most of what is likely needed is contributions to finalize this: https://github.com/rpy2/rpy2/blob/master/rpy2/rinterface_lib/embedded_mswin.py这不是最终情况,可能需要的大部分内容是最终确定这一点的贡献: https://github.com/rpy2/rpy2/blob/master/rpy2/rinterface_lib/embedded_mswin.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM