如何使用 R 从 PROJ4 字符串接收 EPSG 代码?

Exp*_*reR 2 r raster utm coordinate-systems epsg

如何使用 R 从 PROJ4 字符串接收 EPSG 代码

我有一堆栅格数据集(随机分布在世界各地,北半球和南半球),具有坐标参考系统UTM WGS84。现在我想使用 R 找出每个数据集的具体 EPSG 代码。你有什么想法吗?

# Install and load package raster
install.packages('raster')
library(raster)

# Load a specific raster dataset and query the crs
raster_dat <- raster('D:/UnknownUser/GlobalRasterData/raster_dat1')
crs(raster_dat)
# CRS arguments:
#  +proj=utm +zone=13 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
Run Code Online (Sandbox Code Playgroud)

也许可以以动态方式创建 EPSG 代码,因为 EPSG 代码似乎始终是北半球的 <326> 和特定区域编号(例如 <32>)(德国)的组合,这会导致EPSG 代码 <326> + <32> = <32632>。

不幸的是,我发现您似乎从南半球的 <327> 开始,然后添加特定的区域编号,例如 <32> (尼日利亚),结果是 <327> + <32> =<32732>。

现在我不确定这个理论是否正确(需要验证,包括来源))以及是否有更简单的方法从 PROJ4 字符串接收 EPSG 代码。

我发现的有用链接:

网址:https ://spatialreference.org/ref/epsg/?page=9&search=wgs+84+utm

网址: https: //epsg.io/32632

网址:https://de.wikipedia.org/wiki/UTM-Kooperativensystem#/media/Datei :Utm-zones.jpg

编辑:

# Install and load package rgdal
install.packages('rgdal')
library(rgdal)

# following function could be helpful; it creates a dataframe with 3columns; epsg-code, annotation and proj4-string - unfortunately it seems like there is not an epsg code for each utm wgs84 zone...
epsg_list <- rgdal::make_EPSG()
Run Code Online (Sandbox Code Playgroud)

预先非常感谢,ExploreR

mrh*_*ann 6

rgdal包还有一个showEPSG()功能。


## example data from sf package
nc <- sf::read_sf(system.file("shape/nc.shp", package="sf"))
nc_crs <- raster::crs(nc)
nc_crs
#> [1] "+proj=longlat +datum=NAD27 +no_defs"

rgdal::showEPSG(nc_crs)
#> [1] "4267"

## Double check it with sf::st_crs
sf::st_crs(nc)
#> Coordinate Reference System:
#>   EPSG: 4267 
#>   proj4string: "+proj=longlat +datum=NAD27 +no_defs"

## Your proj4 string
p4_example <- '+proj=utm +zone=13 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0;'
rgdal::showEPSG(p4_example)
#> [1] "32613"
Run Code Online (Sandbox Code Playgroud)

由reprex 包(v0.3.0)于 2020-01-09 创建