##importar setores
setores <- readOGR("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/Mapas/Shapes","SetCens_2010_desl")
setores <- subset(setores, select = c(2))
##importar mlme
require(raster)
MLME <- raster("C:/___HUBIC/Documents/Dissert/_PROCFINAL/R/2010/MLME10_2010.tif")
M <- c(0, 0, 0, 0, 2, 0, 2, 4, 1, 4, 24, 1)
rcl <- matrix(M, ncol=3, byrow=TRUE)
rclMLME <- reclassify (MLME, rcl)
MLME_SGDF <- as(rclMLME, "SpatialGridDataFrame")
## calcular impb+solo por setor
over <- over(setores, MLME_SGDF, fn = sum, returnList = FALSE)
names(over)="qtdeIS"
bind <- cbind (setores, over)
bind$ha_IS <- (bind$qtdeIS*30*30)/10000
## preparar base de setores
infosetores <- read.dbf ("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/Mapas/Shapes/SetCens_2010_desl.dbf")
infosetores$CD_GEOCODI <- as.character(infosetores$CD_GEOCODI)
infosetores$Ar_ha <- (infosetores$Ar_km2*100)
infosetores <- cbind (infosetores, bind)
infosetores <- subset(infosetores, select = c(2, 16, 19))
#infosetores$ch <- (infosetores$Ar_ha/infosetores$ha_IS)
##importar dados e selecionar variáveis de interesse
dadosBas <- read.csv2 ("C:/_Biblio/IBGE/Censos/Censo2010/Universo/SetoresCensitários/Tabelas/PA/Base informaçoes setores2010 universo PA/CSV/Basico_PA.csv", header = TRUE, sep = ";",na.strings = "X")
dadosBas <- subset(dadosBas, select = c(1, 22:23, 26))
dadosBas$Cod_setor=as.character(dadosBas$Cod_setor)
dadosRRen <- read.csv2 ("C:/_Biblio/IBGE/Censos/Censo2010/Universo/SetoresCensitários/Tabelas/PA/Base informaçoes setores2010 universo PA/CSV/ResponsavelRenda_PA.csv", header = TRUE, sep = ";",na.strings = "X")
dadosRRen <- subset(dadosRRen, select = c(1, 69:78))
dadosRRen$Cod_setor=as.character(dadosRRen$Cod_setor)
dadosDom1 <- read.csv2 ("C:/_Biblio/IBGE/Censos/Censo2010/Universo/SetoresCensitários/Tabelas/PA/Base informaçoes setores2010 universo PA/CSV/Domicilio01_PA.csv", header = TRUE,sep=";",na.strings = "X")
dadosDom1 <- subset(dadosDom1, select = c(1, 14:17, 19:24, 37:44, 45:51))
dadosDom1$Cod_setor=as.character(dadosDom1$Cod_setor)
##Merge e cálculo de porcentagens
setoresdados1 <- merge(infosetores, dadosBas, by.x = "CD_GEOCODI", by.y = "Cod_setor", all.x=TRUE)
names(setoresdados1)[4:6]=c("BasV001","BasV002", "BasV005")
setoresdados1$BasV001 <- as.numeric(setoresdados1$BasV001)
setoresdados1$BasV002 <- as.numeric(setoresdados1$BasV002)
setoresdados1$Dom_ha <- (setoresdados1$BasV001/setoresdados1$ha_IS)
setoresdados1$Pop_ha <- (setoresdados1$BasV002/setoresdados1$ha_IS)
setoresdados1$RenDomSM <- setoresdados1$BasV005/510
setoresdados2 <- merge(setoresdados1, dadosRRen, by.x = "CD_GEOCODI", by.y = "Cod_setor", all.x=TRUE)
names(setoresdados2)[10:19]=c("RRenV067","RRenV068","RRenV069","RRenV070","RRenV071","RRenV072","RRenV073","RRenV074","RRenV075","RRenV076")
tmp=setoresdados2[,which(names(setoresdados2)=="RRenV067"):which(names(setoresdados2)=="RRenV076")]/setoresdados2$BasV001
names(tmp)=paste("P_",names(tmp),sep="")
setoresdados2=cbind(setoresdados2,tmp)
setoresdados2 <- subset(setoresdados2, select = c(1:9, 20:29))
setoresdados <- merge(setoresdados2, dadosDom1, by.x = "CD_GEOCODI", by.y = "Cod_setor", all.x=TRUE)
names(setoresdados)[20:44]=c("Dom1V012","Dom1V013","Dom1V014","Dom1V015","Dom1V017","Dom1V018","Dom1V019","Dom1V020","Dom1V021","Dom1V022","Dom1V035","Dom1V036","Dom1V037","Dom1V038","Dom1V039","Dom1V040","Dom1V041","Dom1V042","Dom1V043","Dom1V044","Dom1V045","Dom1V046","Dom1V047","Dom1V048","Dom1V049")
tmp=setoresdados[20:44]/setoresdados$BasV001
names(tmp)=paste("P_",names(tmp),sep="")
setoresdados=cbind(setoresdados,tmp)
setoresdados <- subset(setoresdados, select = c(1:19, 45:69))
##atribuir valores ao shape
ordem <- subset(infosetores, select = c(1))
df <- merge (ordem, setoresdados, by = "CD_GEOCODI", sort=FALSE)
setores@data <- df
##exportar shape
proj <- CRS("+proj=utm +zone=22 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0")
proj4string(setores) <- proj
require (rgdal)
setores <- readOGR("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/Mapas/Shapes","SetCens_2010_desl")
setores <- subset(setores, select = c(2))
##importar mlme
require(raster)
MLME <- raster("C:/___HUBIC/Documents/Dissert/_PROCFINAL/R/2010/MLME10_2010.tif")
M <- c(0, 0, 0, 0, 2, 0, 2, 4, 1, 4, 24, 1)
rcl <- matrix(M, ncol=3, byrow=TRUE)
rclMLME <- reclassify (MLME, rcl)
MLME_SGDF <- as(rclMLME, "SpatialGridDataFrame")
## calcular impb+solo por setor
over <- over(setores, MLME_SGDF, fn = sum, returnList = FALSE)
names(over)="qtdeIS"
bind <- cbind (setores, over)
bind$ha_IS <- (bind$qtdeIS*30*30)/10000
## preparar base de setores
infosetores <- read.dbf ("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/Mapas/Shapes/SetCens_2010_desl.dbf")
require(foreign)
infosetores <- read.dbf ("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/Mapas/Shapes/SetCens_2010_desl.dbf")
infosetores$CD_GEOCODI <- as.character(infosetores$CD_GEOCODI)
infosetores$Ar_ha <- (infosetores$Ar_km2*100)
infosetores <- cbind (infosetores, bind)
infosetores <- subset(infosetores, select = c(2, 16, 19))
#infosetores$ch <- (infosetores$Ar_ha/infosetores$ha_IS)
##importar dados e selecionar variáveis de interesse
dadosBas <- read.csv2 ("C:/_Biblio/IBGE/Censos/Censo2010/Universo/SetoresCensitários/Tabelas/PA/Base informaçoes setores2010 universo PA/CSV/Basico_PA.csv", header = TRUE, sep = ";",na.strings = "X")
dadosBas <- subset(dadosBas, select = c(1, 22:23, 26))
dadosBas$Cod_setor=as.character(dadosBas$Cod_setor)
dadosRRen <- read.csv2 ("C:/_Biblio/IBGE/Censos/Censo2010/Universo/SetoresCensitários/Tabelas/PA/Base informaçoes setores2010 universo PA/CSV/ResponsavelRenda_PA.csv", header = TRUE, sep = ";",na.strings = "X")
dadosRRen <- subset(dadosRRen, select = c(1, 69:78))
dadosRRen$Cod_setor=as.character(dadosRRen$Cod_setor)
dadosDom1 <- read.csv2 ("C:/_Biblio/IBGE/Censos/Censo2010/Universo/SetoresCensitários/Tabelas/PA/Base informaçoes setores2010 universo PA/CSV/Domicilio01_PA.csv", header = TRUE,sep=";",na.strings = "X")
dadosDom1 <- subset(dadosDom1, select = c(1, 14:17, 19:24, 37:44, 45:51))
dadosDom1$Cod_setor=as.character(dadosDom1$Cod_setor)
##Merge e cálculo de porcentagens
setoresdados1 <- merge(infosetores, dadosBas, by.x = "CD_GEOCODI", by.y = "Cod_setor", all.x=TRUE)
names(setoresdados1)[4:6]=c("BasV001","BasV002", "BasV005")
setoresdados1$BasV001 <- as.numeric(setoresdados1$BasV001)
setoresdados1$BasV002 <- as.numeric(setoresdados1$BasV002)
setoresdados1$Dom_ha <- (setoresdados1$BasV001/setoresdados1$ha_IS)
setoresdados1$Pop_ha <- (setoresdados1$BasV002/setoresdados1$ha_IS)
setoresdados1$RenDomSM <- setoresdados1$BasV005/510
setoresdados2 <- merge(setoresdados1, dadosRRen, by.x = "CD_GEOCODI", by.y = "Cod_setor", all.x=TRUE)
names(setoresdados2)[10:19]=c("RRenV067","RRenV068","RRenV069","RRenV070","RRenV071","RRenV072","RRenV073","RRenV074","RRenV075","RRenV076")
tmp=setoresdados2[,which(names(setoresdados2)=="RRenV067"):which(names(setoresdados2)=="RRenV076")]/setoresdados2$BasV001
names(tmp)=paste("P_",names(tmp),sep="")
setoresdados2=cbind(setoresdados2,tmp)
setoresdados2 <- subset(setoresdados2, select = c(1:9, 20:29))
setoresdados <- merge(setoresdados2, dadosDom1, by.x = "CD_GEOCODI", by.y = "Cod_setor", all.x=TRUE)
names(setoresdados)[20:44]=c("Dom1V012","Dom1V013","Dom1V014","Dom1V015","Dom1V017","Dom1V018","Dom1V019","Dom1V020","Dom1V021","Dom1V022","Dom1V035","Dom1V036","Dom1V037","Dom1V038","Dom1V039","Dom1V040","Dom1V041","Dom1V042","Dom1V043","Dom1V044","Dom1V045","Dom1V046","Dom1V047","Dom1V048","Dom1V049")
tmp=setoresdados[20:44]/setoresdados$BasV001
names(tmp)=paste("P_",names(tmp),sep="")
setoresdados=cbind(setoresdados,tmp)
setoresdados <- subset(setoresdados, select = c(1:19, 45:69))
##atribuir valores ao shape
ordem <- subset(infosetores, select = c(1))
df <- merge (ordem, setoresdados, by = "CD_GEOCODI", sort=FALSE)
setores@data <- df
##exportar shape
proj <- CRS("+proj=utm +zone=22 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0")
proj4string(setores) <- proj
writeOGR (setores, "C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/Mapas/Shapes", "SetCens_2010_desl_dados", driver="ESRI Shapefile", overwrite_layer=TRUE)
bairros <- readOGR("C:/___HUBIC/Documents/Dissert/_PROCFINAL/SIG","SetoresOcupa_Bairros")
bairros <- readOGR("C:/___HUBIC/Documents/Dissert/_PROCFINAL/SIG","SetoresOcupa")
bairros <- subset(bairros, select = c(1, 13))
require (rgdal)
setores <- readOGR("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/Mapas/Shapes","SetCens_2010_desl")
setores <- subset(setores, select = c(2))
require(raster)
MLME <- raster("C:/___HUBIC/Documents/Dissert/_PROCFINAL/R/2010/MLME10_2010.tif")
M <- c(0, 0, 0, 0, 2, 0, 2, 4, 1, 4, 24, 1)
rcl <- matrix(M, ncol=3, byrow=TRUE)
rclMLME <- reclassify (MLME, rcl)
MLME_SGDF <- as(rclMLME, "SpatialGridDataFrame")
over2 <- over(MLME_SGDF, setores, returnList = FALSE)
spg <- over2
coordinates(spg) <- over2[c("s1", "s2")]
MLME_DF <- data.frame(MLME_SGDF)
colnames(MLME_DF)<-c("ocup", "s1", "s2")
bind <- cbind (MLME_DF, over2)
MLME_DF <- data.frame(MLME_SGDF)
temp <- MLME_SGDF
str (over2)
bairros <- readOGR("C:/___HUBIC/Documents/Dissert/_PROCFINAL/SIG","SetoresOcupa")
bairros <- subset(bairros, select = c(1, 13))
over3 <- over(bairros, over2, fn = sum, returnList = FALSE)
require (rgdal)
setores = readOGR("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/Mapas/Shapes","SetCens_2010_desl_dados")
#importar mlme, classificar ocupado/não ocupado e converter para SGDF
require(raster)
MLME = raster("C:/___HUBIC/Documents/Dissert/_PROCFINAL/R/2010/MLME10_2010.tif")
M = c(-1, 2, NA, 2, 24, 1)
rcl = matrix(M, ncol=3, byrow=TRUE)
rcl
rclMLME = reclassify (MLME, rcl)
MLME_SGDF = as(rclMLME, "SpatialGridDataFrame")
mask = MLME_SGDF
#atribuir dados censo ao grid ocupado
over2 = over(MLME_SGDF, setores, returnList = FALSE)
MLME_SGDF@data = over2
mask@data[1:3,]
MLME_SGDF@data[is.na(mask@data)==T,]=NA
writeOGR (MLME_SGDF, "C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/Mapas/Shapes", "MLME_SGDF", driver="ESRI Shapefile", overwrite_layer=TRUE)
sink("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/Out/tempos.txt")
cat("NOTE MAYUMI")
cat("\n")
cat("Memória RAM = 4GB")
cat("\n")
cat("Processador = Intel i5 2.27 GHz")
cat("\n")
cat("Sistema Operacional = 32 Bits")
cat("\n")
cat("\n")
cat("tempo 2010_I")
system.time (source ("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/2010_I.R"))
cat("\n")
cat("\n")
cat("tempo 2000_I")
system.time (source ("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/2000_I.R"))
cat("\n")
sink()
##2 Atribuir valores das variáveis para o GRID
# Importar Setores
require(rgdal)
SetoresPOL_Dados = readOGR("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/Out", "2000_Setores_DadosI")
# Importar MLME
require(raster)
MLME = raster("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/In/MLME10_2000_WGS84.tif")
# Classificar ocupado/não ocupado e converter para SGDF
M = c(-1, 5, 0, 5, 24, 1)
rcl = matrix(M, ncol=3, byrow=TRUE)
rcl
rclMLME = reclassify (MLME, rcl)
MLME_SGDF = as(rclMLME, "SpatialGridDataFrame")
# Juntar Setores_Dados e SGDF
MLME_SGDF_2 = MLME_SGDF
over2 = over(MLME_SGDF_2, SetoresPOL_Dados, returnList = FALSE)
str (over2)
str (MLME_SGDF_2)
install.packages("RSAGA")
install.packages("RSAGA")
install.packages("RSAGA")
install.packages("RSAGA")
install.packages("RSAGA")
x = read.ascii.grid("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/Out", "2010_Grid_Setores_DadosI", return.header = TRUE, print = 0, nodata.values = c(), at.once = TRUE, na.strings = "NA")
require (RSAGA)
x = read.ascii.grid("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/Out", "2010_Grid_Setores_DadosI", return.header = TRUE, print = 0, nodata.values = c(), at.once = TRUE, na.strings = "NA")
grd = as("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/Out", "2010_Grid_Setores_DadosI", "SpatialGrid")
grd = as("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/Out", "2010_Grid_Setores_DadosI", "SpatialGrid")
MLME_SGDF_2010 = readOGR ("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/Out", "2010_Grid_Setores_DadosI")
require(rgdal)
MLME_SGDF_2010 = readOGR ("C:/___HUBIC/Documents/2-DOUTORADO/SER300/Monografia/WGS84/Out", "2010_Grid_Setores_DadosI")
require(rgdal)
library("rgdal", lib.loc="C:/Users/mayumi/Documents/R/win-library/3.1")
