fclose all
clear all
clc
tree_num={'tree1','tree2','tree3','tree4'};
tree_lat=[22.683822,22.683831,22.683843, 22.683928];
tree_lon=[108.856422,108.856401,108.856416,108.856362];
species=['桉樹','松樹','桉樹','松樹'];
tree_height=[15,10,15,9];
crown_diameter=[12.500000,9.900000,13.100000,7.300000];
for i=1:length(tree_num)
P(i).Geometry='Point';
P(i).X = tree_lat(i);%座標X
P(i).Y = tree_lon(i);%座標Y
P(i).tree_id =cell2mat(tree_num(i)); % 結構體輸入不要是元胞
P(i).lat=tree_lat(i);
P(i).lon=tree_lon(i);
P(i).height=tree_height(i);
P(i).crown_diameter=crown_diameter(i);
end
% 生成英文欄位名
shapewrite(P, 'D:\test.shp');
%新增座標系資訊
fid1 = fopen('D:\test.prj','w');
prj_WGS84 = ['GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",','SPHEROID["WGS_1984",6378137.0,298.257223563]],','PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]'];
fprintf(fid1,'%s\n',prj_WGS84);
fclose(fid1);