以此為
uj5u.com熱心網友回復:
該段只是具有您給它的坐標。一條垂直線是這樣的:
kncoast <- data.frame(orig_lat=12.7571,
orig_lon=74.87461,
dest_lat=15,
dest_lon=74.87461)

如果你想讓這條線橫跨卡納塔克邦的海岸,那么這樣的事情會更好:
kncoast <- data.frame(orig_lat=12.7571,
orig_lon=74.87461,
dest_lat=14.75,
dest_lon=74.15)

uj5u.com熱心網友回復:
如果需要提取邊框,可以執行以下操作:
- 使用坐標在您感興趣的區域周圍創建一個邊界框。
- 將卡納塔克邦轉換為單個多邊形,將其轉換為線條以獲得邊界
- 使用邊界框裁剪邊框。然后,您將邊界的部分作為您感興趣的線內的一條線。
我在這里利用@AllanCameron 的答案,請參閱reprex:
library(ggplot2)
library(dplyr)
library(sf)
library(raster)
# get the data for the map (map of Karnataka state in India)
kn_sf <-
getData("GADM", country = "IND", level = 2) %>%
st_as_sf() %>%
filter(NAME_1 == "Karnataka")
# Get points and to bounding box
kncoast <- data.frame(lat=c(12.7571, 14.75),
lon=c(74.87461,74.15))
kncoast_bbox <- kncoast %>% st_as_sf(coords = c("lon", "lat"), crs=4326) %>%
st_bbox() %>% st_as_sfc()
kncoast_bbox
#> Geometry set for 1 feature
#> Geometry type: POLYGON
#> Dimension: XY
#> Bounding box: xmin: 74.15 ymin: 12.7571 xmax: 74.87461 ymax: 14.75
#> Geodetic CRS: WGS 84
#> POLYGON ((74.15 12.7571, 74.87461 12.7571, 74.8...
ggplot(kn_sf)
geom_sf()
geom_sf(data=kncoast_bbox, fill=NA, color="red")

# Use kn_sf to lines and cut
kn_sf_coast <- st_union(kn_sf) %>%
st_cast("MULTILINESTRING") %>%
st_crop(kncoast_bbox)
kn_sf_coast
#> Geometry set for 1 feature
#> Geometry type: MULTILINESTRING
#> Dimension: XY
#> Bounding box: xmin: 74.1507 ymin: 12.75711 xmax: 74.86708 ymax: 14.75004
#> CRS: proj=longlat datum=WGS84 no_defs
#> MULTILINESTRING ((74.72875 13.28264, 74.72847 1...
ggplot(kn_sf)
geom_sf()
geom_sf(data = kn_sf_coast, color="red")

由reprex 包于 2022-06-13 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/491409.html
