转换为 R 中的 sf 数据帧时,重新投影不会更改 'geometry' 列中的值

Reprojection is not changing the values in the 'geometry' column when converting to a sf dataframe in R

我试图在 R 中重新投影的 .csv 文件中有 POINT_X、POINT_Y 和一个 z 点列。最初,它被投影在 EPSG:26777 参考系统,但我试图将其投影回 WGS 84。但是,当我将 .csv 文件导入 R 并尝试转换时,它不会更改我的“几何”列中的点值。如何将它们更改为经纬度坐标?

这是原始投影中导出的数据:

data <- data.frame(point_x = c(2387371.258,
                               2387411.214,
                               2387451.258,
                               2387529.427,
                               2387411.258,
                               2387191.258,
                               2387491.258,
                               2387331.258,
                               2387116.239,
                               2387291.258,
                               2387371.258,
                               2387431.258,
                               2387331.258,
                               2387271.258,
                               2387511.258,
                               2387331.258,
                               2387211.258,
                               2387351.258,
                               2387112.752,
                               2387311.22,
                               2387411.258,
                               2387191.258,
                               2387271.258,
                               2387491.258,
                               2387131.258,
                               2387231.258,
                               2387291.258,
                               2387371.052,
                               2387491.258,
                               2387171.258,
                               2387131.258,
                               2387371.258,
                               2387113.437,
                               2387211.258,
                               2387531.258,
                               2387331.258,
                               2387371.258,
                               2387311.258,
                               2387291.258,
                               2387511.258,
                               2387211.258,
                               2387491.258,
                               2387391.258,
                               2387530.847,
                               2387542.074,
                               2387491.258,
                               2387511.258,
                               2387271.258,
                               2387161.36,
                               2387112.772,
                               2387451.258,
                               2387431.258,
                               2387511.258,
                               2387127.551,
                               2387531.258,
                               2387251.258,
                               2387151.258,
                               2387231.258,
                               2387231.258,
                               2387191.258,
                               2387511.258,
                               2387171.258,
                               2387231.258,
                               2387431.258,
                               2387531.258,
                               2387231.258,
                               2387211.258,
                               2387112.281,
                               2387191.258,
                               2387391.258,
                               2387182.737,
                               2387351.258,
                               2387271.258,
                               2387371.258,
                               2387451.197,
                               2387171.258,
                               2387451.258,
                               2387431.258,
                               2387114.101,
                               2387491.219,
                               2387151.258,
                               2387451.258,
                               2387171.258,
                               2387528.481,
                               2387251.258,
                               2387251.258,
                               2387451.258,
                               2387112.193,
                               2387391.258,
                               2387151.258,
                               2387211.258,
                               2387171.258,
                               2387351.258,
                               2387131.258,
                               2387511.258,
                               2387411.258,
                               2387351.258,
                               2387411.258,
                               2387231.258,
                               2387211.224,
                               2387311.258,
                               2387191.258,
                               2387351.258,
                               2387351.258,
                               2387351.258,
                               2387171.258,
                               2387491.258,
                               2387371.258,
                               2387171.225,
                               2387251.258,
                               2387118.495,
                               2387231.258,
                               2387471.258,
                               2387171.258,
                               2387131.258,
                               2387191.258,
                               2387371.258,
                               2387151.258,
                               2387131.258,
                               2387411.258,
                               2387112.44,
                               2387191.258,
                               2387524.317,
                               2387391.258,
                               2387371.258,
                               2387251.258,
                               2387451.258,
                               2387371.258,
                               2387191.258,
                               2387231.258,
                               2387211.258,
                               2387331.258,
                               2387391.258,
                               2387311.258,
                               2387191.258,
                               2387431.258,
                               2387271.258,
                               2387271.258,
                               2387323.356,
                               2387231.258,
                               2387351.258,
                               2387191.258,
                               2387211.258,
                               2387231.258,
                               2387431.258,
                               2387191.258,
                               2387351.258,
                               2387491.258,
                               2387431.258),
                   point_y = c(289191.3991,
                               289054.1412,
                               289391.3991,
                               289351.3027,
                               289091.399,
                               289071.399,
                               289251.399,
                               289291.3993,
                               289271.587,
                               289311.3992,
                               289311.3992,
                               289151.3992,
                               289151.3992,
                               289131.3989,
                               289411.399,
                               289391.3991,
                               289071.399,
                               289331.3992,
                               289611.4751,
                               289053.1858,
                               289211.3991,
                               289511.3991,
                               289511.3991,
                               289171.3992,
                               289131.3989,
                               289371.3991,
                               289131.3989,
                               289529.3496,
                               289451.3993,
                               289271.399,
                               289211.3991,
                               289371.3991,
                               289391.4699,
                               289231.399,
                               289251.399,
                               289411.399,
                               289331.3992,
                               289411.399,
                               289531.3991,
                               289371.3991,
                               289331.3992,
                               289431.399,
                               289251.399,
                               289291.3169,
                               289055.4637,
                               289131.3989,
                               289071.399,
                               289231.399,
                               289601.478,
                               289431.4643,
                               289291.3993,
                               289271.399,
                               289131.3989,
                               289626.1925,
                               289131.3989,
                               289291.3993,
                               289231.399,
                               289251.399,
                               289351.3991,
                               289351.3991,
                               289151.3992,
                               289431.399,
                               289111.399,
                               289091.399,
                               289111.399,
                               289491.3992,
                               289311.3992,
                               289571.3209,
                               289191.3991,
                               289071.399,
                               289582.6287,
                               289411.399,
                               289331.3992,
                               289471.3992,
                               289054.5359,
                               289191.3991,
                               289151.3992,
                               289231.399,
                               289351.4766,
                               289511.3581,
                               289071.399,
                               289171.3992,
                               289331.3992,
                               289391.2898,
                               289131.3989,
                               289411.399,
                               289311.3992,
                               289628.765,
                               289471.3992,
                               289411.399,
                               289431.399,
                               289251.399,
                               289471.3992,
                               289471.3992,
                               289451.3993,
                               289391.3991,
                               289151.3992,
                               289111.399,
                               289271.399,
                               289052.2304,
                               289111.399,
                               289231.399,
                               289311.3992,
                               289191.3991,
                               289371.3991,
                               289571.399,
                               289211.3991,
                               289511.3991,
                               289051.8482,
                               289171.3992,
                               289191.7413,
                               289451.3993,
                               289251.399,
                               289351.3991,
                               289231.399,
                               289331.3992,
                               289071.399,
                               289511.3991,
                               289591.399,
                               289451.3993,
                               289451.4619,
                               289491.3992,
                               289487.6817,
                               289091.399,
                               289111.399,
                               289431.399,
                               289231.399,
                               289211.3991,
                               289091.399,
                               289291.3993,
                               289171.3992,
                               289371.3991,
                               289411.399,
                               289391.3991,
                               289211.3991,
                               289491.3992,
                               289251.399,
                               289111.399,
                               289541.5201,
                               289311.3992,
                               289211.3991,
                               289291.3993,
                               289091.399,
                               289231.399,
                               289431.399,
                               289111.399,
                               289251.399,
                               289491.3992,
                               289071.399),
                   point_z = c(0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0,
                               0))

