r - 从地理 WGS84 到 R 中墨卡托的项目 - 点不有限

标签 r gis map-projections

我在 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/

相关文章:

javascript - 使用D3.js绘制自定义json映射

java - Java中不同 map 投影之间的转换

r - 在ggplot2图表中按因子计数

image-processing - 将 2D 点映射到新的视角

r - 从 R 数据框列中提取键值对

google-bigquery - 6小时后查询超时,如何优化?

java - 如何使用preparedstatement更新SQL Server列中 "Geometry"的数据

java - 如何创建美国 map 并自由填充每个州的颜色?

r - 提取第一节和第三节之间的字符

r - dplyr:评估错误:使用 gamlss 找不到对象 '.',但使用 lm、gam、glm 方法都很好