适用于地理区域的R包

时间:2014-10-28 15:21:43

标签: r

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

2 个答案:

答案 0 :(得分:2)

Howabout:

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

Veneto

答案 1 :(得分: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

你也可以使用“普通”shapefile,这个(最有可能)是Spacedman帖子中引用的raster包中的内容:

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