1

我是使用 R 进行空间分析的新手。我正在尝试主要使用 R 中的 adehabitatHR 包计算每日家庭范围(MCP 100、后来的 95 和 50%)。我使用了我同事提供的脚本,它对她有用每时每刻。现在,当我运行它时,它可以工作,但是我收到的 e-xx 值太小了。我真的不知道哪里出了问题,我认为它与投影有关,但我太缺乏经验,不知道哪个应该更好。

你可以看到下面的代码。也许有人知道如何解决这个问题?

library (adehabitatHR)
library (sp)
library (scales)  # helps make Polygons partly transparent using the alpha argument below 
library(dplyr)

# Read data frame into R 
tab1<-read.csv(file="animals.csv",sep=",",header=TRUE)

# Remove two rows with NA´s 
tab1 <- tab1 [!is.na(tab1$x_) & !is.na(tab1$y_),]

# Only include three columns (AnimalID + Exp, x and y coordinates) for making MCP´s 
# Creating new ID to group days and AnimalID
tab2 <- tab1 [, c("id", "x_", "y_", "day", "month", "year")] # week, month, day + month
tab2$Time <- paste(tab2$day, tab2$month, sep= " ") #  day + month
tab2$Time2 <- paste(tab2$Time, tab2$year)
tab2$Mix <- paste(tab2$AnimalID, tab2$Time2, sep= " ") # id + time 
tab3 <- tab2 [, c("Mix", "x_", "y_")]
tibble(tab3)

# Check in tab2 which Animal has less than 5 GPS location
tab4 <- tab3 %>%
  group_by(Mix) %>%
  summarise(n = n())

# Filter data with less than 5 
tab5<-filter(tab4, n > 5)
tab6<-filter(tab4, n < 5)
  
# Remove rows from data set which have less than 5 GPS location
tab7 <- tab3 %>% 
  filter(!grepl(" 31 May 2019", Mix))
tab8 <- tab7 %>% 
  filter(!grepl(" 29 Jun 2019", Mix))

# Create a SpatialPointsDataFrame by defining the coordinates
coordinates(tab8) <- c("x_", "y_")
str(tab8)

# Set the coordinate reference system, (CRS) 
# The sample data are UTM points in WGS84 from zone 33N 
proj4string(tab8) <- CRS( "+proj=utm +zone=33N +datum=WGS84 +units=m +no_defs" )

animals.mcp <- mcp(tab8[, "Mix"], percent = 100, unin = "m", unout = "m2") 
as.data.frame(animals.mcp)

输出数据如下所示:

                      id         area
 1 Dec 2019    1 Dec 2019 5.180087e-03
 1 Feb 2020    1 Feb 2020 7.171711e-04
 1 Jan 2020    1 Jan 2020 1.692209e-03
 1 Jul 2019    1 Jul 2019 3.384402e-07
 1 Jun 2019    1 Jun 2019 1.829374e-01
 1 Nov 2019    1 Nov 2019 7.794313e-04
...

提前致谢!

4

1 回答 1

1

所以我能够通过添加来解决它

coordinates(tab7) <- c("x_", "y_") 
proj4string(tab7) <- CRS("+init=epsg:4326") 
tab8 <- spTransform(tab7, CRS("+proj=utm +zone=33N +datum=WGS84 +units=m +no_defs"))

所以首先告诉 R 使用什么坐标系,然后将其投影到必要的区域。

希望这可以帮助其他有同样问题的人!

于 2021-09-18T14:11:56.370 回答