确认Dataframe的空间投影

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

我正在为美国制作项目映射数据。数据最初来自带有 Lambert Confomal Conic 投影的 ncdf 文件。转换为栅格时,纬度和经度变量存在错误,因此我分别处理了每个变量并将它们放入数据框中。

在处理并绘制数据后,它在美国的平面(“+proj=longlat +datum=NAD83 +no_defs”)投影 shapefile 上显示为曲线。我试图将点转换为坐标并将点重新投影到 shapefile 投影无济于事。

(https://i.stack.imgur.com/gQPGo.png)

数据框:https://www.dropbox.com/s/ntd8hv6qnw1cy2i/Data1deg.xlsx?dl=0 形状文件:https://www.dropbox.com/s/vwuduwfslc2zjjg/cb_2018_us_state_20m.shp?dl=0

library(sf)
library(sp)
library(rgdal)
library(readxl)

#Processed data
datafile <- readxl::read_xlsx("Data1deg.xlsx")

#Shape File
Shape <- readOGR("cb_2018_us_state_20m.shp")
Shapecrs <- Shape@proj4string@projargs
statenums <- c("0", "1", "2", "3", "4", "5", "6", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "49", "50", "51")
Shape1 <- Shape[statenums, ]

#conrvrting dataframe long and lat to coordinate points
coordinates <-  st_as_sf(datafile, coords = c("xv", "yv"))
st_is_longlat(coordinates)

#original data projection
coordinates_geo <- st_set_crs(coordinates, "+proj=lcc +lat_0=40.0000076293945 +lon_0=-97 +lat_1=30 +lat_2=45 +x_0=0 +y_0=0 +R=6370000 +units=m +no_defs")
plot(coordinates_geo)

#Attempts to reproject data
reprojcoord <- st_transform(coordinates_geo, Shapecrs)
plot(reprojcoord)
reprojcoord1 <- st_transform_proj(coordinates_geo, Shapecrs)
plot(reprojcoord1)

有没有办法像上面尝试的那样简单地从纬度/经度值确认/更改数据框中的数据投影?

r spatial map-projections reprojection-error
1个回答
0
投票

你在做什么有点神秘;或想做。但这里有一些指示

读取shapefile并删除一些状态:

library(sf)
v <- st_read("cb_2018_us_state_20m.shp")
i <- v$NAME %in% c("Alaska", "Puerto Rico", "Hawaii", "District of Columbia")
v <- v[!i, ]

阅读电子表格并创建一个 sf 对象。

d <- readxl::read_xlsx("Data1deg.xlsx")
crds <- st_as_sf(d, coords = c("xv", "yv"))
st_crs(crds) <- "+proj=longlat"

坐标明确为经/纬度。你不能假装它们是别的东西。预计数据是弯曲的,因为这些数据来自网格化的 LCC 数据。他们描述您的工作流程的方式,似乎您在开始时使用您的 ncdf 文件犯了一个错误。

© www.soinside.com 2019 - 2024. All rights reserved.