如何在R中提取这个sf对象的沿海部分的坐标?

问题描述 投票:0回答:1

使用 rnaturalearth 包,我已经能够像这样制作大西洋地图。

library(rnaturalearth)
library(rnaturalearthdata)

#Load Canada from Natural Earth
canada_dl = ne_countries(scale = 110, country = "Canada")
#Plot Canada, but only the Atlantic Canada bits 
canada_atlantic_only = st_crop(canada_dl, xmin = -70, xmax = -50 , ymin = 41, ymax = 61)

这就是地图本身的样子,我对此很满意。

enter image description here

我想做的是沿着这张地图的海岸线开始,然后沿着这条线提取坐标。我将使用这些坐标绘制其他线到离岸更近和更远的点,但基本上我不知道如何要求 R 给我代表加拿大大西洋海岸线的线的坐标。有没有办法使用 rnaturalearth 来做到这一点?

r gis
1个回答
0
投票

您可以使用

sf::st_cast()
来转换几何类型。请注意,警告告诉您,如果特征被分割,例如,原始几何形状的值将被转移到每个单独的零件。如果您有面积值等,则需要在
st_cast()
之后再次重新计算它们。但是,鉴于您正在创建点,您可以忽略这些警告。

library(rnaturalearth)
library(rnaturalearthdata)
library(sf)

canada_dl = ne_countries(scale = 110, country = "Canada") |>
  st_crop(xmin = -70, xmax = -50 , ymin = 41, ymax = 61) |>
  st_cast("POINT")

# Warning messages:
# 1: attribute variables are assumed to be spatially constant throughout all geometries 
# 2: In st_cast.sf(st_crop(ne_countries(scale = 110, country = "Canada"),  :
#   repeating attributes for all sub-geometries for which they may not be constant

canada_dl[,"geometry"]
# Simple feature collection with 114 features and 0 fields
# Geometry type: POINT
# Dimension:     XY
# Bounding box:  xmin: -70 ymin: 43.54523 xmax: -52.6481 ymax: 61.02989
# Geodetic CRS:  WGS 84
# First 10 features:
#   geometry
# 1        POINT (-70 46.69299)
# 2  POINT (-69.99997 46.69307)
# 3  POINT (-69.23722 47.44778)
# 4      POINT (-68.905 47.185)
# 5  POINT (-68.23444 47.35486)
# 6  POINT (-67.79046 47.06636)
# 7  POINT (-67.79134 45.70281)
# 8  POINT (-67.13741 45.13753)
# 9  POINT (-66.02605 45.25931)
# 10 POINT (-64.42549 45.29204)
© www.soinside.com 2019 - 2024. All rights reserved.