我在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()现在,当我试图预测到墨卡托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投影点(S)非有限)
错误发生在spTransform函数上。它似乎几乎不能计算一个有限的xy坐标从拉长到墨卡托的一些点,但我不知道如何修复/address这一点。我在这个网站和其他网站上的搜索已经导致了这个错误的其他实例,但是在投影数据时,对于是什么触发了错误,我不能很好地解释,这样我就可以修复它。
谢谢您的指导!莉亚
解决方案代码:对于那些遇到这种情况的人,我只是裁剪数据,以便能够用Mercator绘制图表。这只是一个演示,因此为了可视化、映射的目的,丢失一些数据是可以的。
# 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"))发布于 2016-02-24 20:57:13
问题似乎是在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"))https://stackoverflow.com/questions/35611194
复制相似问题