MATLAB-based spatial data global polynomial interpolation method (trend surface method) and inverse distance weighting (IDW) method interpolation and result analysis


  Build on the progress to complete the basic theory of geoscience computing explained (see blog 1 ) and Spatial Data variograms calculated and empirical semivariogram drawing (see blog 2 post) Basic practical operation of the geoscience computing, we will delve into, the actual geoscience computing two important method of interpolation problems: global polynomial interpolation and inverse distance weighting method . About Kriging method, you can see here .
  In order to facilitate everyone's understanding, this article will explain separately from the code part; first, the specific operation process and method will be elaborated, and then all the codes used in this article will be completely attached to the end of this article. Among them, because the data used in this article is not mine, I regret that the data cannot be provided to everyone; but based on the ideas of this blog and the detailed explanation of the code, you can use your own data to perform related operations and analysis The process is fully reproduced.

1 background knowledge

  The acquisition of spatial data is the basis and origin of spatial analysis. We always hope to obtain more and more comprehensive and accurate spatial attribute data information of the research area. However, in actual work, due to cost and resource constraints, it is impossible to measure all unknown areas, and more data can only be obtained from a limited number of sampling points. Therefore, we can consider selecting appropriate spatial sampling points, using a certain mathematical model, and predicting the unknown attribute information of all locations in the study area based on the known sampling point data.
  Spatial Interpolation is a common method for converting discrete point measurement data into continuous data surfaces, including two application forms: Interpolation and Extrapolation. Spatial interpolation is based on the first law of geography, that is, generally, the closer the distance, the higher the correlation.
  At the method level, spatial interpolation can generally be divided into deterministic interpolation method (Deterministic Interpolation) and geostatistics method (Geostatistics). The former creates a fitting surface based on the similarity between the information points or the smoothness of the entire surface, and the latter quantifies the spatial autocorrelation of the information points based on the comprehensive statistical law of the information points, thereby creating an interpolation surface. On the other hand, according to the sampling point distribution range taken into consideration in interpolation calculation, it is divided into overall interpolation method and local interpolation method. The former uses the entire measured sampling point data set to fit the whole area, such as global polynomial interpolation (Global Polynomial Interpolation); the latter only uses the sampling point data in a nearby area to predict the unknown point data, such as reverse (inverse) ) Distance Weighted (Inverse Distance Weighted, IDW). In addition, based on the relationship between the predicted value of the sampling point in the surface of the interpolation result and the measured value, it can be divided into accurate interpolation and inaccurate interpolation.
  With the help of MATLAB software, this paper uses the global polynomial interpolation method and the inverse distance weighting method to calculate the soil pH value , the soil pH value , and the inverse distance weighting method in Shayang County, Jingmen City, Hubei Province .Two kinds of attribute data such as organic matter content are calculated by spatial interpolation, and the fitting effects of corresponding interpolation methods are compared.
  The global polynomial interpolation method is based on the coverage area of ​​all sampling points, and fits a most suitable plane or curved surface by means such as least squares method, so that each sampling point is more evenly distributed in the vicinity of this plane or curved surface, and all of them are high. The absolute value of the sum of the point distances out of the surface and the sum of all the point distances below the surface should be approximate. The global polynomial interpolation method is not suitable for describing the characteristics of areas with large fluctuations in the spatial distribution of attribute data.
  Inverse distance weighting is known to use a range of data points around the point to be interpolated, the data to be interpolated to be interpolated center point; a point closer the distance to be interpolated, the greater the influence of this point, i.e., the larger the corresponding coefficient . The calculation of the weight often depends on the p power of the inverse distance (the reciprocal of the distance). Generally, take p equal to 2. According to the principle of the method, the inverse distance weighting method often leads to the phenomenon of multi-point centers in spatial distribution.

2 actual operation part

2.1 Spatial data read

This article uses the data in the above blog 2 as an example, which includes the spatial location (X and Y, in meters), pH, organic matter content, and total nitrogen content of 658 soil sampling points in Shayang County, Jingmen City, Hubei Province. These data are also stored in the "data.xls" file, and the later operations are mostly implemented based on MATLAB software. Therefore, the source data must be selectively imported into MATLAB software according to specific calculation needs.