这是我正在尝试做的事情:

#Open packages
library(pacman)
p_load(raster, 
       sf, 
       dplyr, 
       ggplot2, 
       scales, 
       magrittr, 
       gstat, 
       gridExtra, 
       raster,
       sp,
       automap,
       mapview,
       leaflet,
       rgdal)

#Read in data, provided above
data <- read.csv('data.csv')

#Change to a spatial object and reproject to WGS84
data <- st_as_sf(data, coords = c('point_x', 'point_y'), crs = crs('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'))

crs(data)命令的结果是:

Coordinate Reference System:
Deprecated Proj.4 representation: +proj=longlat +datum=WGS84 +no_defs 
WKT2 2019 representation:
GEOGCRS["unknown",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]],
        ID["EPSG",6326]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433],
        ID["EPSG",8901]],
    CS[ellipsoidal,2],
        AXIS["longitude",east,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433,
                ID["EPSG",9122]]],
        AXIS["latitude",north,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433,
                ID["EPSG",9122]]]] 

如上结果表明重投影成功。但是,运行 glimpse(data) 命令显示坐标仍然在原来的投影系统中:

Rows: 300
Columns: 2
$ point_z  <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0~
$ geometry <POINT [°]> POINT (2387371 289191.4), POINT (2387411 289054.1), ~

如何将这些点更改为纬度和经度点?

要将数据转换为 lat/lon,首先您需要使用原始 crs 值加载它。

data <- st_as_sf(data, coords = c('point_x', 'point_y'), 
          crs = 26777)

您将获得原始数据的 sf 对象,具有原始坐标,但现在 st_transform 将知道如何将其转换为其他坐标系:

data_latlong <- st_transform(data, crs = 4326)

应该给你 latitude/longitude 值的坐标。