【发布时间】:2012-02-09 05:32:14
【问题描述】:
给定一个 shapefile,我如何塑造和使用数据文件,以便能够使用与 shapefile 中的形状区域对应的标识符来绘制专题地图?
#Download English Government Office Network Regions (GOR) from:
#http://www.sharegeo.ac.uk/handle/10672/50
tmp_dir = tempdir()
url_data = "http://www.sharegeo.ac.uk/download/10672/50/English%20Government%20Office%20Network%20Regions%20(GOR).zip"
zip_file = sprintf("%s/shpfile.zip", tmp_dir)
download.file(url_data, zip_file)
unzip(zip_file, exdir = tmp_dir)
library(maptools)
#Load in the data file (could this be done from the downloaded zip file directly?
gor=readShapeSpatial(sprintf('%s/Regions.shp', tmp_dir))
#I can plot the shapefile okay...
plot(gor)
#and I can use these commands to get a feel for the data...
summary(gor)
attributes(gor@data)
gor@data$NAME
#[1] North East North West
#[3] Greater London Authority West Midlands
#[5] Yorkshire and The Humber South West
#[7] East Midlands South East
#[9] East of England
#9 Levels: East Midlands East of England ... Yorkshire and The Humber
#download data from http://www.justice.gov.uk/downloads/publications/statistics-and-data/courts-and-sentencing/csq-q3-2011-insolvency-tables.csv
#insolvency<- read.csv("~/Downloads/csq-q3-2011-insolvency-tables.csv")
insolvency=read.csv("http://www.justice.gov.uk/downloads/publications/statistics-and-data/courts-and-sentencing/csq-q3-2011-insolvency-tables.csv")
insolvencygor.2011Q3=subset(insolvency,Time.Period=='2011 Q3' & Geography.Type=='Government office region')
#tidy the data
require(gdata)
insolvencygor.2011Q3=drop.levels(insolvencygor.2011Q3)
names(insolvencygor.2011Q3)
#[1] "Time.Period" "Geography"
#[3] "Geography.Type" "Company.Winding.up.Petition"
#[5] "Creditors.Petition" "Debtors.Petition"
levels(insolvencygor.2011Q3$Geography)
#[1] "East" "East Midlands"
#[3] "London" "North East"
#[5] "North West" "South East"
#[7] "South West" "Wales"
#[9] "West Midlands" "Yorkshire and the Humber"
#So what next?
到目前为止,我该如何采取下一步来生成主题/等值线图,例如根据 Debtors.Petition 值对每个区域进行着色?
(我还刚刚注意到一个可能的问题 - 大写 GOR 级别不匹配:“Yorkshire and the Humber”和“Yorkshire and The Humber”)
【问题讨论】:
-
似乎this SO post(右侧栏中“相关”列表中的第一个)可能会帮助您完成剩下的工作。
-
我看到了,但是前几次都错过了修复...所以我需要做的是:gor@data=merge(insolvencygor.2011Q3,gor@data,by .x='Geography',by.y='NAME') plot(gor,col=levels(gor@data$Creditors.Petition)) 虽然具有适当的颜色映射和适当的区域名称映射(我注意到它不仅仅是约克和亨伯赛德的不匹配......)
-
您能否将您的数据集简化为一个小示例来说明您的问题?您可以使用 save 命令保存这些并将它们上传到 SO 或服务器并在此处发布链接。这将使您更轻松地减少大量代码。
-
我不知道如何使 shapefile 变小...我从以下位置开始:a)想要生成专题地图,b)知道存在用于在地图上生成轮廓的 shapefile,和 c) 错误,就是这样......也许值得一提的是,我在这种情况下使用 R 的原因是因为在我看来 R 可以处理 shapefile......
-
还有其他工具可以很容易地处理 shapefile,例如QGis 或 GVSig,它们都是开源 GIS 程序。