2014-10-28 78 views
-1

有人告诉我一个R包,其中包含一些区域和国家边界的物体定义。我试图找到意大利地区威尼托的边界。包装的名称是什么?你知道另一种方法来找到边界(我不确定威尼托是否包含在包中)?地理区域的R包

回答

2

Howabout:

require(raster) 
veneto = subset(getData('GADM', country='ITA', level=1), NAME_1=="Veneto") 
plot(veneto) 

Veneto

+0

非常感谢您!这正是我想要的! – Darko 2014-10-28 15:54:34

+0

你知道关于SpatialPolygonsDataFrame的一个很好的参考吗?我必须在这方面做很大的工作,并且我想知道关于这个对象的所有信息。 – Darko 2014-10-28 16:16:02

+0

https://github.com/Robinlovelace/Creating-maps-in-R/是一个很好的入门教程 – hrbrmstr 2014-10-28 16:35:27

0

您也可以与那些流行与D3人群TopoJSON/GeoJSON的文件的工作:

library(rgdal) 
library(RCurl) 
library(ggplot2) 
library(rgeos) 

# for theme_map() 
devtools::source_gist("https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df") 

# location of Italy TopoJSON file 
url <- "https://gist.githubusercontent.com/andreaangeli/5b64a102e357198780e9/raw/e076b45eb2fcb8de6a0ec612f863499181bb494b/ita.json" 

download.file(url, destfile="ita.json", method="curl") 

ogrListLayers("ita.json") # to see that the layer is "reg2011" 

ita <- readOGR("ita.json", "reg2011") 

veneto <- ita[ita$id == 5,] # region 5 is Veneto 

# could just plot(veneto) now, but I like ggplot better 

veneto_map <- fortify(veneto, region="id") 

gg <- ggplot(data=veneto_map) 
gg <- gg + geom_map(map=veneto_map, aes(map_id=id, group=group, x=long, y=lat), color="black", fill="white") 
gg <- gg + coord_map() 
gg <- gg + theme_map() 
gg 

enter image description here

你也可以与“正常”形状文件一起工作,这是一个(大多数可能)有什么在raster包Spacedman的帖子引用:

download.file("http://biogeo.ucdavis.edu/data/diva/adm/ITA_adm.zip", "ITA_adm.zip") 
unzip("ITA_adm.zip", exdir="ITA_adm") 

ita <- readOGR("ITA_adm/", "ITA_adm1") 

veneto <- ita[ita$NAME_1 == "Veneto",] # this shapefile has region names in it! 

veneto_map <- fortify(veneto) 

gg <- ggplot(data=veneto_map) 
gg <- gg + geom_map(map=veneto_map, aes(map_id=id, group=group, x=long, y=lat), color="black", fill="white") 
gg <- gg + coord_map() 
gg <- gg + theme_map() 
gg 

enter image description here

+0

谢谢!但是venezia怎么样?它已经从那张地图上切下来了...... – Darko 2014-10-28 16:14:09

+0

它已经被“优化/简化了,许多TopoJSON/GeoJSON文件试图减少多边形的数量,所以形状的绘制速度越快(多边形越多,速度就越慢)区域级形状文件通常也会进行这种多边形优化(即,它不是限于TopoJSON/GeoJSON的功能),即使是来自http://www.istat.it/it/archivio/24613的管理级别的shape文件也已被简化。你需要的细节,可以找到其他来源(如内置Spacedman显示)。对于_many_映射的需要,边界细节并不重要。 – hrbrmstr 2014-10-28 16:27:08

+0

我从字面上发现,也有一个在2s谷歌搜索之后。 – hrbrmstr 2014-10-28 16:27:43