2.2 Removal of abnormal data

As mentioned in the above blog, the original sampling point data we obtained may have certain errors in the process of sampling records, laboratory tests, etc., resulting in individual outliers; and the existence of outliers will affect the later spatial interpolation effect (especially local Interpolation method) has a greater impact. Therefore, the "mean plus standard deviation method" is selected to filter and eliminate abnormal data. Please see blog 2 for the specific meaning of this method .
In the above blog, the "2S" and "3S" methods were used to deal with it, and it was found that the "2S" method has better processing effect than the latter. Therefore, this article directly chooses to use the "2S" method to process the results to continue.
After the abnormal value is obtained, it is removed from the original 658 sampling points; the remaining sampling point data continues subsequent operations.

2.3 Validation set screening

Aiming at the accuracy test of the results obtained by different interpolation methods, this article adopts the method of setting training data (Training Data) and test data (Test Data) and comparing them. The data after the above-mentioned anomaly elimination is randomly divided into two parts, of which 80% is used as training data, and the remaining 20% ​​is used as test data (ie, validation set). It should be noted that the test data can only be used to detect the construction effect of the interpolation model, and cannot participate in the model construction process, otherwise the results may be over-fitted (that is, the model has a good interpolation and fitting effect on the data given this time, but The prediction effect of the outer area without data is poor). Since the verification set data is randomly selected, the procedure can be executed multiple times in the later stage to obtain a stable accuracy measurement index.

2.4 Solving by least square method

As the name "Global Polynomial Interpolation" indicates, the principle of this interpolation method is actually to solve the coefficients of a polynomial describing a plane or a curved surface; and this solution process is often realized by the least square method.
Considering the complexity of polynomials, this article limits the polynomial order to second and third order, and compares their interpolation effects. The form of the second-order polynomial is as follows: the form of the
Insert picture description here
third-order polynomial is as follows: In the
Insert picture description here
above two formulas, W(x,y) is the interpolation value of the point (x,y) to be interpolated, x and y are the coordinates, φ is a constant, and the other letters represent each corresponding Term coefficient.
If you use AcrMap and other software to perform trend surface interpolation, you can increase the order appropriately according to the actual situation.

2.5 Inverse distance weighting method

The inverse distance weighting method realizes interpolation through the actual value of each known point and its weight with respect to the point to be interpolated. The formula is as follows:
Insert picture description here
where ω_i is the weight of the i-th known point to be interpolated (x_0, y_0), and d_i0 is two The distance between the persons, n is the number of known points, p is the power parameter, W(x_0,y_0) is the interpolation value of the point to be interpolated (x_0,y_0), Z(x_i,y_i) is the corresponding attribute of the i-th known point Numerical value.
In this article, take the initial p=2, and adjust it appropriately according to the interpolation effect.

2.6 Interpolation accuracy test

As mentioned earlier, this article compares and analyzes the accuracy of the interpolation results through randomly selected test data. Combined with the numerical characteristics of actual spatial data, the final indicators selected to measure the accuracy of interpolation include Mean Error (ME) [1], Mean Absolute Error (MAE), and Root Mean Square Error (Root Mean Square Error). , RMSE) and correlation coefficient (Correlation Coefficient).
Among them, the average error can know the size relationship between the interpolation result and the observed value of the actual measurement point; the average absolute error represents the average value of the absolute error between the spatial interpolation and the observed value of the actual measurement point, which can better reflect the actual situation of the interpolation result error; root mean square Error represents the sample standard deviation of the difference (ie residual) between the interpolation result and the observed value of the measured point; the correlation coefficient (Pearson correlation coefficient is used here) is used to evaluate the linear correlation between the spatial interpolation and the observed value of the measured point.

2.7 Data export and thematic map production

