Newer
Older
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function target = poly3(this,long,lat,alt,varargin)
%KML.POLY3(long,lat,alt) Draw a polygonal 3D form, with vertices given by long, lat and alt.
%
% Copyright 2012 Rafael Fernandes de Oliveira (rafael@rafael.aero)
% $Revision: 2.3 $ $Date: 2012/09/05 08:00:00 $
target = struct('type','','id','');
[long,lat] = this.checkUnit(long,lat);
p = inputParser;
nlat = numel(lat);
p.addRequired('lat', @(a)isnumeric(a) && isvector(a) &&~isempty(a));
p.addRequired('long',@(a)isnumeric(a) && isvector(a) &&~isempty(a) && numel(a)==nlat);
p.addRequired('alt', @(a)isnumeric(a) && isvector(a) &&~isempty(a) && numel(a)==nlat);
p.addParamValue('id',kml.getTempID('kml_poly3'),@ischar);
p.addParamValue('name','kml_poly3',@ischar);
p.addParamValue('description','',@ischar);
p.addParamValue('visibility',true,@islogical);
p.addParamValue('lineColor','FFFFFFFF',@(a)ischar(a) && numel(a)==8);
p.addParamValue('polyColor','FFFFFFFF',@(a)ischar(a) && numel(a)==8);
p.addParamValue('lineWidth',1,@(a)isnumeric(a) && numel(a)==1);
p.addParamValue('altitudeMode','relativeToGround',@(a)ismember(a,{'clampToGround','relativeToGround','absolute'}));
p.addParamValue('extrude',false,@islogical);
p.addParamValue('tessellate',true,@islogical);
p.addParamValue('timeStamp','',@ischar);
p.addParamValue('timeSpanBegin','',@ischar);
p.addParamValue('timeSpanEnd','',@ischar);
p.parse(lat,long,alt,varargin{:});
arg = p.Results;
% coordinates = mat2str([long(:) lat(:) alt(:)]);
% coordinates = coordinates(2:end-1);
% coordinates = strrep(coordinates,' ',',');
% coordinates = strrep(coordinates,';',' ');
coordinates = sprintf('%0.16g,%0.16g,%0.16g ',[long(:) lat(:) alt(:)].');
placemark = this.xml.createElement('Placemark');
polygon = this.xml.createElement('Polygon');
outboundary = this.xml.createElement('outerBoundaryIs');
linearring = this.xml.createElement('LinearRing');
style = this.xml.createElement('Style');
linestyle = this.xml.createElement('LineStyle');
polystyle = this.xml.createElement('PolyStyle');
placemark.setAttribute('id',arg.id);
placemark.appendChild(this.textNode('name',arg.name));
placemark.appendChild(this.textNode('visibility',num2str(arg.visibility)));
placemark.appendChild(this.textNode('description',arg.description));
if ~isempty(arg.timeStamp)
timeStamp = this.xml.createElement('TimeStamp');
timeStamp.appendChild(this.textNode('when',arg.timeStamp));
placemark.appendChild(timeStamp);
elseif ~isempty(arg.timeSpanBegin) || ~isempty(arg.timeSpanEnd)
timeSpan = this.xml.createElement('TimeSpan');
if ~isempty(arg.timeSpanBegin)
timeSpan.appendChild(this.textNode('begin',arg.timeSpanBegin));
end
if ~isempty(arg.timeSpanEnd)
timeSpan.appendChild(this.textNode('end',arg.timeSpanEnd));
end
placemark.appendChild(timeSpan);
end
linestyle.appendChild(this.textNode('color',arg.lineColor));
linestyle.appendChild(this.textNode('width',num2str(arg.lineWidth)));
polystyle.appendChild(this.textNode('color',arg.polyColor));
linearring.setAttribute('id',['LinearRing_' arg.id]);
linearring.appendChild(this.textNode('coordinates',coordinates));
polygon.setAttribute('id',['Polygon_' arg.id]);
polygon.appendChild(this.textNode('extrude',num2str(arg.extrude)));
polygon.appendChild(this.textNode('tesselate',num2str(arg.tessellate)));
polygon.appendChild(this.textNode('altitudeMode',arg.altitudeMode));
outboundary.appendChild(linearring);
polygon.appendChild(outboundary);
style.appendChild(linestyle);
style.appendChild(polystyle);
placemark.appendChild(style);
placemark.appendChild(polygon);
this.doc.appendChild(placemark);
target.type = 'Placemark';
target.id = arg.id;
end