Example #1
0
    //to read file
    public static List <Track> LoadFile(string path, string name)
    {
        StreamReader sr = null;

        try
        {
            sr = File.OpenText(path + "//" + name);
        }
        catch (Exception e)
        {
            return(null);
        }

        string line;
        Track  temp = new Track("temp");

        List <Track> tracks = new List <Track>();

        CoordinatorChange coo = new CoordinatorChange();

        while ((line = sr.ReadLine()) != null)
        {
            //if ((pos = line.IndexOf("T")) != -1)
            if (line.Contains("T"))
            {
                temp.calculAvg();
                //Track track = new Track(line.Remove(pos));
                Track track = new Track(line);
                temp = track;
                tracks.Add(track);
                //release
                track = null;
            }
            else if (line.Contains(","))
            {
                string[] result   = line.Split(',');
                Position position = coo.wgs2gcj(new Position(float.Parse(result[0]), float.Parse(result[1]), new PTime(result[2])));
                temp.positions.Add(position);
                //release
                position = null;
                Array.Clear(result, 0, result.Length);
            }
        }
        temp.calculAvg();//last one to calculate
        sr.Close();
        sr.Dispose();
        //release
        temp = null;
        coo  = null;
        return(tracks);
    }
Example #2
0
    //to read file
    public static List <Track> LoadFile(string path, string name)
    {
        TextAsset    ta     = Resources.Load <TextAsset>(path + "/" + name);
        StringReader reader = new StringReader(ta.text);

        string line;
        Track  temp = new Track("temp");

        List <Track> tracks = new List <Track>();

        CoordinatorChange coo = new CoordinatorChange();

        while ((line = reader.ReadLine()) != null)
        {
            //if ((pos = line.IndexOf("T")) != -1)
            if (line.Contains("T"))
            {
                temp.calculAvg();
                //Track track = new Track(line.Remove(pos));
                Track track = new Track(line);
                temp = track;
                tracks.Add(track);
            }
            else if (line.Contains(","))
            {
                string[] result   = line.Split(',');
                Position position = coo.wgs2gcj(new Position(float.Parse(result[0]), float.Parse(result[1]), new PTime(result[2])));
                temp.positions.Add(position);
                //release
                Array.Clear(result, 0, result.Length);
            }
        }
        temp.calculAvg();//last one to calculate

        return(tracks);
    }
Example #3
0
    ////////////////static function////////////////////
    //create title, list[0] is title, list[1] is next linenumber
    public static List <object> getTitle(string path, string name, float lineNumber)
    {
        TextAsset    ta     = Resources.Load <TextAsset>(path + "/" + name);
        StringReader reader = new StringReader(ta.text);

        string line;

        float beginNumber = 0;

        Track track = new Track("temp");

        CoordinatorChange coo   = new CoordinatorChange();
        float             count = lineNumber;

        //skip to the target line
        for (int i = 0; i < count; i++)
        {
            reader.ReadLine();
        }
        //for read the name
        while (true)
        {
            line = reader.ReadLine();
            if (line != null)
            {
                if (line.Contains("T"))
                {
                    track       = new Track(line);
                    beginNumber = count;
                    count++;
                    break;
                }
                else
                {
                    Debug.Log("the line " + count + " do not have T, see the next line.");
                    count++;
                }
            }
            else
            {
                count = -1;
                break;
            }
        }

        if (count != -1)
        {
            //for create positions
            while ((line = reader.ReadLine()) != null)
            {
                if (line.Contains(","))
                {
                    string[] result   = line.Split(',');
                    Position position = coo.wgs2gcj(new Position(float.Parse(result[0]), float.Parse(result[1]), new PTime(result[2])));
                    track.positions.Add(position);
                    count++;
                    //release
                    Array.Clear(result, 0, result.Length);
                }
                else if (line.Contains("T"))
                {
                    break;
                }
                else
                {
                    Debug.Log("face some problem in line " + count);
                }
            }
            track.calculAvg();
        }


        Title title = new Title(track.name, track.avgLat, track.avgLon, beginNumber);

        List <object> temp = new List <object>();

        temp.Add(title);
        temp.Add(count);

        return(temp);
    }