1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| protected void Page_Load(object sender, EventArgs e)
{
string fichier = "~/Pro/GPS_Files/1011.igc";
string scriptString;
try
{
scriptString = "";
List<System.Drawing.PointF> Liste = new List<System.Drawing.PointF>();
System.Drawing.PointF Point = new System.Drawing.PointF();
// Création d'une instance de StreamReader pour permettre la lecture de notre fichier
StreamReader monStreamReader = new StreamReader(Server.MapPath(fichier));
string ligne = monStreamReader.ReadLine();
string Degres = "";
string Minutes = "";
string Secondes = "";
double Lat, Lng;
// Lecture de toutes les lignes et affichage de chacune sur la page
while (ligne != null)
{
try
{
if (ligne.Substring(0, 1) == "B")
{
Degres = ligne.Substring(7, 2);
Minutes = ligne.Substring(9, 2);
Secondes = ligne.Substring(11, 3);
Lat = double.Parse(Degres) + (double.Parse(Minutes) / 60.000) + (double.Parse(Secondes) * 60 / 1000 / 3600.000);
if (ligne.Substring(14, 1) == "S") Lat = -Lat;
Lat = Math.Round(Lat, 6);
//scriptString += Degres + " " + Minutes + " " + Secondes + " --> "+Lat+" / ";
Degres = ligne.Substring(15, 3);
Minutes = ligne.Substring(18, 2);
Secondes = ligne.Substring(20, 3);
Lng = double.Parse(Degres) + (double.Parse(Minutes) / 60.000) + (double.Parse(Secondes) * 60 / 1000 / 3600.000);
Lng = Math.Round(Lng, 6);
if (ligne.Substring(23, 1) == "W") Lng = -Lng;
//scriptString += Degres+" "+Minutes+" "+Secondes + " -> "+Lng+"<br>";
Point.X = float.Parse(Lat.ToString());
Point.Y = float.Parse(Lng.ToString());
Liste.Add(Point);
}
ligne = monStreamReader.ReadLine();
}
catch
{
}
}
scriptString = Liste.Count.ToString();
//scriptString = GoogleAPI.EncodeCoordinates(Liste);
// Fermeture du StreamReader (attention très important)
monStreamReader.Close();
}
catch (Exception ex)
{
// Code exécuté en cas d'exception
scriptString = ex.Message;
}
Response.Write(scriptString);
} |
Partager