Ejemplo n.º 1
0
        public static void CentroidToShapefile()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "文本文件|*.txt;*.csv";
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                StreamReader sr = new StreamReader(ofd.FileName);
                //string[] header = sr.ReadLine().Split(',');
                IFeatureSet oFS = new FeatureSet(FeatureType.Point);
                oFS.Projection = ProjectionInfo.FromEpsgCode(4326);
                oFS.Name       = "BusStop";
                oFS.DataTable.Columns.Add("Name", typeof(string));
                while (!sr.EndOfStream)
                {
                    string[] line         = sr.ReadLine().Split(',');
                    double   x            = double.Parse(line[2]);
                    double   y            = double.Parse(line[3]);
                    var      xyCorrection = CoordinateTransformUtil.bd09towgs84(x, y);
                    var      fe           = oFS.AddFeature(new Point(xyCorrection[0], xyCorrection[1]));
                    fe.DataRow.BeginEdit();
                    fe.DataRow["Name"] = line[0];
                    fe.DataRow.EndEdit();
                }
                oFS.SaveAs("BusStop.shp", true);
                sr.Close();
                Console.WriteLine("Shapefile转换成功!");
                Console.ReadKey();
            }
        }
Ejemplo n.º 2
0
        private static void TransformGPS()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "文本文件|*.txt;*.csv";
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                using (TextReader sr = new StreamReader(ofd.FileName /*,Encoding.GetEncoding("GB2312")*/))
                {
                    var csv = new CsvReader(sr);
                    csv.Configuration.Delimiter = "\t";
                    var records = csv.GetRecords <RefPoints>().ToList();
                    foreach (var item in records)
                    {
                        double[] newPoints = CoordinateTransformUtil.bd09towgs84(item.X, item.Y);
                        item.X = newPoints[0];
                        item.Y = newPoints[1];
                        //double[] newStart = CoordinateTransformUtil.bd09towgs84(item.StartX, item.StartY);
                        //double[] newEnd = CoordinateTransformUtil.bd09towgs84(item.EndX, item.EndY);
                        //item.StartX = newStart[0];
                        //item.StartY = newStart[1];
                        //item.EndX = newEnd[0];
                        //item.EndY = newEnd[1];
                    }
                    StreamWriter sw        = new StreamWriter("newRef_points_hefei.csv", false, Encoding.UTF8);
                    var          csvwriter = new CsvWriter(sw);
                    csvwriter.WriteRecords(records);
                    sw.Close();
                }
                Console.WriteLine("Data Transform Completed!");
                Console.ReadKey();
            }
        }
Ejemplo n.º 3
0
        private static void ProcessingGPSTrajectories()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "文本文件|*.txt;*.csv";
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                StreamWriter sw      = new StreamWriter("newTraces.txt");
                var          gpsData = GPSIO.GPSTrajectoryReader.ReadAll(ofd.FileName);
                foreach (var item in gpsData.GPSTrajectoriesData)
                {
                    sw.Write(item.UserID + "\t");
                    for (int i = 0; i < item.GPSCount; i++)
                    {
                        double[] newPoint = CoordinateTransformUtil.bd09towgs84(item[i].X, item[i].Y);
                        sw.Write(string.Format("{0},{1},{2}", item[i].TimeStamp, newPoint[0], newPoint[1]));
                        if (i != item.GPSCount - 1)
                        {
                            sw.Write("|");
                        }
                    }
                    sw.Write(Environment.NewLine);
                }
                sw.Close();
                Console.WriteLine("Data Transform Completed!");
                Console.ReadKey();
            }
        }