簡體   English   中英

反向地圖投影:如何從投影坐標中獲取緯度/經度坐標

[英]reverse map-projection: how to get lat/lon coordinates from projected coordinates

我有一組經緯度坐標,我可以使用例如 Mollweide 投影進行投影。

library(mapproj)
set.seed(0)
n <- 100
s <- data.frame(lon = rnorm(n, 0, 60),
                lat = rnorm(n, 0, 40))
p <- mapproject(s$lon, s$lat, proj="mollweide", par=NULL, 
                orientation=c(90,200,0))                 

# plot projected coors
plot(p$x, p$y, type="n", asp=1/1, bty="n")
map.grid(c(-180, 180, -90, 90), nx=20, ny=20, 
         font=1, col=grey(.6), labels=F)
points(p$x, p$y, pch="x", cex = .8)

# a point to reverse project
points(1,0, pch=16, col="red", cex=2)

在此處輸入圖片說明

現在,我有一個場景,我需要對投影坐標進行一些計算,並將結果反向投影回緯度/經度坐標。 例如,如何反向投影紅點[1,0]

任何想法如何做到這一點?

我不知道您是否有理由需要首先使用mapproject進行投影。 如果您可以改用spTransform ,那么這會變得更容易,因為您還可以使用spTransform來反轉相同的過程。

假設您確實需要使用mapproject ,我們仍然可以使用spTransform將點從您的投影坐標系轉換為經緯度坐標,但需要更多的擺弄來處理mapproject投影的非標准格式,即點被標准化為位於 -1 到 1 緯度和 -2 到 2 經度之間。 在更標准的地圖投影中,緯度/經度以距離(通常為米)表示。

所以,首先我們可以使用 spTransform 找出我們需要將歸一化的 mapproject 坐標轉換為實際距離所需的轉換因子:

library(rgdal)
my.points = data.frame(x=c(0,180),y=c(90,0))
my.points = SpatialPoints(my.points, CRS('+proj=longlat'))
my.points = spTransform(my.points, CRS('+proj=moll'))
# SpatialPoints:
#             x       y
# [1,]        0 9020048
# [2,] 18040096       0
# Coordinate Reference System (CRS) arguments: +proj=moll +ellps=WGS84 

現在我們可以使用這些引用將標准化的地圖項目坐標轉換為以米為單位的距離:

my.points = data.frame(x=p$x * 18040096/2 , y=p$y * 9020048)
my.points = SpatialPoints(my.points, CRS('+proj=moll'))

並將這些重新投影到緯度/經度地理坐標中:

my.points = as.data.frame(spTransform(my.points, CRS('+proj=longlat')))

最后,我們需要按經度旋轉這些點,以撤消在mapproject中執行的旋轉。

my.points$x = my.points$x + 200
my.points$x[my.points$x > 180] = my.points$x[my.points$x > 180] - 360

讓我們檢查它是否有效:

head(my.points)
#           x          y
# 1  75.77725  31.274368
# 2 -19.57400 -31.071065
# 3  79.78795 -24.639597
# 4  76.34576   1.863212
# 5  24.87848 -45.215432
# 6 -92.39700  23.068752

head(s)
#         lon        lat
# 1  75.77726  31.274367
# 2 -19.57400 -31.071065
# 3  79.78796 -24.639596
# 4  76.34576   1.863212
# 5  24.87849 -45.215431
# 6 -92.39700  23.068751

如果沒有開箱即用的功能,您可以編寫自己的函數,如下所示:

ref_project <- function(x, y) {
    long <- tibble(
        long = seq(-180, 180, 1),
        x = mapproject(long, rep(0, length(long)), projection = 'mollweide', orientation = c(90, 200, 0))$x
    )
    lat <- tibble(
        lat = seq(-90, 90, 1),
        x = mapproject(rep(0, length(lat)), lat, projection = 'mollweide', orientation = c(90, 200, 0))$y
    )

    return(c(long[which(abs(long$x - x) == min(abs(long$x - x))), 'long'],
             lat[which(abs(lat$x - y) == min(abs(lat$x - y))), 'lat']))
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM