Hi All,
i need your assistance with the following:
i have built an application that fills inputs from a database to a datagridview.
the applicaiton then takes the inputs from the datagridview and writes it down to a file (kml --> google earth).
i know how to write to a file the issue is the order.
the output of the file should be:
[CODE]
-101.2023177342566,35.92269094626265,0 -101.2022793432744,35.92253750459201,0 -101.2020270554968,35.92258752157488,0 -101.2020657349624,35.92275793800641,0 -101.2023177342566,35.92269094626265,0
[/CODE]
currently i managed to wirte the first part of the file
[CODE]
-101.2023177342566,35.92269094626265,0 -101.2022793432744,35.92253750459201,0 -101.2020270554968,35.92258752157488,0 -101.2020657349624,35.92275793800641,0 -101.2023177342566,35.92269094626265,0
[/CODE]
the issue i have is with the second part of the syntax:
[CODE]
[/CODE]
no matter where i put
[CODE]
KMLwriter1.WriteLine("\r\n");
KMLwriter1.WriteLine("" + "\r\n");
KMLwriter1.WriteLine("" + "\r\n");
KMLwriter1.WriteLine("" + "\r\n");
KMLwriter1.WriteLine("" + "\r\n");
KMLwriter1.WriteLine("" + "\r\n");
[/CODE]
i mess up the file and i get something like this
[CODE]
-101.2023177342566,35.92269094626265,0
-101.2022793432744,35.92253750459201,0
[/CODE]
below you can find my current code.
[CODE]
#region Class LatLongPair
class LatLongPair
{
public double Lat { get;set; }
public double Lon { get;set; }
}
#endregion
private void button3_Click(object sender, EventArgs e)
{
StreamWriter KMLwriter1 = new System.IO.StreamWriter(KMLDestinationTB.Text + "\\" + sitenameTB.Text + ".kml", false);
#region KML Header Writings
#endregion KML Header Writing
#region testing new code from web
// this is a new code from the web
Dictionary
List
LatLongPair lPair = null;
string matchHandle = string.Empty;
for (int i = 0; i < LayersGrid.Rows.Count; i++)
{
try
{
if (LayersGrid.Rows[i].Cells[0].Value.ToString() == matchHandle)
{
lPair.Lat = Convert.ToDouble(LayersGrid.Rows[i].Cells[2].Value);
lPair.Lon = Convert.ToDouble(LayersGrid.Rows[i].Cells[1].Value);
lst.Add(lPair);
}
else
{
matchHandle = LayersGrid.Rows[i].Cells[0].Value.ToString();
lPair = new LatLongPair();
lPair.Lat = Convert.ToDouble(LayersGrid.Rows[i].Cells[2].Value);
lPair.Lon = Convert.ToDouble(LayersGrid.Rows[i].Cells[1].Value);
lst = new List
lst.Add(lPair);
LatLongCollectionByName.Add(matchHandle, lst);
#region KML Placemark Writing
KMLwriter1.WriteLine("
KMLwriter1.WriteLine("
KMLwriter1.WriteLine("
KMLwriter1.WriteLine("
KMLwriter1.WriteLine("
KMLwriter1.WriteLine("
KMLwriter1.WriteLine("
KMLwriter1.WriteLine("
}
foreach (KeyValuePair
{
KMLwriter1.WriteLine(lPair.Lon + "," + lPair.Lat + ",0");
}
}
catch
{
MessageBox.Show("error");
}
#endregion
// }
KMLwriter1.WriteLine("\r\n");
KMLwriter1.WriteLine("" + "\r\n");
KMLwriter1.WriteLine("" + "\r\n");
KMLwriter1.WriteLine("" + "\r\n");
KMLwriter1.WriteLine("" + "\r\n");
KMLwriter1.WriteLine("" + "\r\n");
//end of new code from web
#endregion
}
KMLwriter1.Close();
}
[/CODE]
thanks in advance
Jonathan
j kPosted Nov 13, 2013, 1:47 PM
thanks