gpt4 book ai didi

r - 通过连接点(lon-lat)在 R 中绘制的谷歌地图上查找位置区域

转载 作者:行者123 更新时间:2023-12-01 17:22:18 25 4
gpt4 key购买 nike

我正在尝试使用 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

请帮助我找到可以在我的代码中使用的计算面积的方法,这样当我在 map 上绘制纬度和经度点时,我就能得到这些点覆盖的确切区域。

我们将不胜感激您的任何帮助!

最佳答案

对于经/纬度坐标矩阵

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)

关于r - 通过连接点(lon-lat)在 R 中绘制的谷歌地图上查找位置区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48685827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com