1 | %
|
---|
2 | % definition for the kml_feature super (base) and sub (derived) abstract class.
|
---|
3 | %
|
---|
4 | % [kml]=kml_feature(varargin)
|
---|
5 | %
|
---|
6 | % where the optional varargin and defaults are:
|
---|
7 | % id (char, feature id, '')
|
---|
8 | % name (char, name, '')
|
---|
9 | % visibility (logical, visibility, true)
|
---|
10 | % open (logical, open, false)
|
---|
11 | % snippet (char, snippet, '')
|
---|
12 | % descript (char, description, '')
|
---|
13 | % styleurl (char, style url, '')
|
---|
14 | % style (cell array, styles)
|
---|
15 | %
|
---|
16 | % note that zero arguments constructs a default instance; one
|
---|
17 | % argument of the class copies the instance; and two or more
|
---|
18 | % arguments constructs a new instance from the arguments.
|
---|
19 | %
|
---|
20 | classdef kml_feature < kml_object
|
---|
21 | properties
|
---|
22 | name ='';
|
---|
23 | visibility=true;
|
---|
24 | open =false;
|
---|
25 | snippet ='';
|
---|
26 | descript ='';
|
---|
27 | styleurl ='';
|
---|
28 | style ={};
|
---|
29 | end
|
---|
30 |
|
---|
31 | methods
|
---|
32 | function [kml]=kml_feature(varargin)
|
---|
33 |
|
---|
34 | kml=kml@kml_object(varargin{:});
|
---|
35 |
|
---|
36 | switch nargin
|
---|
37 |
|
---|
38 | % create a default object
|
---|
39 |
|
---|
40 | case 0
|
---|
41 |
|
---|
42 | % copy the object or create the object from the input
|
---|
43 |
|
---|
44 | otherwise
|
---|
45 | if (nargin == 1) && isa(varargin{1},class(kml))
|
---|
46 | kml=varargin{1};
|
---|
47 |
|
---|
48 | else
|
---|
49 | fnames=fieldnames(kml_feature());
|
---|
50 |
|
---|
51 | for i=length(fieldnames(kml_object()))+1:min(nargin,length(fnames))
|
---|
52 | if isa(varargin{i},class(kml.(fnames{i})))
|
---|
53 | if ~isempty(varargin{i})
|
---|
54 | kml.(fnames{i})=varargin{i};
|
---|
55 | end
|
---|
56 | else
|
---|
57 | if ~isempty(inputname(i))
|
---|
58 | warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
59 | inputname(i),fnames{i},class(varargin{i}),class(kml.(fnames{i})));
|
---|
60 | else
|
---|
61 | warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
62 | i ,fnames{i},class(varargin{i}),class(kml.(fnames{i})));
|
---|
63 | end
|
---|
64 | end
|
---|
65 | end
|
---|
66 | end
|
---|
67 |
|
---|
68 | end
|
---|
69 |
|
---|
70 | end
|
---|
71 |
|
---|
72 | % display the object
|
---|
73 |
|
---|
74 | function []=disp(kml)
|
---|
75 |
|
---|
76 | for i=1:numel(kml)
|
---|
77 | if strcmp(class(kml),'kml_feature')
|
---|
78 | disp(sprintf('class ''%s'' object ''%s%s'' = \n',...
|
---|
79 | class(kml),inputname(1),string_dim(kml,i)));
|
---|
80 | end
|
---|
81 | disp@kml_object(kml(i));
|
---|
82 | disp(sprintf(' name: ''%s''' ,kml(i).name));
|
---|
83 | disp(sprintf(' visibility: %g' ,kml(i).visibility));
|
---|
84 | disp(sprintf(' open: %g' ,kml(i).open));
|
---|
85 | disp(sprintf(' snippet: ''%s''' ,kml(i).snippet));
|
---|
86 | disp(sprintf(' descript: ''%s''' ,kml(i).descript));
|
---|
87 | disp(sprintf(' styleurl: ''%s''' ,kml(i).styleurl));
|
---|
88 | if strcmp(class(kml),'kml_feature')
|
---|
89 | disp(sprintf(' style: %s %s\n' ,string_size(kml(i).style),...
|
---|
90 | class(kml(i).style)));
|
---|
91 | else
|
---|
92 | disp(sprintf(' style: %s %s' ,string_size(kml(i).style),...
|
---|
93 | class(kml(i).style)));
|
---|
94 | end
|
---|
95 | end
|
---|
96 |
|
---|
97 | end
|
---|
98 |
|
---|
99 | % return the fieldnames of the object
|
---|
100 |
|
---|
101 | function [fnames]=fieldnames(kml)
|
---|
102 |
|
---|
103 | % fieldnames for a sub (derived) class list those before super (base)
|
---|
104 |
|
---|
105 | fnames=fieldnames(kml_object());
|
---|
106 | fnames={fnames{:} ...
|
---|
107 | 'name' ...
|
---|
108 | 'visibility' ...
|
---|
109 | 'open' ...
|
---|
110 | 'snippet' ...
|
---|
111 | 'descript' ...
|
---|
112 | 'styleurl' ...
|
---|
113 | 'style' ...
|
---|
114 | }';
|
---|
115 |
|
---|
116 | end
|
---|
117 |
|
---|
118 | % set the properties of the object
|
---|
119 |
|
---|
120 | function [kml]=setprops(kml,varargin)
|
---|
121 |
|
---|
122 | kmlref=feval(class(kml));
|
---|
123 | fnames=fieldnames(kmlref);
|
---|
124 |
|
---|
125 | % loop through each parameter in the input list (comparing to the reference
|
---|
126 | % object in case property types have been changed)
|
---|
127 |
|
---|
128 | for i=1:2:length(varargin)
|
---|
129 | if ismember(varargin{i},fnames) && (i+1 <= length(varargin))
|
---|
130 | if isa(varargin{i+1},class(kmlref.(varargin{i})))
|
---|
131 | kml.(varargin{i})=varargin{i+1};
|
---|
132 | else
|
---|
133 | if ~isempty(inputname(i+1))
|
---|
134 | warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
135 | inputname(i+2),varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
---|
136 | else
|
---|
137 | warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
138 | i+2 ,varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
---|
139 | end
|
---|
140 | end
|
---|
141 | else
|
---|
142 | warning('Property ''%s'' for class ''%s'' does not exist.',...
|
---|
143 | varargin{i},class(kmlref));
|
---|
144 | end
|
---|
145 | end
|
---|
146 |
|
---|
147 | end
|
---|
148 |
|
---|
149 | % write the object
|
---|
150 |
|
---|
151 | function []=kml_write(kml,fid,indent)
|
---|
152 |
|
---|
153 | if ~exist('fid','var') || isempty(fid)
|
---|
154 | fid=1;
|
---|
155 | end
|
---|
156 | if ~exist('indent','var') || isempty(indent)
|
---|
157 | indent='';
|
---|
158 | end
|
---|
159 |
|
---|
160 | % loop over the features
|
---|
161 |
|
---|
162 | for i=1:numel(kml)
|
---|
163 | kmli=kml(i);
|
---|
164 | if strcmp(class(kml),'kml_feature')
|
---|
165 | if ~isempty(kmli.id)
|
---|
166 | fprintf(fid,'%s<!Feature id="%s">\n',indent,kmli.id);
|
---|
167 | else
|
---|
168 | fprintf(fid,'%s<!Feature>\n',indent);
|
---|
169 | end
|
---|
170 | end
|
---|
171 | kml_write@kml_object(kmli,fid,indent);
|
---|
172 | if ~isempty(kmli.name)
|
---|
173 | fprintf(fid,'%s <name>%s</name>\n',indent,kmli.name);
|
---|
174 | end
|
---|
175 | fprintf(fid,'%s <visibility>%d</visibility>\n',indent,kmli.visibility);
|
---|
176 | fprintf(fid,'%s <open>%d</open>\n',indent,kmli.open);
|
---|
177 | if ~isempty(kmli.snippet)
|
---|
178 | fprintf(fid,'%s <Snippet maxLines="2">%s</Snippet>\n',indent,kmli.snippet);
|
---|
179 | end
|
---|
180 | if ~isempty(kmli.descript)
|
---|
181 | fprintf(fid,'%s <description>%s</description>\n',indent,kmli.descript);
|
---|
182 | end
|
---|
183 | if ~isempty(kmli.styleurl)
|
---|
184 | fprintf(fid,'%s <styleUrl>%s</styleUrl>\n',indent,kmli.styleurl);
|
---|
185 | end
|
---|
186 |
|
---|
187 | % loop over the styles for each feature
|
---|
188 |
|
---|
189 | for j=1:numel(kmli.style)
|
---|
190 | if ~isempty(kmli.style{j})
|
---|
191 | if isa(kmli.style{j},'kml_styleselector')
|
---|
192 | kml_write(kmli.style{j},fid,[indent ' ']);
|
---|
193 | else
|
---|
194 | warning('kml(%d).style{%d} is a ''%s'' class object, not ''%s''.',...
|
---|
195 | i,j,class(kmli.style{j}),'kml_styleselector');
|
---|
196 | end
|
---|
197 | end
|
---|
198 | end
|
---|
199 |
|
---|
200 | if strcmp(class(kml),'kml_feature')
|
---|
201 | fprintf(fid,'%s<!/Feature>\n',indent);
|
---|
202 | end
|
---|
203 | end
|
---|
204 |
|
---|
205 | end
|
---|
206 |
|
---|
207 | % string write the object
|
---|
208 |
|
---|
209 | function [sbuf]=kml_swrite(kml,sbuf,indent)
|
---|
210 |
|
---|
211 | if ~exist('sbuf','var') || isempty(sbuf)
|
---|
212 | sbuf=string_buf;
|
---|
213 | end
|
---|
214 | if ~exist('indent','var') || isempty(indent)
|
---|
215 | indent='';
|
---|
216 | end
|
---|
217 |
|
---|
218 | % loop over the features
|
---|
219 |
|
---|
220 | for i=1:numel(kml)
|
---|
221 | kmli=kml(i);
|
---|
222 | if strcmp(class(kml),'kml_feature')
|
---|
223 | if ~isempty(kmli.id)
|
---|
224 | sbuf=add(sbuf,sprintf('%s<!Feature id="%s">\n',indent,kmli.id));
|
---|
225 | else
|
---|
226 | sbuf=add(sbuf,sprintf('%s<!Feature>\n',indent));
|
---|
227 | end
|
---|
228 | end
|
---|
229 | sbuf=kml_swrite@kml_object(kmli,sbuf,indent);
|
---|
230 | if ~isempty(kmli.name)
|
---|
231 | sbuf=add(sbuf,sprintf('%s <name>%s</name>\n',indent,kmli.name));
|
---|
232 | end
|
---|
233 | sbuf=add(sbuf,sprintf('%s <visibility>%d</visibility>\n',indent,kmli.visibility));
|
---|
234 | sbuf=add(sbuf,sprintf('%s <open>%d</open>\n',indent,kmli.open));
|
---|
235 | if ~isempty(kmli.snippet)
|
---|
236 | sbuf=add(sbuf,sprintf('%s <Snippet maxLines="2">%s</Snippet>\n',indent,kmli.snippet));
|
---|
237 | end
|
---|
238 | if ~isempty(kmli.descript)
|
---|
239 | sbuf=add(sbuf,sprintf('%s <description>%s</description>\n',indent,kmli.descript));
|
---|
240 | end
|
---|
241 | if ~isempty(kmli.styleurl)
|
---|
242 | sbuf=add(sbuf,sprintf('%s <styleUrl>%s</styleUrl>\n',indent,kmli.styleurl));
|
---|
243 | end
|
---|
244 |
|
---|
245 | % loop over the styles for each feature
|
---|
246 |
|
---|
247 | for j=1:numel(kmli.style)
|
---|
248 | if ~isempty(kmli.style{j})
|
---|
249 | if isa(kmli.style{j},'kml_styleselector')
|
---|
250 | sbuf=kml_swrite(kmli.style{j},sbuf,[indent ' ']);
|
---|
251 | else
|
---|
252 | warning('kml(%d).style{%d} is a ''%s'' class object, not ''%s''.',...
|
---|
253 | i,j,class(kmli.style{j}),'kml_styleselector');
|
---|
254 | end
|
---|
255 | end
|
---|
256 | end
|
---|
257 |
|
---|
258 | if strcmp(class(kml),'kml_feature')
|
---|
259 | sbuf=add(sbuf,sprintf('%s<!/Feature>\n',indent));
|
---|
260 | end
|
---|
261 | end
|
---|
262 |
|
---|
263 | end
|
---|
264 |
|
---|
265 | % delete the object
|
---|
266 |
|
---|
267 | function []=delete(kml)
|
---|
268 |
|
---|
269 | % loop over the features
|
---|
270 |
|
---|
271 | for i=numel(kml):-1:1
|
---|
272 | kmli=kml(i);
|
---|
273 |
|
---|
274 | % loop over the styles for each feature
|
---|
275 |
|
---|
276 | for j=numel(kmli.style):-1:1
|
---|
277 | if ~isempty(kmli.style{j})
|
---|
278 | if isa(kmli.style{j},'kml_styleselector')
|
---|
279 | delete(kmli.style{j});
|
---|
280 | else
|
---|
281 | warning('kml(%d).style{%d} is a ''%s'' class object, not ''%s''.',...
|
---|
282 | i,j,class(kmli.style{j}),'kml_styleselector');
|
---|
283 | end
|
---|
284 | end
|
---|
285 | end
|
---|
286 | kmli.style ={};
|
---|
287 |
|
---|
288 | end
|
---|
289 |
|
---|
290 | end
|
---|
291 |
|
---|
292 | end
|
---|
293 |
|
---|
294 | end
|
---|