为什么sf :: st_transform()返回一个与调用中使用的投影不同的对象?

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

我想使用sf::st_transform()重新投影我的sf对象,但是变换对象的投影与我在转换调用中指定的投影不同。为什么?

library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3

# target proj4string
my_crs <- "+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs"

# create test sfc
p1 <- st_sfc(st_point(c(1,2)), crs = "+init=epsg:3857")

# re-project p1 to `my_crs`
p2 <- st_transform(p1, crs = my_crs)

all.equal(my_crs, st_crs(p2)$proj4string)
#> [1] "1 string mismatch"

st_crs(p2)
#> Coordinate Reference System:
#>   No EPSG code
#>   proj4string: "+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs"

投影之间的唯一区别是proj4string中的+x_0元素。在p2的投影中已经删除了尾随的1e-10。

r coordinate-systems sf map-projections proj4
1个回答
0
投票

sf::st_transform()使用GDAL进行预测。帮助页面说明:

Some PROJ.4 projections are not supported by GDAL, e.g. "+proj=wintri" because it does 
not have an inverse projection. Projecting to unsupported projections can be done by 
st_transform_proj, part of package lwgeom. Note that the unsupported proj4string cannot 
be passed as argument to st_crs, but has to be given as character string.

如果您在示例中使用PROJ.4进行投影,则它可以正常工作:

library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(lwgeom)
#> Linking to liblwgeom 2.5.0dev r16016, GEOS 3.6.1, PROJ 4.9.3

my_crs <- "+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs"

p1 <- st_sfc(st_point(c(1,2)), crs = "+init=epsg:3857")

p2 <- lwgeom::st_transform_proj(p1, crs = my_crs)

all.equal(my_crs, st_crs(p2)$proj4string)
#> [1] TRUE

我不太了解制图,如果差异是由于帮助页面中提到的反向投影问题或其他原因造成的。

有关:

https://stackoverflow.com/a/51663647/1707525

https://github.com/r-spatial/sf/issues/810

https://github.com/r-spatial/sf/issues/1019

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