Through the above process, the interpolation result of the corresponding attribute data is obtained. First, draw a three-dimensional map of the interpolation result in MATLAB, then save the interpolation result data variable as an ASCII data format file, and import it into the AcrMap software to draw the thematic map.
Among them, after the data is exported to ".txt" format by MATLAB, the following information needs to be added at the beginning of the data:

ncols 1275
nrows 1209
xllcorner 600800
yllcorner 3364600
cellsize 50
NODATA_value -9999

Among them, the corresponding values ​​of ncols and nrows respectively represent the number of columns and rows of the interpolation result, the corresponding values ​​of xllcorner and yllcorner respectively represent the minimum values ​​of the x and y coordinates of the interpolation results (ie, the starting value), and the corresponding value of cellsize represents the pixel size.

3 Results presentation and analysis

Through the average error, average absolute error, root mean square error, correlation coefficient and other four precision measurement indicators, as well as the corresponding trend surface formula and three-dimensional interpolation result graph, the results obtained by different spatial interpolation methods are compared and analyzed as follows, and the thematic map is drawn.

3.1 Comparison of second-order and third-order interpolation of global polynomial interpolation

Using the least square method, the coefficients of the second-order polynomial and the third-order polynomial are solved respectively, and the global polynomial interpolation results of the two spatial attribute data such as pH value and organic matter content and various accuracy indicators are obtained. For polynomials of different orders, six interpolation operations are performed respectively, and the average value is calculated. The results obtained are shown in Table 1 to Table 6, respectively.
Insert picture description hereInsert picture description here
It can be seen from Table 1 to Table 3 that for the global polynomial interpolation method of pH value, the average error of the interpolation results obtained by the second and third order polynomials is negative, that is, the two methods tend to obtain higher interpolation results than the observed value; The average error value obtained by the latter is smaller than the former (that is, the absolute value of the latter indicator is smaller). The second-order and third-order polynomial interpolation results correspond to the average absolute error and the root mean square error. However, the latter two indicators are also smaller than the former. The third-order polynomial correlation coefficient is also slightly larger than the second-order polynomial. In summary, the pH-oriented global polynomial interpolation method has better interpolation effects using third-order polynomials than using second-order polynomials, and the results are in terms of average error, average absolute error, root mean square error, and The correlation coefficient and other four accuracy measurement indicators are all reflected.
It can be seen from Table 4 to Table 6 that for the global polynomial interpolation method for organic matter content, the average error of the interpolation results obtained by the second and third order polynomials is positive, that is, the two methods tend to obtain interpolation results lower than the observed value ; The latter has a larger average error value than the former. The average absolute error of the second-order and third-order polynomial interpolation results is not much different, but the above index values ​​of the latter are also slightly larger than the former. The root mean square error of the second-order polynomial is lower than that of the third-order polynomial, and there is a significant gap between the two indicators. The third-order polynomial correlation coefficient is also slightly smaller than the second-order polynomial. In summary, the global polynomial interpolation method for organic matter content has little difference between the interpolation effect of the second-order polynomial and the interpolation effect of the third-order polynomial. The second-order polynomial interpolation results are in the average error, average absolute error and correlation The coefficient and other three accuracy measures are slightly better than the third-order polynomial, and the third-order polynomial interpolation result performs well in the root mean square error index. Taking into account the randomness of the selection of different test data, it is believed that the above-mentioned closer result does not particularly show the better choice of interpolation method of the two.
From Table 1 to Table 6, it can be seen that for the global polynomial interpolation method, the choice of polynomial order is not necessarily the higher the better, but it needs to be tried and selected based on the actual data situation. In addition to increasing the amount of calculation and prolonging the execution time of a higher order, the accuracy of the interpolation result may not increase, or even show a downward trend in some indicators.

3.2 Global polynomial interpolation function and its three-dimensional result graph

In summary, the second-order polynomial and the third-order polynomial are used to obtain the trend surface function corresponding to the global polynomial interpolation method.
The second-order and third-order global polynomial interpolation trend surface functions for pH value are as follows:
Insert picture description here
Among them, the above-mentioned second-order and third-order trend surface functions respectively correspond to the accuracy measurement indicators as shown in Table 7.
Insert picture description here
The above-mentioned second-order and third-order trend surface functions respectively correspond to the three-dimensional interpolation results as follows.
Insert picture description here
Insert picture description here

