[英]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. 我設法安裝了 package,但沒有使用它的 function。
我使用安裝了我需要的包(rgdal、sp、raster、lidR、io)
utils.install_packages(StrVector(names_to_install))
names_to_install
是仍未安裝的軟件包的列表。 這工作正常。
我知道如何嘗試“基本”函數,比如 sum,它可以工作:
import rpy2.robjects as robjects
function_sum = robjects.r['sum']
但同樣的方法似乎不適用於來自光柵 package 的光柵 function:
function_raster = robjects.r['raster']
因為我收到錯誤:
LookupError: 'raster' not found
我還嘗試了以下方法:
raster_package = importr('raster')
為了能夠運行下一個並加載我的光柵文件:
raster_package.raster(my_raster_file)
但第一行 (import('raster')) 導致 python 崩潰,我收到錯誤:
Process finished with exit code -1073741819 (0xC0000005)
這不會發生在其他加載的包(如 rgdal)中,但是使用光柵 package 和 lidR package 我得到錯誤。
我查了這個錯誤,似乎是訪問沖突,但我不知道我能做些什么以及為什么它只發生在某些包上。
我希望能夠從 package 柵格中調用柵格 function。
編輯
我在 windows 10 的計算機上嘗試過,運行時不再顯示錯誤
raster_package = importr('raster')
仍然很高興知道 Windows 7 有什么問題以及是否有任何解決方案。
rpy2
目前不支持 Windows。 這不是最終情況,可能需要的大部分內容是最終確定這一點的貢獻: https://github.com/rpy2/rpy2/blob/master/rpy2/rinterface_lib/embedded_mswin.py
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.