0001 function GEplot(filename,Lat,Lon,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 error(nargchk(3, 8, nargin));
0065 n1=length(Lat);
0066 n2=length(Lon);
0067 if (n1~=n2)
0068 error('Lat and Lon vectors should have the same length');
0069 end
0070 if (nargin==5 || nargin==7)
0071 error('size arguments must be "MarkerSize" or "LineWidth" strings followed by a number');
0072 end
0073
0074
0075
0076
0077 markersize=7;
0078 linewidth=2;
0079 if (nargin==6)
0080 if (strcmpi(opt11,'markersize')==1)
0081 markersize=opt12;
0082 elseif (strcmpi(opt11,'linewidth')==1)
0083 linewidth=opt12;
0084 else
0085 error('size arguments must be "MarkerSize" or "LineWidth" strings followed by a number');
0086 end
0087 end
0088 if (nargin==8)
0089 if (strcmpi(opt21,'markersize')==1)
0090 markersize=opt22;
0091 elseif (strcmpi(opt21,'linewidth')==1)
0092 linewidth=opt22;
0093 else
0094 error('size arguments must be "MarkerSize" or "LineWidth" strings followed by a number');
0095 end
0096 end
0097
0098
0099
0100
0101 symbol='none';
0102 iconfilename='none';
0103 linestyle='-';
0104 color='b';
0105 colorstring='ffff0000';
0106
0107 if (nargin>=4)
0108
0109 if (strfind(style,'-'))
0110 linestyle='-';
0111 else
0112 linestyle='none';
0113 end
0114
0115
0116 if (strfind(style,'.')), symbol='.'; iconfilename='dot'; end
0117 if (strfind(style,'o')), symbol='o'; iconfilename='circle'; end
0118 if (strfind(style,'x')), symbol='x'; iconfilename='x'; end
0119 if (strfind(style,'+')), symbol='+'; iconfilename='plus'; end
0120 if (strfind(style,'*')), symbol='*'; iconfilename='star'; end
0121 if (strfind(style,'s')), symbol='s'; iconfilename='square'; end
0122 if (strfind(style,'d')), symbol='d'; iconfilename='diamond'; end
0123 if (strfind(style,'S')), symbol='S'; iconfilename='Ssquare'; end
0124 if (strfind(style,'D')), symbol='D'; iconfilename='Sdiamon'; end
0125 if (strfind(style,'O')), symbol='O'; iconfilename='dot'; end
0126 if (strfind(style,'0')), symbol='O'; iconfilename='dot'; end
0127
0128
0129 if (strfind(style,'b')), color='b'; colorstring='ffff0000'; end
0130 if (strfind(style,'g')), color='g'; colorstring='ff00ff00'; end
0131 if (strfind(style,'r')), color='r'; colorstring='ff0000ff'; end
0132 if (strfind(style,'c')), color='c'; colorstring='ffffff00'; end
0133 if (strfind(style,'m')), color='m'; colorstring='ffff00ff'; end
0134 if (strfind(style,'y')), color='y'; colorstring='ff00ffff'; end
0135 if (strfind(style,'k')), color='k'; colorstring='ff000000'; end
0136 if (strfind(style,'w')), color='w'; colorstring='ffffffff'; end
0137 end
0138
0139 iconfilename=strcat('GEimages/',iconfilename,'_',color,'.png');
0140 if (symbol=='.')
0141 markersize=markersize/5;
0142 end
0143
0144
0145
0146
0147
0148 fp=fopen(strcat(filename,'.kml'),'w');
0149 if (fp==-1)
0150 message=disp('Unable to open file %s.kml',filename);
0151 error(message);
0152 end
0153 fprintf(fp,'<?xml version="1.0" encoding="UTF-8"?>\n');
0154 fprintf(fp,'<kml xmlns="http://earth.google.com/kml/2.1">\n');
0155 fprintf(fp,'<Document>\n');
0156 fprintf(fp,'<name>%s</name>\n',strcat(filename,'.kml'));
0157 fprintf(fp,'<description>Graph generated in Matlab (using GEplot.m by Rafael Palacios)</description>\n');
0158
0159
0160 fprintf(fp,'<Style id="mystyle">\n');
0161 fprintf(fp,' <IconStyle>\n');
0162 fprintf(fp,' <scale>%.2f</scale>\n',markersize/14);
0163 fprintf(fp,' <Icon><href>%s</href></Icon>\n',iconfilename);
0164 fprintf(fp,' </IconStyle>\n');
0165 fprintf(fp,' <LineStyle>\n');
0166 fprintf(fp,' <color>%s</color>\n',colorstring);
0167 fprintf(fp,' <width>%d</width>\n',linewidth);
0168 fprintf(fp,' </LineStyle>\n');
0169 fprintf(fp,'</Style>\n');
0170 fprintf(fp,'\n');
0171
0172
0173 if (linestyle=='-')
0174 fprintf(fp,' <Placemark>\n');
0175 fprintf(fp,' <description><![CDATA[Line created with Matlab GEplot.m]]></description>\n');
0176 fprintf(fp,' <name>Line</name>\n');
0177 fprintf(fp,' <visibility>1</visibility>\n');
0178 fprintf(fp,' <open>1</open>\n');
0179 fprintf(fp,' <styleUrl>mystyle</styleUrl>\n');
0180 fprintf(fp,' <LineString>\n');
0181 fprintf(fp,' <extrude>0</extrude>\n');
0182 fprintf(fp,' <tessellate>0</tessellate>\n');
0183 fprintf(fp,' <altitudeMode>clampToGround</altitudeMode>\n');
0184 fprintf(fp,' <coordinates>\n');
0185 for k=1:n1
0186 fprintf(fp,'%11.6f,%11.6f,0\n',Lon(k),Lat(k));
0187 end
0188 fprintf(fp,' </coordinates>\n');
0189 fprintf(fp,' </LineString>\n');
0190 fprintf(fp,' </Placemark>\n');
0191 end
0192
0193 if (strcmp(symbol,'none')==0)
0194 fprintf(fp,' <Folder>\n');
0195 fprintf(fp,' <name>Data points</name>\n');
0196 for k=1:n1
0197 fprintf(fp,' <Placemark>\n');
0198 fprintf(fp,' <description><![CDATA[Point created with Matlab GEplot.m]]></description>\n');
0199
0200 fprintf(fp,' <visibility>1</visibility>\n');
0201 fprintf(fp,' <open>1</open>\n');
0202 fprintf(fp,' <styleUrl>#mystyle</styleUrl>\n');
0203 fprintf(fp,' <Point>\n');
0204 fprintf(fp,' <coordinates>\n');
0205 fprintf(fp,'%11.6f,%11.6f,0\n',Lon(k),Lat(k));
0206 fprintf(fp,' </coordinates>\n');
0207 fprintf(fp,' </Point>\n');
0208 fprintf(fp,' </Placemark>\n');
0209 end
0210 fprintf(fp,' </Folder>\n');
0211 end
0212
0213 fprintf(fp,'</Document>\n');
0214 fprintf(fp,'</kml>\n');
0215
0216 fclose(fp);
0217
0218 if (strcmp(symbol,'none')==1)
0219 zip(filename,{strcat(filename,'.kml')});
0220 else
0221 zip(filename,{strcat(filename,'.kml'), iconfilename});
0222 end
0223 movefile(strcat(filename,'.zip'),strcat(filename,'.kmz'));
0224 delete(strcat(filename,'.kml'));