The second-order and third-order global polynomial interpolation trend surface functions for organic matter content are as follows:

Insert picture description here
Among them, the above-mentioned second-order and third-order trend surface functions respectively correspond to each accuracy measurement index as shown in Table 8.
Insert picture description here
The above-mentioned second-order and third-order trend surface functions respectively correspond to the three-dimensional interpolation results as follows.
Insert picture description here
Insert picture description here

3.3 Thematic mapping of global polynomial interpolation

Through the relevant methods in the previous part of this article, the MATLAB interpolation data result file is imported into ArcMap, and after tailoring, a global polynomial interpolation thematic map of soil pH and organic matter content in Shayang County, Jingmen City, Hubei Province is made. Among them, the specific production method of thematic map will not be repeated here. You can refer to the method in this blog .
Insert picture description here
Insert picture description here
Insert picture description here

The thematic map is shown below.
Insert picture description here
Insert picture description here

Insert picture description here

Insert picture description here
It can be seen from the above four thematic maps that the results obtained by third-order polynomial interpolation generally have a wider range of values ​​than second-order polynomials. For example, the maximum result in the second-order pH value interpolation map is 8.99, while the third-order interpolation can reach 10.34; the same , The minimum result in the second-order organic matter content interpolation map is 8.91, while the third-order interpolation can be as low as 5.53. In response to this phenomenon, I personally think that it may be because the third-order polynomial interpolation has a greater degree of curvature than the second-order polynomial interpolation, and the smoothing effect is less obvious than that of the second-order polynomial, so the range of values ​​it can reach is also larger.
On the other hand, from the perspective of thematic map, it can be found that the pH value and the distribution of organic matter content have a certain spatial relationship: areas with higher pH values ​​tend to have lower organic matter content (mainly concentrated in the eastern part of Shayang County); on the contrary, The organic matter content tends to be relatively high (mainly concentrated in the central and western regions of Shayang County). And this result is also in line with the conclusion that "soil organic matter and pH have a high negative correlation" [2].

3.4 Interpolation result of inverse distance weighting method and its three-dimensional result graph

According to the aforementioned method in this paper, take the initial p=2 and adjust it appropriately according to the interpolation effect. Repeat the inverse distance weighting method several times to obtain the interpolation results of the two spatial attribute data such as pH value and organic matter content and various accuracy indicators. The results are shown in Table 9.
Insert picture description here
It can be seen from Table 9 that the interpolation effect of the inverse distance weighting method for pH value and organic matter content is not particularly satisfactory in the above four accuracy measures. Compared with the aforementioned global polynomial interpolation method (including second-order and third-order), the error is slightly Big. In particular, the root mean square error of the results of the inverse distance weighting method for organic matter content has an average value of about 5.10, indicating the sample standard deviation of the difference (ie residual) between the organic matter content interpolation results of each IDW method and the observed value at the measured point Larger. In addition, the average correlation coefficient of the inverse distance weighted organic matter content interpolation results is not higher than 0.50, that is, the average value of R^2 will be lower than 0.25. Compared with the organic matter content, the accuracy of the pH value interpolation results are slightly better overall; it can be seen that the overall accuracy of the pH value inverse distance weighting method interpolation effect is better than that of the organic matter content; and this may be related to the two The internal spatial correlation, numerical value, and distribution characteristics of each attribute data are related. From the overall accuracy measurement index, the effect of the inverse distance weighting method implemented by programming is slightly worse than that of the global polynomial interpolation method.
On the other hand, in the process of implementing the inverse distance weighting method for multiple times, it is found that the accuracy of each execution effect varies greatly; especially the organic matter content, sometimes the above accuracy indicators can reach a good level, and sometimes they are more accurate. Poor, such as the root-mean-square error can even reach about 8 sometimes. From this or it can be seen that the inverse distance weighting method is a local interpolation method, and its execution effect is greatly affected by the selection of training data and test data.
The three-dimensional interpolation results of the inverse distance weighting method for pH value and organic matter content are shown in the following two figures respectively.
Insert picture description here
Insert picture description here

