如何切换到r中的proj6
我正在尝试从RGDAL和PROJ4切换出来,因为两者都被弃用。 我尝试使用SF分配一个坐标参考系统,但继续遇到有关CRS仍然是ProJ4的错误。  
pacman::p_load(sf, raster)
cell.coords <- data.frame(lon = rep(c(2, 3), 2), lat =
rep(c(1, 2), each = 2), cell.id = 10:13)
blank.grid <- st_as_sf(rasterToPolygons(rasterFromXYZ(
cell.coords[ , c("lon", "lat", "cell.id")])))
# Try, in turn, each of the following.
# First three successfully show the crs when blank.grid is called,
# but crs(blank.grid) includes "Deprecated Proj.4 representation"
wgs84 <- 4326
# next is based on https://gis.stackexchange.com/questions/372692/how-should-i-handle-crs-properly-after-the-major-change-in-proj-library
wgs84 <- "OGC:CRS84"
# next is based on https://gis.stackexchange.com/questions/385114/how-to-update-crs-r-object-from-proj4-to-proj6
wgs84 <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +datum=WGS84 +units=m +no_defs"
# For the rest, blank.grid returns CRS: NA
wgs84 <- "4326+datum=WGS84"
wgs84 <- "+init=epsg:4326+datum=WGS84"
wgs84 <- "EPSG:4326"
# Apply and check each option with
st_crs(blank.grid) <- wgs84
blank.grid
crs(blank.grid)
&nbsp; 我意识到我们被推荐了( https://gis.stackexchange.com/questions/372692/how-should-ihold-i handle-crs-properly-after-after-the-major-change-change-change-in-proj-library ) 和/或 http://rgdal.r-forge.r-project.org/articles/proj6_gdal3.html. 这两个都是我不了解的长文档,并且涉及一个细节i级别i使用简单的射手不需要希望。
最佳解决方案将是一个单个命令,以创建空白。grid,以CRS作为参数。使用Terra而不是栅格是最好的,因为我认为我读到栅格也不是这个世界的时间。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
rast
创建栅格模板(空白栅格)。有不同的方法来指定CRS(权威:代码,ProJ或WKT)。例如:r1
和r2
具有相同的坐标参考系统,可用于大多数目的和目的(经度/纬度,wgs84),但请注意上面打印的方式的差异。对于EPSG代码,通常可以使用诸如“ LON/LAT”之类的简短描述。但是您尝试过的这些字符串:“ 4326+datum = wgs84”和“+init = epsg:4326+datum = wgs84”无效,因为它们混合了EPSG和ProJ。您可以使用单个EPSG代码,也可以通过ProJ表示法指定参数。一个例外是使用这样的符号:“+init = epsg:4326”(但是没有理由使用该符号,因为您可以使用“ EPSG:4326”)。
使用SF,您还可以将EPSG代码指定为数字“ 4326”,而没有权限前缀,但是
Terra
不接受(因为它太不透明)。您还可以使用“ WKT”(可能包括对EPSG代码的引用),但这是非常详细的,通常在脚本中通常不用于指定CRS。但这就是它们在内部表示的方式,您可以这样检查它们:
再次显示
r1
比r2
更喜欢。同样不是您可以将其他参数用于
rast
,以设置所需的范围,分辨率和层数。但是,使用您的cell.coords
您可以做:我不确定为什么在示例中使用
rastertopolygons
,但是如果您想要矩形多边形或栅格,或者可以这样做,我可以这样 做请注意,尽管您从rgdal收到的这些讨厌的消息,但出于大多数目的和目的,proj.4符号效果很好,并为最透明的(人类可读)代码提供了良好的作用。
您是对的,前进的道路是忘记栅格/SP和朋友(RGDAL,RGEO),并使用
Terra
和/或sf
而不是。You can use
rast
to create a raster template (blank raster). There are different ways to specify the crs (authority:code, PROJ, or WKT). For example:r1
andr2
have the same coordinate reference system for most intents and purposes (longitude/latitude, WGS84), but note the difference in how they are printed above. For an EPSG code a short description like "lon/lat" is typically available.But these strings you tried: "4326+datum=WGS84" and "+init=epsg:4326+datum=WGS84" are not valid because they mix EPSG and PROJ. You can either use a single EPSG code, or specify parameters via the PROJ notation. The one exception is using the PROJ notation like this: "+init=epsg:4326" (but there is no reason to use that notation anymore as you can instead use "epsg:4326").
With sf, you can also specify the EPSG code as the number only "4326", without the authority prefix, but
terra
does not accept that (because it is too opaque).You can also use "WKT" (that may include references to EPSG codes) but that is very verbose and not typically used in scripts to specify the crs. But it is how they are represented internally, and you can inspect them like this:
Again showing that
r1
is a bit more fancy thanr2
.Also not that you can use additional argument to
rast
, to set the desired extent, resolution, and number of layers. But with yourcell.coords
you can do:I am not sure why you used
rasterToPolygons
in your example but if you wanted rectangular polygons instead or a raster you could doI would note that despite these pesky messages you get from rgdal, for most intents and purposes the PROJ.4 notation works fine, and makes for the most transparent (human-readable) code.
And you are right that the way forward is to forget about raster/sp and friends (rgdal, rgeos), and use
terra
and/orsf
instead.