0001 function GEplot_3D(filename,Lat,Lon,Elev,style,opt11,opt12,opt21,opt22)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 error(nargchk(4, 9, nargin));
0068 n1=length(Lat);
0069 n2=length(Lon);
0070 n3=length(Elev);
0071 if (n1~=n2 | n1~=n3)
0072 error('Lat, Lon, and Elev vectors should have the same length');
0073 end
0074 if (nargin==6 || nargin==8)
0075 error('size arguments must be "MarkerSize" or "LineWidth" strings followed by a number');
0076 end
0077
0078
0079
0080
0081 markersize=7;
0082 linewidth=2;
0083 if (nargin==7)
0084 if (strcmpi(opt11,'markersize')==1)
0085 markersize=opt12;
0086 elseif (strcmpi(opt11,'linewidth')==1)
0087 linewidth=opt12;
0088 else
0089 error('size arguments must be "MarkerSize" or "LineWidth" strings followed by a number');
0090 end
0091 end
0092 if (nargin==9)
0093 if (strcmpi(opt21,'markersize')==1)
0094 markersize=opt22;
0095 elseif (strcmpi(opt21,'linewidth')==1)
0096 linewidth=opt22;
0097 else
0098 error('size arguments must be "MarkerSize" or "LineWidth" strings followed by a number');
0099 end
0100 end
0101
0102
0103
0104
0105 symbol='none';
0106 iconfilename='none';
0107 linestyle='-';
0108 color='b';
0109 colorstring='7fff0000';
0110
0111 if (nargin>=5)
0112
0113 if (strfind(style,'-'))
0114 linestyle='-';
0115 else
0116 linestyle='none';
0117 end
0118
0119
0120 if (strfind(style,'.')), symbol='.'; iconfilename='dot'; end
0121 if (strfind(style,'o')), symbol='o'; iconfilename='circle'; end
0122 if (strfind(style,'x')), symbol='x'; iconfilename='x'; end
0123 if (strfind(style,'+')), symbol='+'; iconfilename='plus'; end
0124 if (strfind(style,'*')), symbol='*'; iconfilename='star'; end
0125 if (strfind(style,'s')), symbol='s'; iconfilename='square'; end
0126 if (strfind(style,'d')), symbol='d'; iconfilename='diamond'; end
0127 if (strfind(style,'S')), symbol='S'; iconfilename='Ssquare'; end
0128 if (strfind(style,'D')), symbol='D'; iconfilename='Sdiamon'; end
0129 if (strfind(style,'O')), symbol='O'; iconfilename='dot'; end
0130 if (strfind(style,'0')), symbol='O'; iconfilename='dot'; end
0131
0132
0133 if (strfind(style,'b')), color='b'; colorstring='7fff0000'; end
0134 if (strfind(style,'g')), color='g'; colorstring='7f00ff00'; end
0135 if (strfind(style,'r')), color='r'; colorstring='7f0000ff'; end
0136 if (strfind(style,'c')), color='c'; colorstring='7fffff00'; end
0137 if (strfind(style,'m')), color='m'; colorstring='7fff00ff'; end
0138 if (strfind(style,'y')), color='y'; colorstring='7f00ffff'; end
0139 if (strfind(style,'k')), color='k'; colorstring='7f000000'; end
0140 if (strfind(style,'w')), color='w'; colorstring='7fffffff'; end
0141 end
0142
0143 iconfilename=strcat('GEimages/',iconfilename,'_',color,'.png');
0144 if (symbol=='.')
0145 markersize=markersize/5;
0146 end
0147
0148
0149
0150
0151
0152 fp=fopen(strcat(filename,'.kml'),'w');
0153 if (fp==-1)
0154 message=disp('Unable to open file %s.kml',filename);
0155 error(message);
0156 end
0157 fprintf(fp,'<?xml version="1.0" encoding="UTF-8"?>\n');
0158 fprintf(fp,'<kml xmlns="http://earth.google.com/kml/2.1">\n');
0159 fprintf(fp,'<Document>\n');
0160 fprintf(fp,'<name>%s</name>\n',strcat(filename,'.kml'));
0161 fprintf(fp,'<description>Graph generated in Matlab (using GEplot.m by Rafael Palacios)</description>\n');
0162
0163
0164 fprintf(fp,'<Style id="mystyle">\n');
0165 fprintf(fp,' <IconStyle>\n');
0166 fprintf(fp,' <scale>%.2f</scale>\n',markersize/14);
0167 fprintf(fp,' <Icon><href>%s</href></Icon>\n',iconfilename);
0168 fprintf(fp,' </IconStyle>\n');
0169 fprintf(fp,' <LineStyle>\n');
0170 fprintf(fp,' <color>%s</color>\n',colorstring);
0171 fprintf(fp,' <width>%d</width>\n',linewidth);
0172 fprintf(fp,' </LineStyle>\n');
0173 fprintf(fp,' <PolyStyle>\n');
0174 fprintf(fp,' <color>7fffffff</color>\n');
0175 fprintf(fp,' <colorMode>normal</colorMode>\n');
0176 fprintf(fp,' <fill>1</fill>\n');
0177 fprintf(fp,' <outline>1</outline>\n');
0178 fprintf(fp,' </PolyStyle>\n');
0179 fprintf(fp,'</Style>\n');
0180 fprintf(fp,'\n');
0181
0182
0183 if (linestyle=='-')
0184 fprintf(fp,' <Placemark>\n');
0185 fprintf(fp,' <description><![CDATA[Line Cross Section created with VMT using GEplot.m]]></description>\n');
0186 fprintf(fp,' <name>Line</name>\n');
0187 fprintf(fp,' <visibility>1</visibility>\n');
0188 fprintf(fp,' <open>1</open>\n');
0189 fprintf(fp,' <styleUrl>mystyle</styleUrl>\n');
0190 fprintf(fp,' <LineString>\n');
0191 fprintf(fp,' <extrude>1</extrude>\n');
0192 fprintf(fp,' <tessellate>1</tessellate>\n');
0193 fprintf(fp,' <altitudeMode>relativeToGround</altitudeMode>\n');
0194 fprintf(fp,' <coordinates>\n');
0195 for k=1:n1
0196 fprintf(fp,'%.6f,%.6f,%07.2f\n',Lon(k),Lat(k),Elev(k));
0197 end
0198 fprintf(fp,' </coordinates>\n');
0199 fprintf(fp,' </LineString>\n');
0200 fprintf(fp,' </Placemark>\n');
0201 end
0202
0203 if (strcmp(symbol,'none')==0)
0204 fprintf(fp,' <Folder>\n');
0205 fprintf(fp,' <name>Data points</name>\n');
0206 for k=1:n1
0207 fprintf(fp,' <Placemark>\n');
0208 fprintf(fp,' <description><![CDATA[Point created with Matlab GEplot.m]]></description>\n');
0209
0210 fprintf(fp,' <visibility>1</visibility>\n');
0211 fprintf(fp,' <open>1</open>\n');
0212 fprintf(fp,' <styleUrl>#mystyle</styleUrl>\n');
0213 fprintf(fp,' <Point>\n');
0214 fprintf(fp,' <coordinates>\n');
0215 fprintf(fp,'%.6f,%.6f,%07.2f\n',Lon(k),Lat(k),Elev(k));
0216 fprintf(fp,' </coordinates>\n');
0217 fprintf(fp,' </Point>\n');
0218 fprintf(fp,' </Placemark>\n');
0219 end
0220 fprintf(fp,' </Folder>\n');
0221 end
0222
0223 fprintf(fp,'</Document>\n');
0224 fprintf(fp,'</kml>\n');
0225
0226 fclose(fp);
0227
0228 if (strcmp(symbol,'none')==1)
0229 zip(filename,{strcat(filename,'.kml')});
0230 else
0231 zip(filename,{strcat(filename,'.kml'), iconfilename});
0232 end
0233 movefile(strcat(filename,'.zip'),strcat(filename,'.kmz'));
0234 delete(strcat(filename,'.kml'));