3.5 Thematic mapping with inverse distance weighting method

Through the relevant methods in the previous part of this article, the MATLAB interpolation data result file is imported into ArcMap, and after tailoring, the inverse distance weighted interpolation thematic map of soil pH and organic matter content in Shayang County, Jingmen City, Hubei Province is made.
Insert picture description here
Insert picture description here
It can be seen from the above two thematic maps that the interpolation results obtained by the inverse distance weighting method are more numerous and greater in surface fluctuations than the global polynomial interpolation method, and the range affected by the fluctuations is smaller; and as mentioned above , The interpolation result obtained by the inverse distance weighting method has a relatively small central distribution area, that is, the attribute data features including the distribution of several bubble-shaped small points can be seen in the interpolation thematic map. In addition, the distribution characteristics of pH value and organic matter content and the spatial relationship between the two are still the same as the result of global polynomial interpolation, that is, the data sizes of the two are in the opposite state, and the pH value of the central and western parts of Shayang County is relatively low. While the organic matter content is higher, the pH value of the eastern region is relatively high and the organic matter content is lower.
At the same time, as mentioned in the first part of this article, since the inverse distance weighting method is a local interpolation method, the interpolation result of each point to be interpolated is largely affected by the value of its neighboring points; therefore, the above spatial distribution characteristics are only its There will be some exceptions to the overall trend of the results. For example, combining the above two thematic maps, it can be seen that the pH value interpolation result obtained by the inverse distance weighting method also has some local maximum points in the western part of Shayang County, and the values ​​of these maximum points are even the same as the eastern part; At the same time, the organic matter content interpolation results also have scattered local minimum points in the central and western parts of Shayang County.

4 Complete code

4.1 MATLAB code for global polynomial interpolation

%% 文件信息读入
clc;clear;
info=xlsread('data.xls');
opoX=info(:,1);
opoY=info(:,2);
oPH=info(:,3);
% oOM=info(:,4);
% oTN=info(:,5);
%% 2S法计算异常值
mPH=mean(oPH);
sPH=std(oPH);
num2=find(oPH>(mPH+2*sPH)|oPH<(mPH-2*sPH));
%% 异常值剔除
PH=oPH;
for i=1:length(num2)
    n=num2(i,1);
    PH(n,:)=[0];
end
PH(all(PH==0,2),:)=[];
poX=opoX;
for i=1:length(num2)
    n=num2(i,1);
    poX(n,:)=[0];
end
poX(all(poX==0,2),:)=[];
poY=opoY;
for i=1:length(num2)
    n=num2(i,1);
    poY(n,:)=[0];
end
poY(all(poY==0,2),:)=[];
%% 验证集筛选
very=[randperm(length(PH),floor(length(PH)*0.2))]';
%% 验证集剔除
cPH=PH;
vPH=zeros(length(very),1);
vpoX=vPH;
vpoY=vPH;
for i=1:length(very)
    m=very(i,1);
    vPH(i,:)=cPH(m,:);
    cPH(m,:)=[0];
end
cPH(all(cPH==0,2),:)=[];
cpoX=poX;
for i=1:length(very)
    m=very(i,1);
    vpoX(i,:)=cpoX(m,:);
    cpoX(m,:)=[0];
end
cpoX(all(cpoX==0,2),:)=[];
cpoY=poY;
for i=1:length(very)
    m=very(i,1);
    vpoY(i,:)=cpoY(m,:);
    cpoY(m,:)=[0];
