如何在地图上计算多边形和圆的面积

时间:2015-09-28 23:32:20

标签: r geospatial

我想计算地图上具有给定半径的圆与部分与圆重叠的多边形之间的重叠区域。 这是地图:

map(database="worldHires", xlim = c(-97.1, -80), ylim = c(25, 32.5), col = "grey", fill=TRUE, lwd = 2, bg = "lightblue2", mar=rep(0, 4))
#add Grand Isle
points(-90.0122, 29.2278, pch = 21, col = "blue", bg = "blue", cex=2)
text(-91.5, 28.9, "Grand Isle", cex = 1.2)

这是半径为100km的圆

plotCircle <- function(LonDec, LatDec, Km) {
  ER <- 6371 #Mean Earth radius in kilometers. Change this to 3959 and you will have your function working in miles.
AngDeg <- seq(1:360) #angles in degrees 
Lat1Rad <- LatDec*(pi/180)#Latitude of the center of the circle in radians
Lon1Rad <- LonDec*(pi/180)#Longitude of the center of the circle in radians
AngRad <- AngDeg*(pi/180)#angles in radians
Lat2Rad <-asin(sin(Lat1Rad)*cos(Km/ER)+cos(Lat1Rad)*sin(Km/ER)*cos(AngRad)) #Latitude of each point of the circle rearding to angle in radians
Lon2Rad <- Lon1Rad+atan2(sin(AngRad)*sin(Km/ER)*cos(Lat1Rad),cos(Km/ER)-   sin(Lat1Rad)*sin(Lat2Rad))#Longitude of each point of the circle rearding to angle in radians
Lat2Deg <- Lat2Rad*(180/pi)#Latitude of each point of the circle rearding to angle in degrees (conversion of radians to degrees deg = rad*(180/pi) )
Lon2Deg <- Lon2Rad*(180/pi)#Longitude of each point of the circle rearding to angle in degrees (conversion of radians to degrees deg = rad*(180/pi) )
polygon(Lon2Deg,Lat2Deg,lty=2)
}

plotCircle(-90.0122,29.2278,100)#Plot a dashed circle of 100 km around Grand Isle

这可以将圆圈绘制到地图上。 多边形在这里

poly <- readOGR("path/filename")
poly1<- spTransform(poly, CRS("+proj=longlat +datum=WGS84"))
plot(poly1, add=TRUE, col="orange")

这会将多边形添加到地图上。然后我尝试使用

res <-gIntersection(x, poly1)

其中x = plotCircle或将地图与绘制在其上的圆组合在一起的函数。我不断收到以下错误消息:

  

相同的错误(spgeom1 @ proj4string,spgeom2 @ proj4string):     试图从没有插槽的基本类(“函数”)的对象获取插槽“proj4string”

我假设一个或另一个不是空间物体,也许它是圆形,因为我只是在地图上绘制它。所以我尝试使用spTransform将圆圈转换为SP对象,但这不起作用。关于如何实现这一目标的任何想法都将不胜感激。

我使用下面的问题作为一个起点,但它没有解决我的问题。

How to calculate the area of polygon overlap in R?

0 个答案:

没有答案