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