从 Geographic WGS84 到 R 中的 Mercator 的项目 - points not finite
project from Geographic WGS84 to Mercator in R - points not finite
我运行正在研究 R 中一些我不理解的投影问题。
我已经下载了以下全球数据集:
http://www.naturalearthdata.com/downloads/110m-physical-vectors/110m-land/
然后我使用不同的投影创建地图来教授空间投影的概念。
我已成功映射和重新投影/映射 lat/lon WGS84 中的数据并重新投影到 Robinson
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 中一些我不理解的投影问题。
我已经下载了以下全球数据集:
http://www.naturalearthdata.com/downloads/110m-physical-vectors/110m-land/
然后我使用不同的投影创建地图来教授空间投影的概念。
我已成功映射和重新投影/映射 lat/lon WGS84 中的数据并重新投影到 Robinson
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"))