-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy patheow05.R
32 lines (27 loc) · 976 Bytes
/
eow05.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Demonstrate problem with +proj=ortho forward/backward
library(sf)
sessionInfo()
packageVersion("sf")
sf::sf_extSoftVersion()
projFix <- function(crs) # FIXME: check sf version (?)
{
if (grepl("+proj=ortho", crs)) {
if (!grepl("+R=", crs))
crs <- paste(crs, "+R=6378137")
if (!grepl("+f=", crs))
crs <- paste(crs, "+f=0")
}
crs
}
proj <- projFix("+proj=ortho +lat_0=-20 +datum=WGS84 +no_defs")
proj0 <- projFix("OGC:CRS84") # ? "+proj=longlat +datum=WGS84 +no_defs"
grid <- expand.grid(lon=seq(-180,180,2.5), lat=seq(-90,90,2.5))
lonlat <- cbind(grid$lon, grid$lat)
xy <- sf_project(proj0, proj, lonlat, keep=TRUE)
LONLAT <- sf_project(proj, proj0, xy, keep=TRUE)
ok <- is.finite(LONLAT[,1]) & is.finite(LONLAT[,2])
par(mar=c(3,3,1,1), mgp=c(2,0.7,0))
plot(xy[,1]/1e3, xy[,2]/1e3, asp=1,
xlab="Easting Coordinate [km]", ylab="Northing Coordinate [km]",
pch=20, cex=0.3, col=ifelse(ok, "red", "blue"))
grid()