sf sfc对象的坐标转换似乎无法正常工作

4

我有一个 R sf 对象:

library(sf)
library(magritr)

g1 = structure(list(ele = c(1819.80249, 1821.150879, 1825.393188, 
1817.905029), time = structure(c(1542700973, 1542701079, 1542701326, 
1542701500), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    geometry = structure(list(structure(c(36.228614, -0.38239
    ), class = c("XY", "POINT", "sfg")), structure(c(36.228447, 
    -0.382341), class = c("XY", "POINT", "sfg")), structure(c(36.227496, 
    -0.382352), class = c("XY", "POINT", "sfg")), structure(c(36.227352, 
    -0.382332), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT", 
    "sfc"), precision = 0, bbox = structure(c(36.227352, -0.38239, 
    36.228614, -0.382332), .Names = c("xmin", "ymin", "xmax", 
    "ymax"), class = "bbox"), crs = structure(list(epsg = NA_integer_, 
        proj4string = NA_character_), .Names = c("epsg", "proj4string"
    ), class = "crs"), n_empty = 0L)), .Names = c("ele", "time", 
"geometry"), row.names = 2:5, class = c("sf", "data.table", "data.frame"
), sf_column = "geometry", agr = structure(c(NA_integer_, NA_integer_
), .Names = c("ele", "time"), .Label = c("constant", "aggregate", 
"identity"), class = "factor"))

这显示为

> g1
Simple feature collection with 4 features and 2 fields
geometry type:  POINT
dimension:      XY
bbox:           xmin: 36.22735 ymin: -0.38239 xmax: 36.22861 ymax: -0.382332
epsg (SRID):    NA
proj4string:    NA
       ele                time                   geometry
2 1819.802 2018-11-20 08:02:53  POINT (36.22861 -0.38239)
3 1821.151 2018-11-20 08:04:39 POINT (36.22845 -0.382341)
4 1825.393 2018-11-20 08:08:46  POINT (36.2275 -0.382352)
5 1817.905 2018-11-20 08:11:40 POINT (36.22735 -0.382332)

我希望将坐标转换为CRS=32736:

g1 %>% st_set_crs(32736) %>% st_transform(crs=32736)

这将会给出:

Simple feature collection with 4 features and 2 fields
geometry type:  POINT
dimension:      XY
bbox:           xmin: 36.22735 ymin: -0.38239 xmax: 36.22861 ymax: -0.382332
epsg (SRID):    32736
proj4string:    +proj=utm +zone=36 +south +datum=WGS84 +units=m +no_defs
       ele                time                   geometry
2 1819.802 2018-11-20 08:02:53  POINT (36.22861 -0.38239)
3 1821.151 2018-11-20 08:04:39 POINT (36.22845 -0.382341)
4 1825.393 2018-11-20 08:08:46  POINT (36.2275 -0.382352)
5 1817.905 2018-11-20 08:11:40 POINT (36.22735 -0.382332)

坐标尚未重新投影。我在做什么错误的地方?

你首先要说坐标是32736:st_set_crs(32736),然后再将其转换为相同的坐标系;st_transform(crs=32736)...所以(当然)什么也不会改变...你必须使用st_set_crs来设置原始shapefile的坐标系...然后使用st_transform来转换为32736。 - Wimpel
谢谢 - 原始的crs是NA。我不能直接进行转换,因为st_transform(g1, crs = 32736)会出现“Error in st_transform.sfc(st_geometry(x), crs, ...) : sfc object should have crs set”的错误提示。 - Henk
你必须找到一种方法来确定输入数据的坐标系... - Wimpel
它是经纬度WGS84坐标系4326。 - Henk
1个回答

5

根据上述评论:

g1 %>% st_set_crs(4326) %>% st_transform(crs=32736)

这可能是你正在寻找的内容

# Simple feature collection with 4 features and 2 fields
# geometry type:  POINT
# dimension:      XY
# bbox:           xmin: 859306.9 ymin: 9957667 xmax: 859447.5 ymax: 9957673
# epsg (SRID):    32736
# proj4string:    +proj=utm +zone=36 +south +datum=WGS84 +units=m +no_defs
# ele                time                 geometry
# 2 1819.802 2018-11-20 08:02:53 POINT (859447.5 9957667)
# 3 1821.151 2018-11-20 08:04:39 POINT (859428.9 9957672)
# 4 1825.393 2018-11-20 08:08:46 POINT (859322.9 9957671)
# 5 1817.905 2018-11-20 08:11:40 POINT (859306.9 9957673)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接