forked from esdsystems/TecDEM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_auto_basin.m
73 lines (48 loc) · 1.62 KB
/
export_auto_basin.m
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
73
function export_auto_basin(varargin)
try
info = evalin('base','info');
boundary = evalin('base','boundary');
catch
msgbox('No Data to Export','Error')
uiwait
return
end
minlat = [];
maxlat = [];
minlon = [];
maxlon = [];
% R = evalin('base','R');
area_info = evalin('base','area_info');
res1 = area_info.PixelScale(1);
res2 = area_info.PixelScale(2);
y1 = area_info.TiePoints.WorldPoints.Y;
x1 = area_info.TiePoints.WorldPoints.X;
R = makerefmat(x1, y1,res1,-res2);
stream = boundary;
lstr = length(stream);
for i = 1:1:lstr
stream(i).ibr = [stream(i).ibr stream(i).ibr(1)];
stream(i).ibc = [stream(i).ibc stream(i).ibc(1)];
[lo la]=pix2map(R,stream(i).ibr,stream(i).ibc);
% minlat =min(la);
% maxlat =max(la);
% minlon =min(lo);
% maxlon =max(lo);
%
% rivers(i) = struct('Geometry','Line','BoundingBox',[minlon minlat maxlon maxlat],'Lon',lo,'Lat',la,'ID',i,'BOX1',minlon ,'BOX2',minlat ,'BOX3',maxlon ,'BOX4',maxlat);
BBOX = [min(lo) max(la); max(lo) min(la)]';
rivers(i) = struct('Geometry','Polygon','BoundingBox',BBOX,'Lon',lo,'Lat',la, 'ID',i,'BasinNo',i);
% rivers(i) =
% struct('Geometry','Polygon','BoundingBox',BBOX,'Lon',lo,'Lat',la, 'ID',i,'bsn_shp',stream(i).shp,'Hi',stream(i).Hi);
end
assignin('base','rivers',rivers)
[filename, pathname] = uiputfile(strcat(info.path,'*.shp'),'Save as Shape File');
files = strcat(pathname,filename);
if isempty(files)
return
end
shapewrite(rivers,files)
export_prj(strcat(files(1:end-3),'prj'))
% cd(curr_dir)
% google_earth(files);
end