# GEplot_3DShoreLine

## PURPOSE

## SYNOPSIS

function GEplot_3DShoreline(filename,Lat,Lon,Elev,style,opt11,opt12,opt21,opt22)

## DESCRIPTION

    Shoreline does not tasselate or extrude

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function GEplot_3DShoreline(filename,Lat,Lon,Elev,style,opt11,opt12,opt21,opt22)
    0002 %
    0003 %Shoreline does not tasselate or extrude
    0004
    0005 %3D adaptation of GEplot.  3D version will plot a 3 dimensional plot given the added elevation vector
    0006 %input--P.R. Jackson, USGS, 1-16-08
    0007
    0008 % function GEplot(filename,Lat,Lon,style,opt11,opt12,opt21,opt22)
    0009 %
    0010 % Description: creates a file in kmz format that can be opened into Google Earth.
    0011 %    GEplot uses the same syntax as the traditional plot function but
    0012 %    requires Latitude and Longitudd (WGS84) instead of x and y (note that Lat is
    0013 %    the first argument).
    0014 %    If you need to convert from UTM to Lat/Lon you may use utm2deg.m also
    0015 %    available at Matlab Central
    0016 %
    0017 % Arguments:
    0018 %    filename Example 'rafael', will become 'rafael.kmz'.  The same name
    0019 %             will appear inside Temporary Places in Google Earth as a layer.
    0020 %    dot_size Approximate size of the mark, in meters
    0021 %    Lat, Lon Vectors containing Latitudes and Longitudes.  The number of marks
    0022 %             created by this function is equal to the length of Lat/Lon vectors
    0023 %(opt)style   allows for specifying symbols and colors (line styles are not
    0024 %             supported by Google Earth currently. (see bellow)
    0025 %(opt)opt...   allows for specifying symbol size and line width (see bellow)
    0026 %
    0027 % Example:
    0028 %    GEplot('my_track',Lat,Lon,'o-r','MarkerSize',10,'LineWidth',3)
    0029 %    GEplot('my_track',Lat,Lon)
    0030 %
    0031 % Plot style parameters implemented in GEplot
    0032 %            color               symbol                line style
    0033 %            -----------------------------------------------------------
    0034 %            b     blue          .     point              -    solid
    0035 %            g     green         o     circle          (none)  no line
    0036 %            r     red           x     x-mark
    0037 %            c     cyan          +     plus
    0038 %            m     magenta       *     star
    0039 %            y     yellow        s     square
    0040 %            k     black         d     diamond
    0041 %            w     white (new)   S     filled square (new)
    0042 %                                D     filled diamond (new)
    0043 %                                O     filled circle=big dot (new)
    0044 %
    0045 % Plot properties: 'MarkerSize' 'LineWidth'
    0046 %
    0047 % Additional Notes:
    0048 % 'Hold on' and 'Hold off' were not implemented since one can generate a
    0049 %    .kmz file for each plot and open all simultaneously within GE.
    0050 % Unless you have a lot of data point it is recomended to show the symbols
    0051 %    since they are created in a separate folder so within Google Earth it
    0052 %    is very easy to show/hide the line or the symbols.
    0053 % Current kml/kmz format does not support different linestyles, just solid.
    0054 %    Nevertheless it is possible to define the opacity of the color (the
    0055 %    first FF in the color definition means no transparency).
    0056 % Within Matlab, it is possible to generate a second plot with the
    0057 %    same name, then you just need to select File/Revert within GE to update.
    0058 %
    0059 %
    0060 % Author: Rafael Palacios, Universidad Pontificia Comillas
    0061 % http://www.iit.upcomillas.es/palacios
    0062 % November 2006
    0063 % Version 1.1: Fixed an error while plotting graphs without symbols.
    0064 %
    0065
    0066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0067 % Argument checking
    0068 %
    0069 error(nargchk(4, 9, nargin));  %3 arguments required, 8 maximum
    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 % symbol size and line width
    0082 %
    0083 markersize=7; %matlab default
    0084 linewidth=2;  %matlab default is 0.5, too thin for map overlay
    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 % symbol, line style and color
    0106 %
    0107 symbol='none';
    0108 iconfilename='none';
    0109 linestyle='-';
    0110 color='b';
    0111 colorstring='7f0000ff';
    0112
    0113 if (nargin>=5)
    0114     %linestyle
    0115     if (strfind(style,'-'))
    0116         linestyle='-';
    0117     else
    0118         linestyle='none';
    0119     end
    0120
    0121     %symbol
    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     %color
    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 % Creating kml file
    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 %Symbol styles definition
    0166 fprintf(fp,'<Style id="mystyle">\n');
    0167 fprintf(fp,'   <IconStyle>\n');
    0168 fprintf(fp,'      <scale>%.2f</scale>\n',markersize/14); %scale adjusted for .png image sizes
    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)); %max(Elev)-
    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 %    fprintf(fp,'         <name>Point %d</name>\n',k);  %you may add point labels here
    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)); %max(Elev)-
    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'));