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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function target = model(this,long,lat,alt,heading,tilt,roll,varargin)
%KML.MODEL(long,lat,alt,heading,tilt,roll) Places the 3D model (specified by the pair
% attribute 'model','modelfile.dae') in the position and orientation given by long,
% lat, alt, heading, tilt and roll. If the inputs represent a vector of points, the
% model is repeated in each of them.
%
% Many model files can be found in the <a href="http://sketchup.google.com/3dwarehouse/">Google 3D Warehouse</a> website.
%
% 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,heading,tilt,roll] = this.checkUnit(long,lat,heading,tilt,roll);
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.addRequired('heading',@(a)isnumeric(a) && isvector(a) &&~isempty(a) && numel(a)==nlat);
p.addRequired('tilt',@(a)isnumeric(a) && isvector(a) &&~isempty(a) && numel(a)==nlat);
p.addRequired('roll',@(a)isnumeric(a) && isvector(a) &&~isempty(a) && numel(a)==nlat);
p.addParamValue('id',kml.getTempID('kml_model'),@ischar);
p.addParamValue('name','kml_model',@ischar);
p.addParamValue('description','',@ischar);
p.addParamValue('visibility',true,@islogical);
p.addParamValue('model','',@ischar);
p.addParamValue('scaleX',1,@(a)isnumeric(a) && (numel(a)==nlat || numel(a)==1));
p.addParamValue('scaleY',1,@(a)isnumeric(a) && (numel(a)==nlat || numel(a)==1));
p.addParamValue('scaleZ',1,@(a)isnumeric(a) && (numel(a)==nlat || numel(a)==1));
p.addParamValue('scale',1, @(a)isnumeric(a) && (numel(a)==nlat || numel(a)==1));
p.addParamValue('altitudeMode','relativeToGround',@(a)ismember(a,{'clampToGround','relativeToGround','absolute'}));
p.addParamValue('timeStamp','',@ischar);
p.addParamValue('timeSpanBegin','',@ischar);
p.addParamValue('timeSpanEnd','',@ischar);
p.parse(lat,long,alt,heading,tilt,roll,varargin{:});
arg = p.Results;
if isempty(arg.model)
error('Missing model parameter')
end
arg.scaleX = arg.scaleX .*arg.scale;
arg.scaleY = arg.scaleY .*arg.scale;
arg.scaleZ = arg.scaleZ .*arg.scale;
if numel(arg.scaleX)==1 && nlat>1
arg.scaleX = repmat(arg.scaleX,size(lat));
end
if numel(arg.scaleY)==1 && nlat>1
arg.scaleY = repmat(arg.scaleY,size(lat));
end
if numel(arg.scaleZ)==1 && nlat>1
arg.scaleZ = repmat(arg.scaleZ,size(lat));
end
for i = 1:nlat
target(i).type = 'Placemark';
target(i).id = [arg.id '_' num2str(i)];
target(i).location_id = ['Location_' target(i).id ];
target(i).orientation_id = ['Orientation_' target(i).id ];
target(i).scale_id = ['Scale_' target(i).id ];
target(i).model_id = ['Model_' target(i).id ];
placemark = this.xml.createElement('Placemark');
model = this.xml.createElement('Model');
location = this.xml.createElement('Location');
orientation = this.xml.createElement('Orientation');
scale = this.xml.createElement('Scale');
link = this.xml.createElement('Link');
placemark.setAttribute('id',target(i).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
location.setAttribute('id',target(i).location_id);
location.appendChild(this.textNode('latitude', num2str(lat(i),16)));
location.appendChild(this.textNode('longitude', num2str(long(i),16)));
location.appendChild(this.textNode('altitude', num2str(alt(i),16)));
orientation.setAttribute('id',target(i).orientation_id);
orientation.appendChild(this.textNode('heading', num2str(heading(i))));
orientation.appendChild(this.textNode('tilt', num2str(tilt(i))));
orientation.appendChild(this.textNode('roll', num2str(roll(i))));
scale.setAttribute('id',target(i).scale_id);
scale.appendChild(this.textNode('x', num2str(arg.scaleX(i))));
scale.appendChild(this.textNode('y', num2str(arg.scaleY(i))));
scale.appendChild(this.textNode('z', num2str(arg.scaleZ(i))));
link.appendChild(this.textNode('href',arg.model));
model.setAttribute('id',target(i).model_id);
model.appendChild(this.textNode('altitudeMode',arg.altitudeMode));
model.appendChild(location);
model.appendChild(orientation);
model.appendChild(scale);
model.appendChild(link);
placemark.appendChild(model);
this.doc.appendChild(placemark);
end
this.addIncludeFile(arg.model);
end