【发布时间】:2020-08-29 16:28:49
【问题描述】:
我有一个纬度/经度点数据集,旨在转换为 R 中的简单特征 (sf)。 我的目标是使用从 urbnmapr 库中检索到的多边形在美国地图上绘制这些位置。
使用我们的地理参考进行绘图,如代码所示,会显示所有点。
当使用 geom_sf() 绘制点时,它们最终位于南达科他州。尽管我认为正确使用了 st_as_sf() 函数,但似乎纬度/经度点没有被转换为正确的坐标参考系。
需要对此代码进行哪些更正才能在美国地图上正确显示风力涡轮机位置的分布?
# Map the locations of US Wind Turbines
library(urbnmapr)
library(ggplot2)
library(readr)
library(dplyr)
library(sf)
# This file is available from https://eerscmap.usgs.gov/uswtdb/assets/data/uswtdbCSV.zip
turbine <- read_csv("C:\\mydir\\uswtdb_v3_1_20200717.csv")
# Convert lat/long to a sf
turbine_sf <- turbine %>%
st_as_sf(coords = c("xlong", "ylat"), crs=2163)
# obtain state geometries
states_sf <- get_urbn_map(map = "states", sf = TRUE)
# Remove AK, HI from state and PR and GU from turbines as well
states_sf <- states_sf[!(states_sf$state_abbv %in% c("HI","AK")),]
turbine <- turbine [!(turbine$t_state %in% c('HI','AK','PR','GU')),]
# simple plot shows all locations
ggplot(turbine, aes(x=xlong, y=ylat)) + geom_point()
#plot locations over map
ggplot() +
geom_sf(data = turbine_sf) +
geom_sf(data = states_sf, fill = NA, color = "black", size = 0.15, alpha = 0) +
coord_sf(datum = st_crs(2163)) +
labs(fill = "",
title = "",
caption='') +
theme_bw()
【问题讨论】: