0

I'm currently tasked with creating a small C# application in Visual C# 2010 Express that loads a CSV file and processes the information to create an array of points, to be displayed on a map. The entries in the CSV are as follows:

Device;Latitude;Longitude;Speed;Time

57EA7531-0E1F-41C7-B785-22398D445FEA;55.512.653;13.306.292;93;13-4-2014 14:01

The idea is to load this information, split the data, appoint it to different attributes of the following code:

ShapeLayer sl = new ShapeLayer("Marker");
wpfMap.Layers.Add(sl);
marker.Width = marker.Height = 20;
marker.ToolTip = "A map marker"; [needs to contain Device;Latitude;Longitude;Speed;Time]
sl.Shapes.Add(marker);
ShapeCanvas.SetLocation(marker, new System.Windows.Point(8.4, 49)); [needs to contain Longitude,Latitude]

noted inbetween [] is the data from the CSV that needs to be entered.

This CSV file contains about 2000 entries and for each entry, a points needs to be created using the above code. I have very limited experience with loading CSV's and creating an Array with the processed data, is there ayone that can help me out?

KDE
  • 65
  • 5
  • Take a look at http://stackoverflow.com/questions/1375410/very-simple-c-sharp-csv-reader to load the CSV and split the data – Etienne Fesser Apr 17 '14 at 12:34
  • As you mentioned CSV contains 2000 entries. What is criterion to match which entry belong to which marker? – Hassan Apr 17 '14 at 12:43
  • the data in each line of the CSV file should be processed in that piece of code and stored in an array of 'markers', after which i can display them. – KDE Apr 17 '14 at 13:01

1 Answers1

0

There are different ways. I will do something like that.

NOTE. Exception handling will be required in this solution.

 string[] allLines = System.IO.File.ReadAllLines(@"yourCVSPath.csv");

 foreach(string sLine in allLines)
 {
         string[] arrLine = sLine.Split(new char[] { ',' }); // or ';' according to provided data

          if (arrLine.Length == 5)
          {
               string sDevice = arrLine[0];
               string sLatitude = arrLine[1];
               string sLongitude = arrLine[2];
               string sSpeed = arrLine[3];
               string sTime = arrLine[4];

               ShapeLayer sl = new ShapeLayer("Marker");
               wpfMap.Layers.Add(sl);
               marker.Width = marker.Height = 20;
               marker.ToolTip = sLine; //[needs to contain Device;Latitude;Longitude;Speed;Time]
               sl.Shapes.Add(marker);
               ShapeCanvas.SetLocation(marker, new System.Windows.Point(sLongitude, sLatitude)); //[needs to contain Longitude,Latitude]
          }
  }
Hassan
  • 5,360
  • 2
  • 22
  • 35