我在 R 中遇到了一些我不理解的投影问题。
我已经下载了以下全局数据集:
http://www.naturalearthdata.com/downloads/110m-physical-vectors/110m-land/
然后,我使用不同的投影创建 map 来教授空间投影的概念。
我已成功映射并重新投影/映射纬度/经度 WGS84 中的数据并重新投影到罗宾逊
library(rgdal)
library(ggplot2)
setwd("~/Documents/data")
# read shapefile
worldBound <- readOGR(dsn="Global/Boundaries/ne_110m_land",
layer="ne_110m_land")
# convert to dataframe
worldBound_df <- fortify(worldBound)
# plot map
ggplot(worldBound_df, aes(long,lat, group=group)) +
geom_polygon() +
labs(title="World map (longlat)") +
coord_equal() +
ggtitle("Geographic - WGS84 Datum")
# reproject from longlat to robinson
worldBound_robin <- spTransform(worldBound,
CRS("+proj=robin"))
worldBound_df_robin <- fortify(wmap_robin)
ggplot(worldBound_df_robin, aes(long,lat, group=group)) +
geom_polygon() +
labs(title="World map (robinson)") +
coord_equal()
现在 - 当我尝试投影到 Mercator WGS84 时,我遇到了问题。
# reproject from longlat to mercator
worldBound_merc <- spTransform(worldBound,
CRS("+init=epsg:3395"))
# make ggplot happy
worldBound_df_merc <- fortify(worldBound_merc)
# plot map
ggplot(worldBound_df_merc, aes(long,lat, group=group)) +
geom_polygon() +
labs(title="World map (Mercator WGS84)") +
coord_equal()
我收到错误: .spTransform_Polygon(input[[i]], to_args = to_args, from_args = from_args, 中的错误: 多边形 8 点失败 多边形 1 点 另外:警告消息: 在 .spTransform_Polygon(input[[i]], to_args = to_args, from_args = from_args, 中: 2 个投影点非有限
错误出现在 spTransform 函数上。对于某些点来说,它似乎无法计算从经纬度到墨卡托的有限 xy 坐标,但我不明白如何解决/解决这个问题。我在此网站和其他网站上的搜索导致了此错误的其他实例,但没有很好地解释投影数据时触发错误的原因,以便我可以修复它。
感谢您的指导! 利亚
解决方案代码: 对于那些遇到这个问题的人 - 我只是裁剪了数据以便能够使用墨卡托进行绘图。这只是一个演示,因此出于视觉、绘图目的丢失一些数据是可以的。
# create extent object from world data
newExt <- extent(worldBound)
# redefine the extent to the limits of mercator EPSG 3395
newExt@ymin <- -80
newExt@ymax <- 80
# crop data to new extent
merc_WorldBound <- crop(worldBound,
newExt)
# reproject from longlat to mercator
worldBound_merc <- spTransform(merc_WorldBound,
CRS("+init=epsg:3395"))
最佳答案
问题似乎是位于 epsg:3395 投影范围之外的点 (-180, -80, 180, 84) http://spatialreference.org/ref/epsg/wgs-84-world-mercator/ 。要纠正此问题,您可以将 shapefile 裁剪到适当的范围,然后执行重新投影。
library(raster)
library(rgdal)
worldBoundClipped <- crop(worldBound,extent(-180,180,-84,80))
worldBound_merc <- spTransform(worldBoundClipped,CRS("+init=epsg:3395"))
关于r - 从地理 WGS84 到 R 中墨卡托的项目 - 点不有限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35611194/