我正在尝试使用ggmap和ggplot2库使用点和线计算标记位置的面积。我找不到任何有关如何通过连接R中的经度和纬度点来计算面积的示例。
我要查找的区域的点和线的代码如下:
library(ggmap)
library(ggplot2)
coordinates <- read.csv("U://30-Power & Water//25 Renewables//R plots//plant location plot//lat_lon.csv", header=T)
coordinates <- data.frame(coordinates)
map <- get_map(location = c(mean(coordinates[1:13,3]), mean(coordinates[1:13,2])), zoom = 13, maptype = "satellite", source = "google")
Sweihan <- ggmap(map)+
geom_point(data = coordinates, aes(x = coordinates[,3], y = coordinates[,2]))+
geom_path(data = coordinates, aes(x = coordinates[,3], y = coordinates[,2]))
+ geom_polygon(data = coordinates, aes(x = coordinates[1:13,3], y = coordinates[1:13,2]))
Sweihan
我的数据如下所示:
Point Latitute..N. Longitude..
1 P1 24.53450 55.41547
2 P2 24.52929 55.41913
3 P3 24.52929 55.43241
4 P4 24.54342 55.46566
5 P5 24.55113 55.46241
6 P6 24.55545 55.47364
7 P7 24.56041 55.47109
8 P8 24.55841 55.46529
9 P9 24.55867 55.46521
10 P10 24.54863 55.43838
11 P11 24.54712 55.43917
12 P12 24.54085 55.42715
13 P13 24.54043 55.42712
14 P1 24.53450 55.41547
请帮助我找到可以在代码中使用的面积计算方法,以便在地图上绘制纬度和经度点时,可以得到这些点所覆盖的确切面积。
任何类型的帮助将不胜感激!
最佳答案
对于lon / lat坐标矩阵
p <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60), c(-180,-20))
library(geosphere)
areaPolygon(p)
# with your data "d"
# areaPolygon(as.matrix(d[,3:2]))
或用于SpatialPolygonsDataFrame
library(raster)
p <- shapefile(system.file("external/lux.shp", package="raster"))
a <- area(p)