使发生数据和气候栅格中的 SpatialGridDataFrame 相互匹配
Make SpatialGridDataFrame from occurrence data and climate raster match each other
我有两个 SpatialGridDataFrame
,一个是根据物种出现数据创建的,另一个是根据气候数据栅格创建的。我需要使两个网格相互匹配以执行物种多样性模型。我正在努力使两个对象的网格拓扑相同,这是 运行 我将使用的函数所必需的。
以下是我的数据的可重复性子集:
bioclim <- structure(list(x = c(-83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.5543059413, -83.545972608,
-83.5376392747, -83.5293059414, -83.5209726081, -83.5126392748,
-83.5043059415, -83.4959726082, -83.4876392749, -83.4793059416,
-83.4709726083, -83.462639275, -83.4543059417, -83.4459726084,
-83.4376392751, -83.4293059418, -83.4209726085, -83.4126392752,
-83.4043059419, -83.3959726086, -83.3876392753, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.3959726086, -83.3876392753,
-83.379305942, -83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.4043059419,
-83.3959726086, -83.3876392753, -83.379305942, -83.3709726087,
-83.5543059413, -83.545972608, -83.5376392747, -83.5293059414,
-83.5209726081, -83.5126392748, -83.5043059415, -83.4959726082,
-83.4876392749, -83.4793059416, -83.4709726083, -83.462639275,
-83.4543059417, -83.4459726084, -83.4376392751, -83.4293059418,
-83.4209726085, -83.4126392752, -83.4043059419, -83.3959726086,
-83.3876392753, -83.379305942, -83.3709726087, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.3959726086, -83.3876392753,
-83.379305942, -83.3709726087, -83.5543059413, -83.545972608,
-83.5376392747, -83.5293059414, -83.5209726081, -83.5126392748,
-83.5043059415, -83.4959726082, -83.4876392749, -83.4793059416,
-83.4709726083, -83.462639275, -83.4543059417, -83.4459726084,
-83.4376392751, -83.4293059418, -83.4209726085, -83.4126392752,
-83.4043059419, -83.3959726086, -83.3876392753, -83.379305942,
-83.3709726087, -83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.4043059419,
-83.3959726086, -83.3876392753, -83.379305942, -83.3709726087,
-83.5543059413, -83.545972608, -83.5376392747, -83.5293059414,
-83.5209726081, -83.5126392748, -83.5043059415, -83.4959726082,
-83.4876392749, -83.4793059416, -83.4709726083, -83.462639275,
-83.4543059417, -83.4459726084, -83.4376392751, -83.4293059418,
-83.4209726085, -83.4126392752, -83.4043059419, -83.3959726086,
-83.3876392753, -83.379305942, -83.3709726087, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.3959726086, -83.3876392753,
-83.379305942, -83.3709726087, -83.5543059413, -83.545972608,
-83.5376392747, -83.5293059414, -83.5209726081, -83.5126392748,
-83.5043059415, -83.4959726082, -83.4876392749, -83.4793059416,
-83.4709726083, -83.462639275, -83.4543059417, -83.4459726084,
-83.4376392751, -83.4293059418, -83.4209726085, -83.4126392752,
-83.4043059419, -83.3959726086, -83.3876392753, -83.379305942,
-83.3709726087, -83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.4043059419,
-83.3959726086, -83.3876392753, -83.379305942, -83.3709726087,
-83.5543059413, -83.545972608, -83.5376392747, -83.5293059414,
-83.5209726081, -83.5126392748, -83.5043059415, -83.4959726082,
-83.4876392749, -83.4793059416, -83.4709726083, -83.462639275,
-83.4543059417, -83.4459726084, -83.4376392751, -83.4293059418,
-83.4209726085, -83.4126392752, -83.4043059419, -83.3959726086,
-83.3876392753, -83.379305942, -83.3709726087, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.3959726086, -83.3876392753,
-83.379305942, -83.3709726087, -83.5543059413, -83.545972608,
-83.5376392747, -83.5293059414, -83.5209726081, -83.5126392748,
-83.5043059415, -83.4959726082, -83.4876392749, -83.4793059416,
-83.4709726083, -83.462639275, -83.4543059417, -83.4459726084,
-83.4376392751, -83.4293059418, -83.4209726085, -83.4126392752,
-83.4043059419, -83.3959726086, -83.3876392753, -83.379305942,
-83.3709726087, -83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.4043059419,
-83.3959726086, -83.3876392753, -83.379305942, -83.3709726087,
-83.5543059413, -83.545972608, -83.5376392747, -83.5293059414,
-83.5209726081, -83.5126392748, -83.5043059415, -83.4959726082,
-83.4876392749, -83.4793059416, -83.4709726083, -83.462639275,
-83.4543059417, -83.4459726084, -83.4376392751, -83.4293059418,
-83.4209726085, -83.4126392752, -83.4043059419, -83.3959726086,
-83.3876392753, -83.379305942, -83.3709726087, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.3959726086, -83.3876392753,
-83.379305942, -83.3709726087, -83.5543059413, -83.545972608,
-83.5376392747, -83.5293059414, -83.5209726081, -83.5126392748,
-83.5043059415, -83.4959726082, -83.4876392749, -83.4793059416,
-83.4709726083, -83.462639275, -83.4543059417, -83.4459726084,
-83.4376392751, -83.4293059418, -83.4209726085, -83.4126392752,
-83.4043059419, -83.3959726086, -83.3876392753, -83.379305942,
-83.3709726087, -83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.4043059419,
-83.3959726086, -83.3876392753, -83.379305942, -83.3709726087,
-83.4876392749, -83.4793059416, -83.4709726083, -83.462639275,
-83.4543059417, -83.4459726084, -83.4376392751, -83.4293059418,
-83.4209726085, -83.4126392752, -83.4043059419, -83.3959726086,
-83.3876392753, -83.379305942, -83.3709726087), y = c(8.61236071670001,
8.61236071670001, 8.61236071670001, 8.61236071670001, 8.61236071670001,
8.61236071670001, 8.61236071670001, 8.61236071670001, 8.61236071670001,
8.61236071670001, 8.61236071670001, 8.61236071670001, 8.61236071670001,
8.61236071670001, 8.61236071670001, 8.61236071670001, 8.61236071670001,
8.61236071670001, 8.60402738340001, 8.60402738340001, 8.60402738340001,
8.60402738340001, 8.60402738340001, 8.60402738340001, 8.60402738340001,
8.60402738340001, 8.60402738340001, 8.60402738340001, 8.60402738340001,
8.60402738340001, 8.60402738340001, 8.60402738340001, 8.60402738340001,
8.60402738340001, 8.60402738340001, 8.60402738340001, 8.60402738340001,
8.59569405010001, 8.59569405010001, 8.59569405010001, 8.59569405010001,
8.59569405010001, 8.59569405010001, 8.59569405010001, 8.59569405010001,
8.59569405010001, 8.59569405010001, 8.59569405010001, 8.59569405010001,
8.59569405010001, 8.59569405010001, 8.59569405010001, 8.59569405010001,
8.59569405010001, 8.59569405010001, 8.59569405010001, 8.59569405010001,
8.59569405010001, 8.58736071680001, 8.58736071680001, 8.58736071680001,
8.58736071680001, 8.58736071680001, 8.58736071680001, 8.58736071680001,
8.58736071680001, 8.58736071680001, 8.58736071680001, 8.58736071680001,
8.58736071680001, 8.58736071680001, 8.58736071680001, 8.58736071680001,
8.58736071680001, 8.58736071680001, 8.58736071680001, 8.58736071680001,
8.58736071680001, 8.58736071680001, 8.58736071680001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57902738350001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57902738350001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57902738350001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57902738350001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57902738350001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.57069405020001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.57069405020001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.57069405020001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.57069405020001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.57069405020001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.56236071690001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.56236071690001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.56236071690001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.56236071690001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.56236071690001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.55402738360001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.55402738360001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.55402738360001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.55402738360001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.55402738360001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.54569405030001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.54569405030001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.54569405030001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.54569405030001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.54569405030001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.53736071700001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.53736071700001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.53736071700001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.53736071700001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.53736071700001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52902738370001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52902738370001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52902738370001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52902738370001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52902738370001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.52069405040001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.52069405040001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.52069405040001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.52069405040001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.52069405040001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.51236071710001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.51236071710001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.51236071710001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.51236071710001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.51236071710001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.50402738380001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.50402738380001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.50402738380001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.50402738380001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.50402738380001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.49569405050001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.49569405050001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.49569405050001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.49569405050001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.49569405050001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.48736071720001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.48736071720001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.48736071720001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.48736071720001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.48736071720001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47902738390001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47902738390001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47902738390001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47902738390001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47902738390001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.47069405060001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.47069405060001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.47069405060001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.47069405060001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.47069405060001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.46236071730001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.46236071730001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.46236071730001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.46236071730001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.46236071730001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.45402738400001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.45402738400001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.45402738400001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.45402738400001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.45402738400001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.44569405070001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.44569405070001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.44569405070001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.44569405070001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.44569405070001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.43736071740001, 8.43736071740001,
8.43736071740001, 8.43736071740001, 8.43736071740001, 8.43736071740001,
8.43736071740001, 8.43736071740001, 8.43736071740001, 8.43736071740001,
8.43736071740001, 8.43736071740001, 8.43736071740001, 8.43736071740001,
8.43736071740001), CHELSA_bio1_1981.2010_V.2.1 = c(24.55, 24.55,
24.7500000000001, 24.95, 24.95, 25.15, 25.35, 25.7500000000001,
25.65, 25.65, 25.65, 25.65, 25.7500000000001, 25.85, 25.85, 25.85,
25.85, 25.95, 24.65, 24.7500000000001, 25.05, 25.15, 25.35, 25.2500000000001,
25.45, 25.55, 25.2500000000001, 25.35, 25.45, 25.65, 25.7500000000001,
25.7500000000001, 25.85, 25.85, 25.85, 25.85, 25.95, 25.05, 24.95,
25.05, 25.05, 25.15, 25.45, 25.45, 25.55, 25.05, 25.05, 25.35,
25.45, 25.65, 25.7500000000001, 25.7500000000001, 25.85, 25.85,
25.85, 25.95, 25.95, 25.95, 24.85, 25.05, 25.15, 25.2500000000001,
25.2500000000001, 25.05, 25.35, 25.35, 24.85, 25.05, 25.35, 25.2500000000001,
25.55, 25.55, 25.55, 25.7500000000001, 25.85, 25.85, 25.85, 25.95,
25.95, 25.95, 25.05, 25.15, 25.2500000000001, 25.35, 25.15, 25.2500000000001,
25.15, 25.35, 25.15, 24.95, 25.05, 25.35, 25.35, 25.15, 25.45,
25.65, 25.7500000000001, 25.85, 25.85, 25.85, 25.85, 25.85, 25.95,
25.2500000000001, 25.35, 25.35, 25.2500000000001, 25.2500000000001,
25.2500000000001, 25.35, 25.05, 24.95, 24.95, 25.2500000000001,
24.95, 24.95, 25.2500000000001, 25.35, 25.45, 25.55, 25.7500000000001,
25.85, 25.85, 25.85, 25.85, 25.85, 25.65, 25.55, 25.45, 25.35,
25.15, 25.05, 25.2500000000001, 25.15, 24.65, 24.65, 24.65, 24.85,
25.05, 25.35, 25.35, 25.35, 25.45, 25.65, 25.7500000000001, 25.85,
25.85, 25.85, 25.95, 25.85, 25.85, 25.65, 25.45, 25.15, 24.85,
24.95, 25.05, 24.85, 24.35, 24.45, 24.55, 24.55, 24.85, 25.05,
25.35, 25.45, 25.65, 25.65, 25.7500000000001, 25.7500000000001,
25.85, 25.85, 25.85, 25.7500000000001, 25.65, 25.45, 25.2500000000001,
24.85, 24.95, 24.55, 24.55, 23.7500000000001, 23.7500000000001,
23.85, 23.95, 24.45, 24.85, 25.05, 25.45, 25.55, 25.7500000000001,
25.65, 25.55, 25.65, 25.7500000000001, 25.7500000000001, 25.7500000000001,
25.65, 25.45, 25.35, 24.95, 24.55, 24.45, 24.65, 24.05, 23.35,
23.2500000000001, 23.7500000000001, 24.05, 24.55, 24.7500000000001,
24.95, 25.2500000000001, 25.45, 25.55, 25.55, 25.7500000000001,
25.7500000000001, 25.65, 25.65, 25.55, 25.35, 25.2500000000001,
24.7500000000001, 24.35, 24.45, 24.55, 24.15, 23.55, 22.95, 23.2500000000001,
23.45, 24.05, 24.2500000000001, 24.85, 25.2500000000001, 25.45,
25.65, 25.65, 25.65, 25.7500000000001, 25.65, 25.45, 25.55, 25.2500000000001,
24.85, 24.55, 24.2500000000001, 24.15, 23.85, 23.05, 22.65, 22.7500000000001,
23.35, 23.85, 24.55, 24.7500000000001, 24.55, 25.05, 25.2500000000001,
25.35, 25.45, 25.65, 25.55, 25.55, 25.45, 25.35, 25.05, 24.85,
24.65, 24.35, 23.95, 23.7500000000001, 23.15, 22.55, 22.55, 23.05,
23.7500000000001, 24.35, 24.35, 24.2500000000001, 24.65, 25.15,
25.15, 25.45, 25.55, 25.55, 25.35, 25.2500000000001, 25.05, 25.15,
24.95, 24.55, 24.35, 23.85, 23.2500000000001, 23.05, 22.65, 22.85,
23.15, 23.65, 24.05, 24.55, 24.85, 25.15, 24.85, 24.85, 25.15,
25.45, 25.65, 25.65, 25.35, 25.2500000000001, 25.15, 24.85, 24.45,
24.15, 24.2500000000001, 23.65, 23.65, 23.2500000000001, 23.7500000000001,
24.05, 24.2500000000001, 24.35, 24.35, 24.65, 24.85, 25.15, 25.2500000000001,
25.45, 25.45, 25.35, 25.15, 25.2500000000001, 24.95, 24.7500000000001,
24.65, 24.85, 24.65, 24.2500000000001, 24.15, 24.15, 23.45, 23.85,
23.7500000000001, 23.95, 24.2500000000001, 24.35, 24.65, 24.85,
25.2500000000001, 25.2500000000001, 25.2500000000001, 25.15,
25.45, 24.85, 24.95, 25.05, 24.95, 24.35, 24.15, 24.15, 24.05,
24.2500000000001, 24.35, 24.2500000000001, 24.05, 23.85, 24.05,
23.95, 24.15, 24.65, 24.85, 25.05, 25.15, 25.05, 25.2500000000001,
25.15, 24.7500000000001, 24.65, 24.85, 24.7500000000001, 24.35,
24.05, 24.2500000000001, 24.45, 24.55, 24.95, 24.65, 24.65, 24.15,
24.2500000000001, 24.15, 24.2500000000001, 24.7500000000001,
24.85, 24.95, 25.15, 24.95, 25.15, 25.05, 25.05, 24.45, 24.85,
24.35, 24.45, 24.35, 24.7500000000001, 25.15, 25.05, 24.95, 24.85,
25.15, 24.45, 24.65, 25.05, 25.15, 25.05, 25.15, 25.35, 25.45,
25.35, 25.35, 25.35, 24.95, 24.7500000000001, 24.7500000000001,
24.85, 25.05, 24.95, 25.35, 25.35, 25.35, 25.05, 25.05, 25.45,
24.95, 24.85, 24.95, 25.2500000000001, 25.55, 25.45, 25.55, 25.55,
25.7500000000001, 25.65, 25.55, 25.55, 25.35, 25.55, 25.95, 26.05,
26.05, 26.05, 26.05, 26.05, 25.95, 25.85, 25.85, 25.65, 25.7500000000001,
25.65, 25.7500000000001, 25.55, 25.7500000000001, 25.95, 25.7500000000001,
25.85, 25.95, 25.7500000000001, 26.15, 26.15, 26.15, 26.15, 26.15,
26.15, 26.15, 26.05, 26.05, 26.05, 26.15, 26.15, 26.15, 26.05,
25.65)), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 24L, 25L, 26L, 27L, 28L,
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
42L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L,
59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 70L, 71L, 72L, 73L,
74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L,
87L, 88L, 89L, 90L, 91L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L,
101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L,
112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L,
123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L,
134L, 135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L,
145L, 146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L,
156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L,
167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L,
178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L,
189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L,
200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L, 209L, 210L,
211L, 212L, 213L, 214L, 215L, 216L, 217L, 218L, 219L, 220L, 221L,
222L, 223L, 224L, 225L, 226L, 227L, 228L, 229L, 230L, 231L, 232L,
233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 241L, 242L, 243L,
244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L, 252L, 253L, 254L,
255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 263L, 264L, 265L,
266L, 267L, 268L, 269L, 270L, 271L, 272L, 273L, 274L, 275L, 276L,
277L, 278L, 279L, 280L, 281L, 282L, 283L, 284L, 285L, 286L, 287L,
288L, 289L, 290L, 291L, 292L, 293L, 294L, 295L, 296L, 297L, 298L,
299L, 300L, 301L, 302L, 303L, 304L, 305L, 306L, 307L, 308L, 309L,
310L, 311L, 312L, 313L, 314L, 315L, 316L, 317L, 318L, 319L, 320L,
321L, 322L, 323L, 324L, 325L, 326L, 327L, 328L, 329L, 330L, 331L,
332L, 333L, 334L, 335L, 336L, 337L, 338L, 339L, 340L, 341L, 342L,
343L, 344L, 345L, 346L, 347L, 348L, 349L, 350L, 351L, 352L, 353L,
354L, 355L, 356L, 357L, 358L, 359L, 360L, 361L, 362L, 363L, 364L,
365L, 366L, 367L, 368L, 369L, 370L, 371L, 372L, 373L, 374L, 375L,
376L, 377L, 378L, 379L, 380L, 381L, 382L, 383L, 384L, 385L, 386L,
387L, 388L, 389L, 390L, 391L, 392L, 393L, 394L, 395L, 396L, 397L,
398L, 399L, 400L, 401L, 402L, 403L, 404L, 405L, 406L, 407L, 408L,
409L, 410L, 411L, 412L, 413L, 414L, 415L, 416L, 417L, 418L, 419L,
420L, 421L, 422L, 423L, 424L, 425L, 426L, 427L, 428L, 429L, 430L,
431L, 432L, 433L, 434L, 435L, 436L, 437L, 438L, 439L, 440L, 441L,
442L, 443L, 444L, 445L, 446L, 447L, 448L, 449L, 450L, 451L, 452L,
453L, 454L, 455L, 456L, 457L, 458L, 459L, 460L, 461L, 462L, 463L,
464L, 465L, 466L, 467L, 468L, 469L, 470L, 471L, 472L, 473L, 474L,
475L, 476L, 477L, 478L, 479L, 480L, 481L, 482L, 483L, 492L, 493L,
494L, 495L, 496L, 497L, 498L, 499L, 500L, 501L, 502L, 503L, 504L,
505L, 506L), class = "data.frame")
occ_df <- structure(list(lon = c(-83.41, -83.51, -83.41143, -83.525, -83.46,
-83.46, -83.43, -83.49, -83.41, -83.44, -83.46944, -83.427778,
-83.516667, -83.433609, -83.411431, -83.55, -83.516805), lat = c(8.54,
8.56, 8.540221, 8.540278, 8.51, 8.52, 8.52, 8.45, 8.52, 8.52,
8.51805, 8.525, 8.566667, 8.531329, 8.540221, 8.45, 8.569294),
`Chrysochlamys glauca` = c(1, 1, 1, 1, 0, 0, 0, 1, 0, 0,
0, 1, 1, 1, 1, 1, 0), `Ocotea atirrensis` = c(0, 1, 0, 0,
1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -17L))
这是我目前拥有的
library(dplyr)
clim <- terra::rast(bioclim)
terra::crs(clim) <- "+proj=longlat +datum=WGS84 +no_defs"
clim_sg_df <- raster::raster(clim) %>%
as("SpatialGridDataFrame")
occ <- occ_df %>%
# rounding lon/lat to fix inconstant coordinate intervals when using gridded()
mutate(across(
matches("lon|lat"),
~ round(.x, 2)
))
sp::coordinates(occ) <- ~ lon + lat
sp::proj4string(occ) <- "+proj=longlat +datum=WGS84 +no_defs"
sp::gridded(occ) <- TRUE
occ_sg_df <- as(occ_sp, "SpatialGridDataFrame")
# terra::plot(clim_sg_df)
# terra::plot(occ_sg_df, add = TRUE)
我有两个主要问题。首先,尽管有相同的投影,但我无法将两个网格绘制在彼此之上,所以我怀疑我的代码有错误。第二,两个对象之间的网格大小不同,我真的不知道如何将它们均质化。
我需要让 clim_sg_df
和 occ_sg_df
相互匹配,以便满足以下条件 returns TRUE
:
identical(as(occ_sg_df, "SpatialGrid"), as(clim_sg_df, "SpatialGrid"))
请注意,我需要保留栅格中的所有像元并使用 sp
包,因为这是我将用于分析的函数所需要的。
#here you have first raster created
clim <- terra::rast(bioclim)
terra::crs(clim) <- "+proj=longlat +datum=WGS84 +no_defs"
#lets create another raster with exactly the same size
#lets clear it
#
occ <- clim
occ[] <- NA
occ_df <- occ_df %>%
# rounding lon/lat to fix inconstant coordinate intervals when using gridded()
mutate(across(
matches("lon|lat"),
~ round(.x, 2)
))
sp::coordinates(occ_df) <- ~ lon + lat
sp::proj4string(occ_df) <- "+proj=longlat +datum=WGS84 +no_defs"
# lets create a vector object which later will be used for rasterization
occ_vec <- vect(occ_df)
# now the important step - rasterizing vector data over raster grid
#
occ <- rasterize(occ_vec, occ)
terra::plot(clim)
terra::plot(occ, add = TRUE )
由 reprex package (v2.0.1)
创建于 2022-01-24
PS。为了更好的可见性,您可以更改颜色,例如
terra::plot(occ, add = TRUE, col = "red" )
您应该使用 rasterize
而不是 gridded
。例如这个光栅和这些点:
library(terra)
r <- rast(system.file("ex/elev.tif", package="terra"))
set.seed(123)
pts <- spatSample(r, 1000, xy=TRUE, na.rm=TRUE, replace=TRUE)
xy <- as.matrix(pts[, c("x", "y")])
你可以做到
spp <- rasterize(xy, r)
或者按单元格统计出现次数
spp <- rasterize(xy, r, 1, fun=sum)
除了矩阵,您还可以使用 SpatVector
个点。
在一张地图上绘制两个重叠的栅格绝非易事,但 Grzegorz Sapijaszko 展示了如何做到这一点。您还可以使用透明度。但通常只在栅格顶部添加点更有意义:
plot(r)
points(xy, cex=.5)
或者有一个点的单元格的中心
pspp <- as.points(spp)
plot(r)
points(pspp, cex=.25)
或者添加单元格的轮廓(如果出现的单元格数量不是太多)
polspp <- as.polygons(spp)
plot(r)
lines(polspp)
使用 R 附带的示例数据更方便,但您可以使用您的示例数据
library(terra)
r <- rast(bioclim)
pts <- vect(data.frame(occ_df), geom=c("lon", "lat"))
x <- rasterize(pts, r)
plot(r)
lines(as.polygons(x))
points(pts, col="red")
在您的示例数据中,您有多个物种。
pts
# class : SpatVector
# geometry : points
# dimensions : 17, 2 (geometries, attributes)
# extent : -83.55, -83.41, 8.45, 8.569294 (xmin, xmax, ymin, ymax)
# coord. ref. :
# names : Chrysochlamys.glauca Ocotea.atirrensis
# type : <num> <num>
# values : 1 0
# 1 1
# 1 0
您可以像这样将 pts
子集化为单个物种
glauca <- pts[pts$Chrysochlamys.glauca == 1, ]
如果您愿意,也可以使用 raster::rasterize
(带有 RasterLayer
和矩阵或 SpatialPointsDataFrame
)。或者像这样将对象从 terra
强制返回到 raster
/sp
:
library(raster)
xr <- raster(x)
pp <- as(pts, "Spatial")
plot(xr)
points(pp)
我有两个 SpatialGridDataFrame
,一个是根据物种出现数据创建的,另一个是根据气候数据栅格创建的。我需要使两个网格相互匹配以执行物种多样性模型。我正在努力使两个对象的网格拓扑相同,这是 运行 我将使用的函数所必需的。
以下是我的数据的可重复性子集:
bioclim <- structure(list(x = c(-83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.5543059413, -83.545972608,
-83.5376392747, -83.5293059414, -83.5209726081, -83.5126392748,
-83.5043059415, -83.4959726082, -83.4876392749, -83.4793059416,
-83.4709726083, -83.462639275, -83.4543059417, -83.4459726084,
-83.4376392751, -83.4293059418, -83.4209726085, -83.4126392752,
-83.4043059419, -83.3959726086, -83.3876392753, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.3959726086, -83.3876392753,
-83.379305942, -83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.4043059419,
-83.3959726086, -83.3876392753, -83.379305942, -83.3709726087,
-83.5543059413, -83.545972608, -83.5376392747, -83.5293059414,
-83.5209726081, -83.5126392748, -83.5043059415, -83.4959726082,
-83.4876392749, -83.4793059416, -83.4709726083, -83.462639275,
-83.4543059417, -83.4459726084, -83.4376392751, -83.4293059418,
-83.4209726085, -83.4126392752, -83.4043059419, -83.3959726086,
-83.3876392753, -83.379305942, -83.3709726087, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.3959726086, -83.3876392753,
-83.379305942, -83.3709726087, -83.5543059413, -83.545972608,
-83.5376392747, -83.5293059414, -83.5209726081, -83.5126392748,
-83.5043059415, -83.4959726082, -83.4876392749, -83.4793059416,
-83.4709726083, -83.462639275, -83.4543059417, -83.4459726084,
-83.4376392751, -83.4293059418, -83.4209726085, -83.4126392752,
-83.4043059419, -83.3959726086, -83.3876392753, -83.379305942,
-83.3709726087, -83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.4043059419,
-83.3959726086, -83.3876392753, -83.379305942, -83.3709726087,
-83.5543059413, -83.545972608, -83.5376392747, -83.5293059414,
-83.5209726081, -83.5126392748, -83.5043059415, -83.4959726082,
-83.4876392749, -83.4793059416, -83.4709726083, -83.462639275,
-83.4543059417, -83.4459726084, -83.4376392751, -83.4293059418,
-83.4209726085, -83.4126392752, -83.4043059419, -83.3959726086,
-83.3876392753, -83.379305942, -83.3709726087, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.3959726086, -83.3876392753,
-83.379305942, -83.3709726087, -83.5543059413, -83.545972608,
-83.5376392747, -83.5293059414, -83.5209726081, -83.5126392748,
-83.5043059415, -83.4959726082, -83.4876392749, -83.4793059416,
-83.4709726083, -83.462639275, -83.4543059417, -83.4459726084,
-83.4376392751, -83.4293059418, -83.4209726085, -83.4126392752,
-83.4043059419, -83.3959726086, -83.3876392753, -83.379305942,
-83.3709726087, -83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.4043059419,
-83.3959726086, -83.3876392753, -83.379305942, -83.3709726087,
-83.5543059413, -83.545972608, -83.5376392747, -83.5293059414,
-83.5209726081, -83.5126392748, -83.5043059415, -83.4959726082,
-83.4876392749, -83.4793059416, -83.4709726083, -83.462639275,
-83.4543059417, -83.4459726084, -83.4376392751, -83.4293059418,
-83.4209726085, -83.4126392752, -83.4043059419, -83.3959726086,
-83.3876392753, -83.379305942, -83.3709726087, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.3959726086, -83.3876392753,
-83.379305942, -83.3709726087, -83.5543059413, -83.545972608,
-83.5376392747, -83.5293059414, -83.5209726081, -83.5126392748,
-83.5043059415, -83.4959726082, -83.4876392749, -83.4793059416,
-83.4709726083, -83.462639275, -83.4543059417, -83.4459726084,
-83.4376392751, -83.4293059418, -83.4209726085, -83.4126392752,
-83.4043059419, -83.3959726086, -83.3876392753, -83.379305942,
-83.3709726087, -83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.4043059419,
-83.3959726086, -83.3876392753, -83.379305942, -83.3709726087,
-83.5543059413, -83.545972608, -83.5376392747, -83.5293059414,
-83.5209726081, -83.5126392748, -83.5043059415, -83.4959726082,
-83.4876392749, -83.4793059416, -83.4709726083, -83.462639275,
-83.4543059417, -83.4459726084, -83.4376392751, -83.4293059418,
-83.4209726085, -83.4126392752, -83.4043059419, -83.3959726086,
-83.3876392753, -83.379305942, -83.3709726087, -83.5543059413,
-83.545972608, -83.5376392747, -83.5293059414, -83.5209726081,
-83.5126392748, -83.5043059415, -83.4959726082, -83.4876392749,
-83.4793059416, -83.4709726083, -83.462639275, -83.4543059417,
-83.4459726084, -83.4376392751, -83.4293059418, -83.4209726085,
-83.4126392752, -83.4043059419, -83.3959726086, -83.3876392753,
-83.379305942, -83.3709726087, -83.5543059413, -83.545972608,
-83.5376392747, -83.5293059414, -83.5209726081, -83.5126392748,
-83.5043059415, -83.4959726082, -83.4876392749, -83.4793059416,
-83.4709726083, -83.462639275, -83.4543059417, -83.4459726084,
-83.4376392751, -83.4293059418, -83.4209726085, -83.4126392752,
-83.4043059419, -83.3959726086, -83.3876392753, -83.379305942,
-83.3709726087, -83.5543059413, -83.545972608, -83.5376392747,
-83.5293059414, -83.5209726081, -83.5126392748, -83.5043059415,
-83.4959726082, -83.4876392749, -83.4793059416, -83.4709726083,
-83.462639275, -83.4543059417, -83.4459726084, -83.4376392751,
-83.4293059418, -83.4209726085, -83.4126392752, -83.4043059419,
-83.3959726086, -83.3876392753, -83.379305942, -83.3709726087,
-83.4876392749, -83.4793059416, -83.4709726083, -83.462639275,
-83.4543059417, -83.4459726084, -83.4376392751, -83.4293059418,
-83.4209726085, -83.4126392752, -83.4043059419, -83.3959726086,
-83.3876392753, -83.379305942, -83.3709726087), y = c(8.61236071670001,
8.61236071670001, 8.61236071670001, 8.61236071670001, 8.61236071670001,
8.61236071670001, 8.61236071670001, 8.61236071670001, 8.61236071670001,
8.61236071670001, 8.61236071670001, 8.61236071670001, 8.61236071670001,
8.61236071670001, 8.61236071670001, 8.61236071670001, 8.61236071670001,
8.61236071670001, 8.60402738340001, 8.60402738340001, 8.60402738340001,
8.60402738340001, 8.60402738340001, 8.60402738340001, 8.60402738340001,
8.60402738340001, 8.60402738340001, 8.60402738340001, 8.60402738340001,
8.60402738340001, 8.60402738340001, 8.60402738340001, 8.60402738340001,
8.60402738340001, 8.60402738340001, 8.60402738340001, 8.60402738340001,
8.59569405010001, 8.59569405010001, 8.59569405010001, 8.59569405010001,
8.59569405010001, 8.59569405010001, 8.59569405010001, 8.59569405010001,
8.59569405010001, 8.59569405010001, 8.59569405010001, 8.59569405010001,
8.59569405010001, 8.59569405010001, 8.59569405010001, 8.59569405010001,
8.59569405010001, 8.59569405010001, 8.59569405010001, 8.59569405010001,
8.59569405010001, 8.58736071680001, 8.58736071680001, 8.58736071680001,
8.58736071680001, 8.58736071680001, 8.58736071680001, 8.58736071680001,
8.58736071680001, 8.58736071680001, 8.58736071680001, 8.58736071680001,
8.58736071680001, 8.58736071680001, 8.58736071680001, 8.58736071680001,
8.58736071680001, 8.58736071680001, 8.58736071680001, 8.58736071680001,
8.58736071680001, 8.58736071680001, 8.58736071680001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57902738350001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57902738350001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57902738350001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57902738350001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57902738350001, 8.57902738350001,
8.57902738350001, 8.57902738350001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.57069405020001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.57069405020001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.57069405020001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.57069405020001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.57069405020001, 8.57069405020001, 8.57069405020001,
8.57069405020001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.56236071690001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.56236071690001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.56236071690001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.56236071690001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.56236071690001, 8.56236071690001, 8.56236071690001, 8.56236071690001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.55402738360001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.55402738360001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.55402738360001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.55402738360001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.55402738360001,
8.55402738360001, 8.55402738360001, 8.55402738360001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.54569405030001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.54569405030001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.54569405030001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.54569405030001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.54569405030001, 8.54569405030001,
8.54569405030001, 8.54569405030001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.53736071700001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.53736071700001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.53736071700001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.53736071700001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.53736071700001, 8.53736071700001, 8.53736071700001,
8.53736071700001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52902738370001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52902738370001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52902738370001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52902738370001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52902738370001, 8.52902738370001, 8.52902738370001, 8.52902738370001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.52069405040001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.52069405040001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.52069405040001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.52069405040001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.52069405040001,
8.52069405040001, 8.52069405040001, 8.52069405040001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.51236071710001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.51236071710001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.51236071710001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.51236071710001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.51236071710001, 8.51236071710001,
8.51236071710001, 8.51236071710001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.50402738380001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.50402738380001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.50402738380001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.50402738380001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.50402738380001, 8.50402738380001, 8.50402738380001,
8.50402738380001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.49569405050001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.49569405050001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.49569405050001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.49569405050001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.49569405050001, 8.49569405050001, 8.49569405050001, 8.49569405050001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.48736071720001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.48736071720001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.48736071720001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.48736071720001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.48736071720001,
8.48736071720001, 8.48736071720001, 8.48736071720001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47902738390001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47902738390001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47902738390001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47902738390001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47902738390001, 8.47902738390001,
8.47902738390001, 8.47902738390001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.47069405060001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.47069405060001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.47069405060001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.47069405060001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.47069405060001, 8.47069405060001, 8.47069405060001,
8.47069405060001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.46236071730001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.46236071730001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.46236071730001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.46236071730001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.46236071730001, 8.46236071730001, 8.46236071730001, 8.46236071730001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.45402738400001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.45402738400001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.45402738400001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.45402738400001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.45402738400001,
8.45402738400001, 8.45402738400001, 8.45402738400001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.44569405070001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.44569405070001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.44569405070001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.44569405070001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.44569405070001, 8.44569405070001,
8.44569405070001, 8.44569405070001, 8.43736071740001, 8.43736071740001,
8.43736071740001, 8.43736071740001, 8.43736071740001, 8.43736071740001,
8.43736071740001, 8.43736071740001, 8.43736071740001, 8.43736071740001,
8.43736071740001, 8.43736071740001, 8.43736071740001, 8.43736071740001,
8.43736071740001), CHELSA_bio1_1981.2010_V.2.1 = c(24.55, 24.55,
24.7500000000001, 24.95, 24.95, 25.15, 25.35, 25.7500000000001,
25.65, 25.65, 25.65, 25.65, 25.7500000000001, 25.85, 25.85, 25.85,
25.85, 25.95, 24.65, 24.7500000000001, 25.05, 25.15, 25.35, 25.2500000000001,
25.45, 25.55, 25.2500000000001, 25.35, 25.45, 25.65, 25.7500000000001,
25.7500000000001, 25.85, 25.85, 25.85, 25.85, 25.95, 25.05, 24.95,
25.05, 25.05, 25.15, 25.45, 25.45, 25.55, 25.05, 25.05, 25.35,
25.45, 25.65, 25.7500000000001, 25.7500000000001, 25.85, 25.85,
25.85, 25.95, 25.95, 25.95, 24.85, 25.05, 25.15, 25.2500000000001,
25.2500000000001, 25.05, 25.35, 25.35, 24.85, 25.05, 25.35, 25.2500000000001,
25.55, 25.55, 25.55, 25.7500000000001, 25.85, 25.85, 25.85, 25.95,
25.95, 25.95, 25.05, 25.15, 25.2500000000001, 25.35, 25.15, 25.2500000000001,
25.15, 25.35, 25.15, 24.95, 25.05, 25.35, 25.35, 25.15, 25.45,
25.65, 25.7500000000001, 25.85, 25.85, 25.85, 25.85, 25.85, 25.95,
25.2500000000001, 25.35, 25.35, 25.2500000000001, 25.2500000000001,
25.2500000000001, 25.35, 25.05, 24.95, 24.95, 25.2500000000001,
24.95, 24.95, 25.2500000000001, 25.35, 25.45, 25.55, 25.7500000000001,
25.85, 25.85, 25.85, 25.85, 25.85, 25.65, 25.55, 25.45, 25.35,
25.15, 25.05, 25.2500000000001, 25.15, 24.65, 24.65, 24.65, 24.85,
25.05, 25.35, 25.35, 25.35, 25.45, 25.65, 25.7500000000001, 25.85,
25.85, 25.85, 25.95, 25.85, 25.85, 25.65, 25.45, 25.15, 24.85,
24.95, 25.05, 24.85, 24.35, 24.45, 24.55, 24.55, 24.85, 25.05,
25.35, 25.45, 25.65, 25.65, 25.7500000000001, 25.7500000000001,
25.85, 25.85, 25.85, 25.7500000000001, 25.65, 25.45, 25.2500000000001,
24.85, 24.95, 24.55, 24.55, 23.7500000000001, 23.7500000000001,
23.85, 23.95, 24.45, 24.85, 25.05, 25.45, 25.55, 25.7500000000001,
25.65, 25.55, 25.65, 25.7500000000001, 25.7500000000001, 25.7500000000001,
25.65, 25.45, 25.35, 24.95, 24.55, 24.45, 24.65, 24.05, 23.35,
23.2500000000001, 23.7500000000001, 24.05, 24.55, 24.7500000000001,
24.95, 25.2500000000001, 25.45, 25.55, 25.55, 25.7500000000001,
25.7500000000001, 25.65, 25.65, 25.55, 25.35, 25.2500000000001,
24.7500000000001, 24.35, 24.45, 24.55, 24.15, 23.55, 22.95, 23.2500000000001,
23.45, 24.05, 24.2500000000001, 24.85, 25.2500000000001, 25.45,
25.65, 25.65, 25.65, 25.7500000000001, 25.65, 25.45, 25.55, 25.2500000000001,
24.85, 24.55, 24.2500000000001, 24.15, 23.85, 23.05, 22.65, 22.7500000000001,
23.35, 23.85, 24.55, 24.7500000000001, 24.55, 25.05, 25.2500000000001,
25.35, 25.45, 25.65, 25.55, 25.55, 25.45, 25.35, 25.05, 24.85,
24.65, 24.35, 23.95, 23.7500000000001, 23.15, 22.55, 22.55, 23.05,
23.7500000000001, 24.35, 24.35, 24.2500000000001, 24.65, 25.15,
25.15, 25.45, 25.55, 25.55, 25.35, 25.2500000000001, 25.05, 25.15,
24.95, 24.55, 24.35, 23.85, 23.2500000000001, 23.05, 22.65, 22.85,
23.15, 23.65, 24.05, 24.55, 24.85, 25.15, 24.85, 24.85, 25.15,
25.45, 25.65, 25.65, 25.35, 25.2500000000001, 25.15, 24.85, 24.45,
24.15, 24.2500000000001, 23.65, 23.65, 23.2500000000001, 23.7500000000001,
24.05, 24.2500000000001, 24.35, 24.35, 24.65, 24.85, 25.15, 25.2500000000001,
25.45, 25.45, 25.35, 25.15, 25.2500000000001, 24.95, 24.7500000000001,
24.65, 24.85, 24.65, 24.2500000000001, 24.15, 24.15, 23.45, 23.85,
23.7500000000001, 23.95, 24.2500000000001, 24.35, 24.65, 24.85,
25.2500000000001, 25.2500000000001, 25.2500000000001, 25.15,
25.45, 24.85, 24.95, 25.05, 24.95, 24.35, 24.15, 24.15, 24.05,
24.2500000000001, 24.35, 24.2500000000001, 24.05, 23.85, 24.05,
23.95, 24.15, 24.65, 24.85, 25.05, 25.15, 25.05, 25.2500000000001,
25.15, 24.7500000000001, 24.65, 24.85, 24.7500000000001, 24.35,
24.05, 24.2500000000001, 24.45, 24.55, 24.95, 24.65, 24.65, 24.15,
24.2500000000001, 24.15, 24.2500000000001, 24.7500000000001,
24.85, 24.95, 25.15, 24.95, 25.15, 25.05, 25.05, 24.45, 24.85,
24.35, 24.45, 24.35, 24.7500000000001, 25.15, 25.05, 24.95, 24.85,
25.15, 24.45, 24.65, 25.05, 25.15, 25.05, 25.15, 25.35, 25.45,
25.35, 25.35, 25.35, 24.95, 24.7500000000001, 24.7500000000001,
24.85, 25.05, 24.95, 25.35, 25.35, 25.35, 25.05, 25.05, 25.45,
24.95, 24.85, 24.95, 25.2500000000001, 25.55, 25.45, 25.55, 25.55,
25.7500000000001, 25.65, 25.55, 25.55, 25.35, 25.55, 25.95, 26.05,
26.05, 26.05, 26.05, 26.05, 25.95, 25.85, 25.85, 25.65, 25.7500000000001,
25.65, 25.7500000000001, 25.55, 25.7500000000001, 25.95, 25.7500000000001,
25.85, 25.95, 25.7500000000001, 26.15, 26.15, 26.15, 26.15, 26.15,
26.15, 26.15, 26.05, 26.05, 26.05, 26.15, 26.15, 26.15, 26.05,
25.65)), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 24L, 25L, 26L, 27L, 28L,
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
42L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L,
59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 70L, 71L, 72L, 73L,
74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L,
87L, 88L, 89L, 90L, 91L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L,
101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L,
112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L,
123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L,
134L, 135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L,
145L, 146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L,
156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L,
167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L,
178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L,
189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L,
200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L, 209L, 210L,
211L, 212L, 213L, 214L, 215L, 216L, 217L, 218L, 219L, 220L, 221L,
222L, 223L, 224L, 225L, 226L, 227L, 228L, 229L, 230L, 231L, 232L,
233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 241L, 242L, 243L,
244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L, 252L, 253L, 254L,
255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 263L, 264L, 265L,
266L, 267L, 268L, 269L, 270L, 271L, 272L, 273L, 274L, 275L, 276L,
277L, 278L, 279L, 280L, 281L, 282L, 283L, 284L, 285L, 286L, 287L,
288L, 289L, 290L, 291L, 292L, 293L, 294L, 295L, 296L, 297L, 298L,
299L, 300L, 301L, 302L, 303L, 304L, 305L, 306L, 307L, 308L, 309L,
310L, 311L, 312L, 313L, 314L, 315L, 316L, 317L, 318L, 319L, 320L,
321L, 322L, 323L, 324L, 325L, 326L, 327L, 328L, 329L, 330L, 331L,
332L, 333L, 334L, 335L, 336L, 337L, 338L, 339L, 340L, 341L, 342L,
343L, 344L, 345L, 346L, 347L, 348L, 349L, 350L, 351L, 352L, 353L,
354L, 355L, 356L, 357L, 358L, 359L, 360L, 361L, 362L, 363L, 364L,
365L, 366L, 367L, 368L, 369L, 370L, 371L, 372L, 373L, 374L, 375L,
376L, 377L, 378L, 379L, 380L, 381L, 382L, 383L, 384L, 385L, 386L,
387L, 388L, 389L, 390L, 391L, 392L, 393L, 394L, 395L, 396L, 397L,
398L, 399L, 400L, 401L, 402L, 403L, 404L, 405L, 406L, 407L, 408L,
409L, 410L, 411L, 412L, 413L, 414L, 415L, 416L, 417L, 418L, 419L,
420L, 421L, 422L, 423L, 424L, 425L, 426L, 427L, 428L, 429L, 430L,
431L, 432L, 433L, 434L, 435L, 436L, 437L, 438L, 439L, 440L, 441L,
442L, 443L, 444L, 445L, 446L, 447L, 448L, 449L, 450L, 451L, 452L,
453L, 454L, 455L, 456L, 457L, 458L, 459L, 460L, 461L, 462L, 463L,
464L, 465L, 466L, 467L, 468L, 469L, 470L, 471L, 472L, 473L, 474L,
475L, 476L, 477L, 478L, 479L, 480L, 481L, 482L, 483L, 492L, 493L,
494L, 495L, 496L, 497L, 498L, 499L, 500L, 501L, 502L, 503L, 504L,
505L, 506L), class = "data.frame")
occ_df <- structure(list(lon = c(-83.41, -83.51, -83.41143, -83.525, -83.46,
-83.46, -83.43, -83.49, -83.41, -83.44, -83.46944, -83.427778,
-83.516667, -83.433609, -83.411431, -83.55, -83.516805), lat = c(8.54,
8.56, 8.540221, 8.540278, 8.51, 8.52, 8.52, 8.45, 8.52, 8.52,
8.51805, 8.525, 8.566667, 8.531329, 8.540221, 8.45, 8.569294),
`Chrysochlamys glauca` = c(1, 1, 1, 1, 0, 0, 0, 1, 0, 0,
0, 1, 1, 1, 1, 1, 0), `Ocotea atirrensis` = c(0, 1, 0, 0,
1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -17L))
这是我目前拥有的
library(dplyr)
clim <- terra::rast(bioclim)
terra::crs(clim) <- "+proj=longlat +datum=WGS84 +no_defs"
clim_sg_df <- raster::raster(clim) %>%
as("SpatialGridDataFrame")
occ <- occ_df %>%
# rounding lon/lat to fix inconstant coordinate intervals when using gridded()
mutate(across(
matches("lon|lat"),
~ round(.x, 2)
))
sp::coordinates(occ) <- ~ lon + lat
sp::proj4string(occ) <- "+proj=longlat +datum=WGS84 +no_defs"
sp::gridded(occ) <- TRUE
occ_sg_df <- as(occ_sp, "SpatialGridDataFrame")
# terra::plot(clim_sg_df)
# terra::plot(occ_sg_df, add = TRUE)
我有两个主要问题。首先,尽管有相同的投影,但我无法将两个网格绘制在彼此之上,所以我怀疑我的代码有错误。第二,两个对象之间的网格大小不同,我真的不知道如何将它们均质化。
我需要让 clim_sg_df
和 occ_sg_df
相互匹配,以便满足以下条件 returns TRUE
:
identical(as(occ_sg_df, "SpatialGrid"), as(clim_sg_df, "SpatialGrid"))
请注意,我需要保留栅格中的所有像元并使用 sp
包,因为这是我将用于分析的函数所需要的。
#here you have first raster created
clim <- terra::rast(bioclim)
terra::crs(clim) <- "+proj=longlat +datum=WGS84 +no_defs"
#lets create another raster with exactly the same size
#lets clear it
#
occ <- clim
occ[] <- NA
occ_df <- occ_df %>%
# rounding lon/lat to fix inconstant coordinate intervals when using gridded()
mutate(across(
matches("lon|lat"),
~ round(.x, 2)
))
sp::coordinates(occ_df) <- ~ lon + lat
sp::proj4string(occ_df) <- "+proj=longlat +datum=WGS84 +no_defs"
# lets create a vector object which later will be used for rasterization
occ_vec <- vect(occ_df)
# now the important step - rasterizing vector data over raster grid
#
occ <- rasterize(occ_vec, occ)
terra::plot(clim)
terra::plot(occ, add = TRUE )
由 reprex package (v2.0.1)
创建于 2022-01-24PS。为了更好的可见性,您可以更改颜色,例如
terra::plot(occ, add = TRUE, col = "red" )
您应该使用 rasterize
而不是 gridded
。例如这个光栅和这些点:
library(terra)
r <- rast(system.file("ex/elev.tif", package="terra"))
set.seed(123)
pts <- spatSample(r, 1000, xy=TRUE, na.rm=TRUE, replace=TRUE)
xy <- as.matrix(pts[, c("x", "y")])
你可以做到
spp <- rasterize(xy, r)
或者按单元格统计出现次数
spp <- rasterize(xy, r, 1, fun=sum)
除了矩阵,您还可以使用 SpatVector
个点。
在一张地图上绘制两个重叠的栅格绝非易事,但 Grzegorz Sapijaszko 展示了如何做到这一点。您还可以使用透明度。但通常只在栅格顶部添加点更有意义:
plot(r)
points(xy, cex=.5)
或者有一个点的单元格的中心
pspp <- as.points(spp)
plot(r)
points(pspp, cex=.25)
或者添加单元格的轮廓(如果出现的单元格数量不是太多)
polspp <- as.polygons(spp)
plot(r)
lines(polspp)
使用 R 附带的示例数据更方便,但您可以使用您的示例数据
library(terra)
r <- rast(bioclim)
pts <- vect(data.frame(occ_df), geom=c("lon", "lat"))
x <- rasterize(pts, r)
plot(r)
lines(as.polygons(x))
points(pts, col="red")
在您的示例数据中,您有多个物种。
pts
# class : SpatVector
# geometry : points
# dimensions : 17, 2 (geometries, attributes)
# extent : -83.55, -83.41, 8.45, 8.569294 (xmin, xmax, ymin, ymax)
# coord. ref. :
# names : Chrysochlamys.glauca Ocotea.atirrensis
# type : <num> <num>
# values : 1 0
# 1 1
# 1 0
您可以像这样将 pts
子集化为单个物种
glauca <- pts[pts$Chrysochlamys.glauca == 1, ]
如果您愿意,也可以使用 raster::rasterize
(带有 RasterLayer
和矩阵或 SpatialPointsDataFrame
)。或者像这样将对象从 terra
强制返回到 raster
/sp
:
library(raster)
xr <- raster(x)
pp <- as(pts, "Spatial")
plot(xr)
points(pp)