end
cpoY(all(cpoY==0,2),:)=[];
%% 最小二乘法求解预处理
inva2=[ones(size(cpoX)),cpoX.^2,cpoY.^2,cpoX.*cpoY,cpoX,cpoY];
inva3=[ones(size(cpoX)),cpoX.^3,cpoY.^3,(cpoX.^2).*cpoY,cpoX.*(cpoY.^2),cpoX.^2,cpoY.^2,cpoX.*cpoY,cpoX,cpoY];
%% 最小二乘法求解
[coef2,bint2,r2,rint2,stats2]=regress(cPH,inva2);
[coef3,bint3,r3,rint3,stats3]=regress(cPH,inva3);
%% 趋势面法效果图绘制准备
step=50;
npoX=600800:step:664500;
npoY=3364600:step:3425000;
[mnpX,mnpY]=meshgrid(npoX,npoY);
%% 趋势面法插值
pPH2=coef2(1,:)+coef2(2,:)*mnpX.^2+coef2(3,:)*mnpY.^2+coef2(4,:)*mnpX.*mnpY+coef2(5,:)*mnpX+coef2(6,:)*mnpY;
pPH3=coef3(1,:)+coef3(2,:)*mnpX.^3+coef3(3,:)*mnpY.^3+coef3(4,:)*(mnpX.^2).*mnpY+coef3(5,:)*mnpX.*(mnpY.^2)+coef3(6,:)*mnpX.^2+coef3(7,:)*mnpY.^2+coef3(8,:)*mnpX.*mnpY+coef3(9,:)*mnpX+coef3(10,:)*mnpY;
%% 趋势面法效果图绘制
scatter3(cpoX,cpoY,cPH);
hold on;
mesh(mnpX,mnpY,pPH2);
title('Global Polynomial Interpolation Results of Quadratic of Organic Matter');
figure();
scatter3(cpoX,cpoY,cPH);
hold on;
mesh(mnpX,mnpY,pPH3);
title('Global Polynomial Interpolation Results of Cubic of Organic Matter');
%% 趋势面法精度对比
vpPH2=coef2(1,:)+coef2(2,:)*vpoX.^2+coef2(3,:)*vpoY.^2+coef2(4,:)*vpoX.*vpoY+coef2(5,:)*vpoX+coef2(6,:)*vpoY;
MEERan2=mean(vPH-vpPH2);
MEERan21=mean(abs(vpPH2-vPH));
RMSEan2=sqrt(sum(vpPH2-vPH).^2/length(vPH));
COCOan2=corrcoef(vpPH2,vPH);
vpPH3=coef3(1,:)+coef3(2,:)*vpoX.^3+coef3(3,:)*vpoY.^3+coef3(4,:)*(vpoX.^2).*vpoY+coef3(5,:)*vpoX.*(vpoY.^2)+coef3(6,:)*vpoX.^2+coef3(7,:)*vpoY.^2+coef3(8,:)*vpoX.*vpoY+coef3(9,:)*vpoX+coef3(10,:)*vpoY;
MEERan3=mean(vPH-vpPH3);
MEERan31=mean(abs(vpPH3-vPH));
RMSEan3=sqrt(sum(vpPH3-vPH).^2/length(vPH));
COCOan3=corrcoef(vpPH3,vPH);
%% 趋势面法导出ASCII
save 3.txt pPH2 -ASCII;
save 4.txt pPH3 -ASCII;

4.2 Inverse distance weighting method MATLAB code

%% 文件信息读入
clc;clear;
info=xlsread('data.xls');
opoX=info(:,1);
opoY=info(:,2);
oPH=info(:,3);
power=2;
% oOM=info(:,4);
% oTN=info(:,5);
%% 2S法计算异常值
mPH=mean(oPH);
sPH=std(oPH);
num2=find(oPH>(mPH+2*sPH)|oPH<(mPH-2*sPH));
%% 异常值剔除
PH=oPH;
for i=1:length(num2)
    n=num2(i,1);
    PH(n,:)=[0];
end
PH(all(PH==0,2),:)=[];
poX=opoX;
for i=1:length(num2)
    n=num2(i,1);
    poX(n,:)=[0];
end
poX(all(poX==0,2),:)=[];
poY=opoY;
for i=1:length(num2)
    n=num2(i,1);
    poY(n,:)=[0];
