我在计算动物家庭范围的区域时遇到了很多麻烦。我想过,一旦我制作了一个家庭范围(如果我已经正确地完成了),计算面积会很容易,但没有
我已经粘贴了一些我一直在尝试的代码。我想知道有没有人有任何见解?
# Load package
library(adehabitat)
#Load file Frodo
dd <- read.csv(file.choose(), header = T)
# Plot the home range
xy <- dd[,c("X","Y")]
id <- dd[,"name"]
hr<- mcp(xy,id,percent=95)
plot(hr)
points(xy[xy$id=="frodo",])
#Great. Home range produced. Now calculate area
area <- mcp.area(xy, id,percent = 95),
# Result 2.287789e-09 Ha. Way to small. Maybe it doesnt like Lat / Long.
# Will try and convert coordinates into M or Km
# Load map project
library(mapproj)
x<-mapproject(t$X,t$Y,projection="mercator")
# Its converted it to something but its not M's or Km's.
# I'll try and run it anyway
xy <- x[,c("X","Y")]
# incorrect number of dimensions
# Ill try Project 4
library(proj4)
xy <- dd[,c("X","Y")]
tr <- ptransform(xy/180*pi, '+proj=latlong +ellps=sphere',
'+proj=merc +ellps=sphere')
View(tr)
# There seems to be a Z column filled with 0's.
# It that going to affect anything?
# Let's look at the data
plot(tr)
# Looks good, Lets try and create a home range
xy <- tr[,c("x","y")]
# 'incorrect number of dimensions'
不知道问题是什么。不知道我是在正确的轨道上还是做错了什么
答案 0 :(得分:2)
为了计算面积,您需要在投影坐标系中获得点数(长/纬度区域只是度数单位)。您使用的投影类型将对结果区域产生很大影响。例如,墨卡托投影区域会偏离赤道区域 - 您可能希望查看适合您所在位置的最佳等面积投影。我将回答您问题的编程部分,一旦找到正确的投影,您就可以替换它们。
require(sp)
require(rgdal)
orig.points <- dd[,c("X","Y")]
# geographic coordinate system of your points
c1 <- CRS("+proj=latlong +ellps=sphere")
# define as SpatialPoints
p1 <- SpatialPoints(orig.points, proj4string=c1)
# define projected coordinate system of your choice, I am using the one you
# defined above, but see:
# http://www.remotesensing.org/geotiff/proj_list/mercator_1sp.html
# to make sure your definition of the mercator projection is appropriate
c2 <- CRS("+proj=merc ellps=sphere")
p2 <- spTransform(p1, c2) # project points
# convert to Polygon (this automatically computes the area as an attribute)
poly <- Polygon(p2)
poly@area #will print out the area