-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRS header #317
Comments
I am not convinced that what you suggest is a good approach. For example, taking the raster data from issue #314
It seems to me that, especially for a CRS like this, the PROJ.4 notation is the only available notation that is easily interpretable by a human. (You can do My understanding from this lengthy discussion: r-spatial/discuss#43 is that PROJ.4 strings are perfectly valid, as long as you use the WGS84, NAD83 or NAD27 datums. I have now added to
I am not sure if that is generally true, as it depends who produces the file. But obviously the recent changes do lead to confusion. I do not have a good solution, but I am hopeful that the PROJ developers will revert back to more general support for the PROJ.4 string, or at least provide a viable alternative that can be used in interactive environments such as R and python. |
Hi @rhijmans - I agree that taking the I also try to understand all of the PROJ6+ impacts, and yes - it seems that the proj4string representation can be used for coordinate operations as long as you want to use the WGS84, NAD83 or NAD27 datums. Also, maybe this is only my wrong assumption (please correct me @rsbivand), but spatial files created with the current (PROJ6+) versions of PROJ store their CRSs using the WKT2 representation. Showing proj4strings to the terra users gives an impression that the CRSs in this package are stored with proj4string. As I mentioned at the beginning - I do not think we have a perfect solution here. However, the current state of things could be improved without taking major effort. One possible solution is shown below: library(terra)
#> terra version 1.4.1
# example 1 ----------------------------
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
crs(r, describe = TRUE)
#> name EPSG area extent
#> 1 WGS 84 4326 <NA> NA, NA, NA, NA
# header:
# coord. ref. : WGS 84 ("EPSG:4326")
# example 2 ----------------------------
r2 <- project(r, "EPSG:3035")
crs(r2, describe = TRUE)
#> name EPSG
#> 1 ETRS89-extended / LAEA Europe 3035
#> area
#> 1 Europe - European Union (EU) countries and candidates. Europe - onshore and offshore: Albania; Andorra; Austria; Belgium; Bosnia and Herzegovina; Bulgaria; Croatia; Cyprus; Czechia; Denmark; Estonia; Faroe Islands; Finland; France; Germany; Gibraltar; Greece; Hungary; Iceland; Ireland; Italy; Kosovo; Latvia; Liechtenstein; Lithuania; Luxembourg; Malta; Monaco; Montenegro; Netherlands; North Macedonia; Norway including Svalbard and Jan Mayen; Poland; Portugal including Madeira and Azores; Romania; San Marino; Serbia; Slovakia; Slovenia; Spain including Canary Islands; Sweden; Switzerland; Turkey; United Kingdom (UK) including Channel Islands and Isle of Man; Vatican City State
#> extent
#> 1 -35.58, 44.83, 84.17, 24.60
# header:
# coord. ref. : ETRS89-extended / LAEA Europe ("EPSG:3035")
# example 3 ----------------------------
r3 <- rast(ncols=349, nrows=277, nlyrs=1, xmin=-16231.4942528736, xmax=11313351.4942529, ymin=-16231.5, ymax=8976019.5, names=c('vwsh_1'), crs="+proj=lcc +lat_0=50 +lon_0=-107 +lat_1=50 +lat_2=50 +x_0=5632642.22547 +y_0=4612545.65137 +datum=WGS84")
crs(r3, describe = TRUE)
#> name EPSG area extent
#> 1 unknown <NA> <NA> NA, NA, NA, NA
is.lonlat(r3)
#> [1] FALSE
# header:
# coord. ref. : Unknown projected coordinate reference system
# example 4 ----------------------------
r4 <- rast(ncols=349, nrows=277, nlyrs=1, xmin=-16231.4942528736, xmax=11313351.4942529, ymin=-16231.5, ymax=8976019.5, names=c('vwsh_1'), crs="+proj=longlat")
crs(r4, describe = TRUE)
#> name EPSG area extent
#> 1 unknown <NA> <NA> NA, NA, NA, NA
is.lonlat(r4)
#> [1] TRUE
# header:
# coord. ref. : Unknown geographic (geodetic) coordinate reference system Created on 2021-09-10 by the reprex package (v2.0.1) |
The most important reason for using the PROJ.4 string in
is much more informative then
A hybrid, something like this:
could also be an option I think this is not very clear:
Because instead of a name, a datum name is now given, and you have to understand that this implies lon/lat. I know that the use of PROJ-string to describe a CRS is discouraged. But the stated reason that this improves expressivity is odd. WKT2 is surely more expressive for machines, but this is not the case for people. PROJ.4 notation is the only available practical system that can be used in scripting. I think that should be a good enough reason to actively encourage its use and hope that the PROJ developers change their minds and again provide full support for it (perhaps in extended form). As for what is stored in files; you may be right about GDAL, but not all files are written with GDAL. |
The sp |
> st_crs(read_sf(system.file("gpkg/nc.gpkg", package="sf")))$Name
- 'VirtualXPath' [XML Path Language - XPath]
[1] "NAD27"
> st_crs(stars::L7_ETMs)$Name
[1] "UTM Zone 25, Southern Hemisphere"
> st_crs(4326)$Name
[1] "WGS 84"
> st_crs("EPSG:27700")$Name
[1] "OSGB 1936 / British National Grid"
> st_crs("+proj=lcc +lat_0=50 +lon_0=-107 +lat_1=50 +lat_2=50 +datum=GGRS87 +units=m")$Name
[1] "unknown" |
With the dev version, I now get this behaviour:
|
Thank you, Robert. I think these changes will be helpful to many users. |
With the recent changes in PROJ, CRS information in spatial file formats is stored as WKT2, and no longer as proj4string. However, the terra package still shows the proj4string to the users in its objects' headers. This could be confusing to many people. @rhijmans would you consider switching to some other header style? It could, for example, use some parts of the
crs(r, describe = TRUE)
function.Below, you can find a simple comparison between terra (
coord. ref. : +proj=longlat +datum=WGS84 +no_defs
) and stars/sf (Geodetic CRS: WGS 84
).Created on 2021-09-06 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: