【问题标题】:Overlay values corresponding lat and long in a shape file in R在R中的形状文件中覆盖对应的纬度和经度值
【发布时间】:2022-10-14 04:02:13
【问题描述】:

我想在R中的shapefile上覆盖excel中的lat-long对应的wmo点。我遇到了其他人的问题,但我仍然无法做到。我已经尝试过这段代码,但没有工作。请帮忙。

shapestate <- read_sf(file.path(dir_ls$input_dir, 'shapefile'), 'State_sim')
plot(st_geometry(shapestate), col="darkblue", main="Tahoe HUC8", axes=TRUE)

wmo<-read.xlsx(file.path(dir_ls$input_dir, 'cyclone', 'checking wind speed.xlsx'))

coordinates(wmo) <- ~ LAT + LON
IND<-spTransform(shapestate, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))


points(wmo$LAT ~ wmo$LON, col = "red", cex = 1, pch = 19)

在这个给定的链接中共享了 excel 中对应的 lat-long 的 shapefile 和值。 shapefile and wmo values in excel

【问题讨论】:

    标签: r geospatial


    【解决方案1】:

    让我来帮助你。由于仅shp 文件不足以正确读取它,我将使用geodata 包来读取边界。在你的情况下:

    sf::st_read("path_to_shapefile.shp") |>
      sf::st_geometry() |>
      plot()
    

    应该足够了。

    使用sf 包及其功能:

    geodata::gadm("India", path = tempdir()) |>
      sf::st_as_sf() |>
      sf::st_geometry() |>
      plot()
    
    readxl::read_excel("/home/sapi/Downloads/checking wind speed.xlsx") |>
      sf::st_as_sf(coords = c("LON", "LAT"), crs = 4326) |>
      sf::st_geometry() |>
      plot(pch = 16, col = "red", add = TRUE)
    

    或使用terra 包:

    geodata::gadm("India", path = tempdir()) |>
      terra::plot()
    
    readxl::read_excel("/home/sapi/Downloads/checking wind speed.xlsx") |>
      terra::vect(geom = c("LON", "LAT"), crs = "EPSG:4326") |>
      terra::plot(pch = 16, col = "red", add = TRUE)
    

    请查看 sf::st_read() 和/或 terra::vect() 函数来读取您的 shapefile。

    创建于 2022 年 10 月 13 日,reprex v2.0.2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-13
      相关资源
      最近更新 更多