【问题标题】:How to have a precise map of a country with R如何使用 R 获得一个国家的精确地图
【发布时间】:2013-10-09 07:55:37
【问题描述】:

我通常会去这个网站: http://gadm.org 找到我想用 R 绘制的国家的轮廓。 但是今天,这个网站关闭了,我不知道如何才能有一个真正准确的地图......

当我尝试时:

library(maps)
map("world", xlim=c(15,23), ylim=c(45.5,49))

这个国家的轮廓不是很准确……

我试图找到一个可以给出轮廓的其他网站,但我没有找到。

有人可以帮助我吗?

【问题讨论】:

  • Natural Earth 有一些不错的 shapefile。
  • 是的,但我不明白如何使用它!你能指导我吗?
  • 使用包maptools 读入一个shapefile。例如,见?readShapeSpatial,一旦你加载了包maptools

标签: r map plot country


【解决方案1】:

好的,假设您想使用来自 Natural Earth 的数据绘制法国等高线:

# First download the data in your working directory
download.file("http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip", "countries.zip")
# Then unzip
unzip("countries.zip")
# Load maptools
library(maptools)
# Read in the shapefile
world <- readShapeSpatial("ne_10m_admin_0_countries.shp")
# Plot France
plot(world[world$ADMIN=="France",1]) 
# Column 1 is the id column, column "ADMIN" contains the country names

【讨论】:

  • 它不起作用:world &lt;- readShapeSpatial("ne_10m_admin_0_countries.shp") Erreur dans getinfo.shape(fn) : Error opening SHP file
  • 您是否准确输入了前两行(download.file 和 unzip)?他们都没有抛出错误?
  • 不,在world &lt;- readShapeSpatial("ne_10m_admin_0_countries.shp") 之前我没有错误。我没有问题地执行“解压缩”etap,file.zip 已在我计算机上的目录中。
  • ... 那你没有输入准确的代码... 我问的原因是因为你得到的错误意味着它没有找到文件如果文件没有解压缩是正常的在工作目录中。将“ne_10m_admin_0_countries.shp”替换为该文件的实际路径。
  • 好的,但解压后的文件(zip 的内容)是否也在您的工作目录中?具体是“ne_10m_admin_0_countries.shp”是你的wd吗?
猜你喜欢
  • 2013-07-15
  • 1970-01-01
  • 1970-01-01
  • 2019-09-28
  • 2020-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多