-
Notifications
You must be signed in to change notification settings - Fork 0
/
total.r
77 lines (60 loc) · 2.24 KB
/
total.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
###########################
# FINAL
###########################
#install necessary packages
source("library.R")
source("function definition.R")
load("NPP.RData")
#######################################
#TODO
#######################################
#download shapefile from FTP
#need to modify according to different years
url0="ftp://ftp2.census.gov/geo/pvs/tiger2010st/"
path="E:/UW/summer2014/USNPP"
statename<-read.csv("E:/UW/summer2014/USNPP/other/statename.csv",header=T,colClasses="character")
url.list<-paste(url0,statename[,2],"_",statename[,1],"/",statename[,2],"/tl_2010_",statename[,2],"_tract10.zip",sep="")
download.list<-paste(path,"/rawshapefile/",statename[,1],".zip",sep="")
shapefilename<-paste(path,"/rawshapefile/tl_2010_",statename[,2],"_tract10.shp",sep="");
#######################################
for(i in 1:dim(statename)[1])
{
download.file(url=url.list[i], destfile=download.list[i])
}
sapply(download.list,FUN=unzip,exdir=paste(path,"/rawshapefile",sep=""))
#save shapefiles in order for later loading
print("choose directory to save all these shapefile")
savedirect<-choose.dir()
for(i in 1:length(shapefilename))
npp.save.shapefile(shapefilename,savedirect,statename[i,1])
#get coordinates of entire united states shapefiles
path="E:/UW/summer2014/USNPP/"
filename<-paste(path,"/shapefile2010/",statename[,1],".RData",sep="")
coord.US<-NULL
for(i in 1:length(filename))
{
coord.US<-rbind(coord.US,npp.coord.matrix(filename[i]))
}
geoid.NPP<-lapply(c(1:dim(NPP)[1]),FUN=npp.selectone,coord.matrix=coord.US,distance=50)
str(geoid.NPP)
########################
#get shape.dataframe
#and save them
########################
#todo path
neighbour<-lapply(1:67,FUN=npp.neighbour,geoid=geoid.NPP)
########################
#read in characteristic data
########################
myindex=6
short<-npp.read(path="E:/Dropbox/NPP/NPP",Ychar="0812")
reg.data<-npp.regdata(short,geoid.NPP,index=myindex)
path0="E:/UW/summer2014/USNPP/shapefile2010"
shape.frame<-npp.shapeframe(path=path0,index=myindex,geoid.NPP,neighbour,statename)
mapdata<-npp.mapdata(reg.data,shape.frame)
#mapping
mapping.pop<-npp.mapping(regdata=reg.data,mapdata,NPP,index=myindex,factor.interest="pop")
mapping.pop
plot.pop<-npp.plot(wkdata=reg.data,interest="pop")
plot.pop
#regression