1 | %BOUNDARY class definition
|
---|
2 | %
|
---|
3 | % Usage:
|
---|
4 | % boundary=boundary();
|
---|
5 |
|
---|
6 | classdef boundary
|
---|
7 | properties (SetAccess=public)
|
---|
8 | shppath = '';
|
---|
9 | shpfilename = '';
|
---|
10 | orientation = 'normal'; %other value is 'reverse'
|
---|
11 | epsg = 4326; %EPSG number, default value is WGS 84 Lat,Long reference frame.
|
---|
12 | end
|
---|
13 | methods (Static)
|
---|
14 | function self = loadobj(self) % {{{
|
---|
15 | % This function is directly called by matlab when a model object is
|
---|
16 | % loaded. Update old properties here
|
---|
17 | end% }}}
|
---|
18 | end
|
---|
19 | methods
|
---|
20 | function self = boundary(varargin) % {{{
|
---|
21 | switch nargin
|
---|
22 | case 0
|
---|
23 | self=setdefaultparameters(self);
|
---|
24 | otherwise
|
---|
25 | self=setdefaultparameters(self);
|
---|
26 | options=pairoptions(varargin{:});
|
---|
27 |
|
---|
28 | %recover field values:
|
---|
29 | self.shppath=getfieldvalue(options,'shppath','');
|
---|
30 | self.shpfilename=getfieldvalue(options,'shpfilename','');
|
---|
31 | self.orientation=getfieldvalue(options,'orientation','normal');
|
---|
32 | self.epsg=getfieldvalue(options,'epsg',4326);
|
---|
33 | end
|
---|
34 | end % }}}
|
---|
35 | function self = setdefaultparameters(self) % {{{
|
---|
36 | self.shppath='';
|
---|
37 | self.shpfilename='';
|
---|
38 | self.orientation='normal';
|
---|
39 | self.epsg=4326;
|
---|
40 | end % }}}
|
---|
41 | function disp(self) % {{{
|
---|
42 | disp(sprintf(' boundary parameters:'));
|
---|
43 |
|
---|
44 | fielddisplay(self,'shppath','path to filename for this boundary');
|
---|
45 | fielddisplay(self,'shpfilename','shape file name');
|
---|
46 | fielddisplay(self,'orientation','orientation (default is ''normal'', can be ''reverse'')');
|
---|
47 | fielddisplay(self,'epsg','EPSG number defining projection for the shape file');
|
---|
48 |
|
---|
49 | end % }}}
|
---|
50 | function output=name(self) % {{{
|
---|
51 | output=self.shpfilename;
|
---|
52 | end % }}}
|
---|
53 | function output=edges(self) % {{{
|
---|
54 |
|
---|
55 | %read domain:
|
---|
56 | [path,name,ext]=fileparts(self.shpfilename);
|
---|
57 | if ~strcmpi(ext,'shp'),
|
---|
58 | ext='shp';
|
---|
59 | end
|
---|
60 | output=shpread([self.shppath '/' name '.' ext]);
|
---|
61 |
|
---|
62 | %do we reverse?
|
---|
63 | if strcmpi(self.orientation,'reverse'),
|
---|
64 | output.x=flipud(output.x);
|
---|
65 | output.y=flipud(output.y);
|
---|
66 | end
|
---|
67 | end % }}}
|
---|
68 | function plot(self,varargin) % {{{
|
---|
69 | %recover options
|
---|
70 |
|
---|
71 | options=pairoptions(varargin{:});
|
---|
72 |
|
---|
73 | %parse input:
|
---|
74 | figurenumber=getfieldvalue(options,'figure',1);
|
---|
75 | color=getfieldvalue(options,'color','r');
|
---|
76 | linewidth=getfieldvalue(options,'linewidth',1);
|
---|
77 | markersize=getfieldvalue(options,'markersize',1);
|
---|
78 | unitmultiplier=getfieldvalue(options,'unit',1);
|
---|
79 | epsg=getfieldvalue(options,'epsg',4326);
|
---|
80 | radius=getfieldvalue(options,'radius',6371012);
|
---|
81 | aboveground=getfieldvalue(options,'aboveground',1000);
|
---|
82 | offset=getfieldvalue(options,'offset',.1);
|
---|
83 | fontsize=getfieldvalue(options,'fontsize',10);
|
---|
84 |
|
---|
85 | %read domain:
|
---|
86 | [path,name,ext]=fileparts(self.shpfilename);
|
---|
87 | if ~strcmpi(ext,'shp'),
|
---|
88 | ext='shp';
|
---|
89 | end
|
---|
90 | domain=shpread([self.shppath '/' name '.' ext]);
|
---|
91 |
|
---|
92 | %convert boundary to another reference frame: {{{
|
---|
93 |
|
---|
94 | for i=1:length(domain),
|
---|
95 | try,
|
---|
96 | [x,y] = gdaltransform(domain(i).x,domain(i).y,sprintf('EPSG:%i',self.epsg),sprintf('EPSG:%i',epsg));
|
---|
97 | catch me
|
---|
98 | disp(me.message());
|
---|
99 | self.disp();
|
---|
100 | end
|
---|
101 | domain(i).x=x; domain(i).y=y;
|
---|
102 | end
|
---|
103 |
|
---|
104 | for i=1:length(domain),
|
---|
105 | hold on;
|
---|
106 | if length(x)==1,
|
---|
107 | p=plot(x,y,'k*');
|
---|
108 | set(p,'MarkerSize',markersize);
|
---|
109 | t=text(x,y,self.shpfilename,'FontSize',fontsize);
|
---|
110 | else
|
---|
111 | p=plot(x,y,'k-');
|
---|
112 | text(sum(x)/length(x),sum(y)/length(y),self.shpfilename,'FontSize',fontsize);
|
---|
113 | end
|
---|
114 | set(p,'Color',color);
|
---|
115 | set(p,'LineWidth',linewidth);
|
---|
116 | end
|
---|
117 | %}}}
|
---|
118 | end % }}}
|
---|
119 | function plot3d(self,varargin) % {{{
|
---|
120 | %recover options
|
---|
121 |
|
---|
122 | options=pairoptions(varargin{:});
|
---|
123 |
|
---|
124 | %parse input:
|
---|
125 | figurenumber=getfieldvalue(options,'figure',1);
|
---|
126 | color=getfieldvalue(options,'color','r');
|
---|
127 | linewidth=getfieldvalue(options,'linewidth',1);
|
---|
128 | markersize=getfieldvalue(options,'markersize',1);
|
---|
129 | unitmultiplier=getfieldvalue(options,'unit',1);
|
---|
130 | epsg=getfieldvalue(options,'epsg',4326);
|
---|
131 | radius=getfieldvalue(options,'radius',6371012);
|
---|
132 | aboveground=getfieldvalue(options,'aboveground',1000);
|
---|
133 | offset=getfieldvalue(options,'offset',.1);
|
---|
134 | fontsize=getfieldvalue(options,'fontsize',10);
|
---|
135 |
|
---|
136 | %read domain:
|
---|
137 | [path,name,ext]=fileparts(self.shpfilename);
|
---|
138 | if ~strcmpi(ext,'shp'),
|
---|
139 | ext='shp';
|
---|
140 | end
|
---|
141 | domain=shpread([self.shppath '/' name '.' ext]);
|
---|
142 |
|
---|
143 | if epsg==4326,
|
---|
144 | %convert boundary to lat,long: {{{
|
---|
145 |
|
---|
146 | for i=1:length(domain),
|
---|
147 | try,
|
---|
148 | [lat,long] = gdaltransform(domain(i).x,domain(i).y,sprintf('EPSG:%i',self.epsg),'EPSG:4326');
|
---|
149 | catch me
|
---|
150 | disp(me.message());
|
---|
151 | self.disp();
|
---|
152 | end
|
---|
153 | domain(i).x=long; domain(i).y=lat;
|
---|
154 | end
|
---|
155 |
|
---|
156 | for i=1:length(domain),
|
---|
157 |
|
---|
158 | %make sure lat,long are what they are supposed to be:
|
---|
159 | %if any(domain(i).x>90 | domain(i).x<-90),
|
---|
160 | % long=domain(i).x; lat=domain(i).y;
|
---|
161 | %else
|
---|
162 | % long=domain(i).y; lat=domain(i).x;
|
---|
163 | %end
|
---|
164 |
|
---|
165 | %project on x,y,z reference frame.
|
---|
166 | [x,y,z]=AboveGround(domain(i).x,domain(i).y,radius,aboveground);
|
---|
167 | [xt,yt,zt]=AboveGround(domain(i).x+offset,domain(i).y+offset,radius,300000);
|
---|
168 | hold on;
|
---|
169 | if length(x)==1,
|
---|
170 | p=plot3(x,y,z,'k*');
|
---|
171 | set(p,'MarkerSize',markersize);
|
---|
172 | t=text(xt,yt,zt,self.shpfilename,'FontSize',fontsize);
|
---|
173 | else
|
---|
174 | p=plot3(x,y,z,'k-');
|
---|
175 | mid=floor(length(xt)/2);
|
---|
176 | text(xt(mid),yt(mid),zt(mid),self.shpfilename,'FontSize',fontsize);
|
---|
177 | end
|
---|
178 | set(p,'Color',color);
|
---|
179 | set(p,'LineWidth',linewidth);
|
---|
180 |
|
---|
181 | end
|
---|
182 | %}}}
|
---|
183 | else
|
---|
184 | %convert boundary to another reference frame: {{{
|
---|
185 |
|
---|
186 | for i=1:length(domain),
|
---|
187 | try,
|
---|
188 | [x,y] = gdaltransform(domain(i).x,domain(i).y,sprintf('EPSG:%i',self.epsg),sprintf('EPSG:%i',epsg));
|
---|
189 | catch me
|
---|
190 | disp(me.message());
|
---|
191 | self.disp();
|
---|
192 | end
|
---|
193 | domain(i).x=x; domain(i).y=y;
|
---|
194 | end
|
---|
195 |
|
---|
196 | for i=1:length(domain),
|
---|
197 | hold on;
|
---|
198 | if length(x)==1,
|
---|
199 | p=plot(x,y,'k*');
|
---|
200 | set(p,'MarkerSize',markersize);
|
---|
201 | t=text(x,y,self.shpfilename,'FontSize',fontsize);
|
---|
202 | else
|
---|
203 | p=plot(x,y,'k-');
|
---|
204 | text(sum(x)/length(x),sum(y)/length(y),self.shpfilename,'FontSize',fontsize);
|
---|
205 | end
|
---|
206 | set(p,'Color',color);
|
---|
207 | set(p,'LineWidth',linewidth);
|
---|
208 | end
|
---|
209 | %}}}
|
---|
210 | end
|
---|
211 | end % }}}
|
---|
212 | end
|
---|
213 | end
|
---|