有时我们有大量的数据需要进行地理探测器处理,比如有100个县的shp, 2010年的全国的NDVI与降雨、LUCC、人口密度的数据,要做100个县 NDVI与其他因素的地理探测器分析,不能一个一个的进行探测。我在实际应用过程中,大概总结了一个流程,希望大家指正。
首先在arcgis 模型构建器 建模,使用 sample 进行采样并使用table to excel工具将导出到excel中。迭代的要素便是100个县的矢量数据。关于如何进行多组迭代我还在学习中,还没有尝试在模型中添加模型进行迭代,还是使用python进行处理更好。
获得EXCEL后需要对excel进行处理,删掉所有excel中的索引列、经纬度信息列和有空值的行,这里我使用的是matlab,其他语言应该也可以实现。
%筛选需要的数据并导出
%筛选需要的数据并导出,这里例子是一个Y,8个X,
clc;
clear;
path = 'F:\l';
maindir = dir('F:*.xlsx');
for i =1:length(maindir)
pathori = strcat(maindir(i).name);
dataall = xlsread(pathori);%读取excel中全部数据
dataall(:,1:4)=[];%删掉矩阵前四列
a=all(~isnan(dataall),2);%筛选存在nan的行,含有空值的行为0
out=dataall(a,:);%删掉data中存在空值的行
%输出
outpath1=strcat('F:\lunwen3\2020\hotspots\OPGD\excel\excel\\',pathori(1:7));
outpath=strcat(outpath1,'.xlsx');
%定义表头
biaotou=[{'Y','X1','X2','X3','X4','X5','X6','X7','X8'};num2cell(out)];
xlswrite(outpath,biaotou);
disp(outpath);
end
处理好的数据就可以使用R语言进行地理探测器分析,并导出结果:
install.packages("GD")
install.packages("stringr")
memory.limit(102400)
library(GD)
library(readxl)
library(stringr)
setwd("F:/")#设置当前工作目录
getwd()#查看当前工作目录
temp=list.files(pattern=".xlsx")
for (i in xxxx){ #要自己设置循环的修改范围
filename<-substr(temp[i],1,nchar(temp[i]))#提取文件名
data <- read_excel(filename)
discmethod <-c("equal","natural","quantile")#参数分散方法
discitv <- c(4:8) #间隔数
continuous_variable<- colnames(data[x :x ])#要自己设置连续变量
testgdm<-gdm(Y~.,continuous_variable = continuous_variable,data=as.data.frame(data),discmethod = discmethod,discitv = discitv)
out=capture.output(testgdm)
filenameout<-substr(temp[i],1,nchar(temp[i])-5)#提取输出文件名,或者自己重新构建文件名
name=paste(filenameout,".txt",seq="")#设置文件名
write.table(out, file = name, append = F,
quote = T, sep = " ", eol = "\n",
na = "NA", dec = ".", row.names = T,
col.names = T, qmethod = c(),
fileEncoding = "utf-8")
}
有时候长时间运行不出结果,可能需要将method中的sd删掉 或者 修改间隔数。