这个问题在这里已经有了答案:
使用Rcpp 1答案 从C ++调用用户定义的R函数任何人都有如何在Rcpp函数中使用geos的提示(我正在构建一个R包)? 其实,我正在寻找一个更好的方法,那么这个:
Rcpp::Environment rgeos_env = Environment::namespace_env("rgeos"); Rcpp::Function Dist = rgeos_env["gDistance"];情境化,我想计算空间多边形之间的距离,但我做了很多次( 蒙特卡洛测试 ),我想提高我的代码速度。
This question already has an answer here:
calling a user-defined R function from C++ using Rcpp 1 answerAnyone have a hint in how to use geos inside Rcpp functions (I'm building an R package)? Actually, I'm looking for a better approach then this:
Rcpp::Environment rgeos_env = Environment::namespace_env("rgeos"); Rcpp::Function Dist = rgeos_env["gDistance"];Contextualizing, I want to calculate distances between spatial polygons, but I do that a lot of times (Monte Carlo Tests) and I want to improve the speed of my code.
最满意答案
我看到两种可能的方法来使用geos,而不用从C ++返回到R:
尝试链接到rgeos包, 使用Rcpp中其他包的C函数
做rgeos软件包的工作,即链接geos库并调用相关函数,参见https://github.com/cran/rgeos/blob/28403d4d4adbc3bd76c11e4c55dec7e097d74f6d/src/rgeos_misc.c#L50
I see two possible approaches to use geos without going back to R from C++:
Try to link with the rgeos package, c.f. using C function from other package in Rcpp
Do what the rgeos package does, i.e. link with the geos library and call the relevant functions, c.f. https://github.com/cran/rgeos/blob/28403d4d4adbc3bd76c11e4c55dec7e097d74f6d/src/rgeos_misc.c#L50
更多推荐
发布评论