end
poY(all(poY==0,2),:)=[];
%% 验证集筛选
very=[randperm(length(PH),floor(length(PH)*0.2))]';
%% 验证集剔除
cPH=PH;
vPH=zeros(length(very),1);
vpoX=vPH;
vpoY=vPH;
for i=1:length(very)
    m=very(i,1);
    vPH(i,:)=cPH(m,:);
    cPH(m,:)=[0];
end
cPH(all(cPH==0,2),:)=[];
cpoX=poX;
for i=1:length(very)
    m=very(i,1);
    vpoX(i,:)=cpoX(m,:);
    cpoX(m,:)=[0];
end
cpoX(all(cpoX==0,2),:)=[];
cpoY=poY;
for i=1:length(very)
    m=very(i,1);
    vpoY(i,:)=cpoY(m,:);
    cpoY(m,:)=[0];
end
cpoY(all(cpoY==0,2),:)=[];
%% IDW效果图绘制准备
step=50;
npoX=600800:step:664500;
npoY=3364600:step:3425000;
[mnpX,mnpY]=meshgrid(npoX,npoY);
%% IDW分母计算
temdeno=zeros(1,length(cPH));
deno=zeros(length(npoY),length(npoX));
for p=1:length(npoY)
    for q=1:length(npoX)
        for i=1:length(cPH)
            temdeno(1,i)=(sqrt((npoY(1,p)-cpoY(i,1))^2+(npoX(1,q)-cpoX(i,1))^2))^(-power);
        end
        deno(p,q)=sum(temdeno(:));
    end
end
%% IDW求解
temPH=zeros(1,length(cPH));
pPH4=zeros(length(npoY),length(npoX));
for p=1:length(npoY)
    for q=1:length(npoX)
        for i=1:length(cPH)
            temPH(1,i)=cPH(i,1).*((sqrt((npoY(1,p)-cpoY(i,1))^2+(npoX(1,q)-cpoX(i,1))^2))^(-power))./deno(p,q);
        end
        pPH4(p,q)=sum(temPH(:));
    end
end
%% IDW效果图绘制
scatter3(cpoX,cpoY,cPH);
hold on;
mesh(mnpX,mnpY,pPH4);
title('IDW Results of Organic Matter');
%% IDW验证1
temdeno4=zeros(1,length(cPH));
deno4=zeros(length(vpoY),length(vpoX));
for p=1:length(vpoY)
    for q=1:length(vpoX)
        for i=1:length(cPH)
            temdeno4(1,i)=(sqrt((vpoY(p,1)-cpoY(i,1))^2+(vpoX(q,1)-cpoX(i,1))^2))^(-power);
        end
        deno4(p,q)=sum(temdeno4(:));
    end
end
%% IDW验证2
temPH4=zeros(1,length(cPH));
vpPH4=zeros(length(vpoY),1);
for p=1:length(vpoY)
    for i=1:length(cPH)
        temPH4(1,i)=cPH(i,1).*((sqrt((vpoY(p,1)-cpoY(i,1))^2+(vpoX(q,1)-cpoX(i,1))^2))^(-power))./deno4(p,q);
    end
    vpPH4(p,1)=sum(temPH4(:));
end
%% 精度计算
MEERan4=mean(vPH-vpPH4);
MEERan41=mean(abs(vpPH4-vPH));
RMSEan4=sqrt(sum(vpPH4-vPH).^2/length(vPH));
COCOan4=corrcoef(vpPH4,(vPH)');
%% 文件转存
save 5ph.txt pPH4 -ASCII;

references

[1] Cao Xianghui, Long Huaiyu, Zhou Jiaogen, et al. Spatial variability characteristics and influencing factors of surface soil organic carbon and total nitrogen in Hebei Province[J]. Journal of Plant Nutrition and Fertilizer, 2016, 22(04): 937- 948.
[2] Dai Wanhong, Huang Yao, Wu Li, Yu Jia. The relationship between organic matter content and pH in zonal soils in China[J]. Acta Pedologica Sinica,2009,46(05):851-860.

Welcome to pay attention to the public account: crazy learning GIS
Insert picture description here

Guess you like

Origin blog.csdn.net/zhebushibiaoshifu/article/details/114037153