示例#1
0
        public static void GenerateParkingRegionShape(List <MBR> mbrs, string fileName, bool addDev = false)
        {
            String rootDir       = Path.GetDirectoryName(fileName);
            String shapeFileName = Path.GetFileNameWithoutExtension(fileName);
            var    transform     = new Wgs2MgsTransform();
            // Read txt
            ShapeType shapeType = ShapeType.PolyLine;

            DbfFieldDesc[] shpFields = new DbfFieldDesc[]
            {
                new DbfFieldDesc {
                    FieldName = "ID", FieldType = DbfFieldType.Character, FieldLength = 14, RecordOffset = 0
                },
                //new DbfFieldDesc { FieldName = "Name", FieldType = DbfFieldType.Character, FieldLength = 18, RecordOffset = 14 },
            };
            ShapeFileWriter sfw = ShapeFileWriter.CreateWriter(rootDir, shapeFileName, shapeType, shpFields);

            foreach (var mbr in mbrs)
            {
                String[]      fieldData = new string[] { " " };
                List <PointF> vertices  = new List <PointF>();
                GeoPoint[]    points    = new GeoPoint[] { mbr.TopLeft, mbr.TopRight, mbr.BottomRight, mbr.BottomLeft, mbr.TopLeft };
                for (int i = 0; i < points.Length; ++i)
                {
                    var point = points[i];
                    if (addDev)
                    {
                        point = transform.Transform(point);
                    }
                    vertices.Add(point.ToPointF());
                }
                sfw.AddRecord(vertices.ToArray(), vertices.Count, fieldData);
            }
            sfw.Close();
        }
示例#2
0
        private static void setParkingPointsAsShapeFile(List <GeoPoint> points, string fileName, bool addDev = false)
        {
            //写入文件
            String    rootDir       = Path.GetDirectoryName(fileName);
            String    shapeFileName = Path.GetFileNameWithoutExtension(fileName);
            ShapeType shapeType     = ShapeType.Point;
            var       transform     = new Wgs2MgsTransform();

            DbfFieldDesc[] fields = new DbfFieldDesc[]
            {
                new DbfFieldDesc {
                    FieldName = "ID", FieldType = DbfFieldType.Character, FieldLength = 14, RecordOffset = 0
                },
                //new DbfFieldDesc { FieldName = "Name", FieldType = DbfFieldType.Character, FieldLength = 18, RecordOffset = 14 },
            };
            ShapeFileWriter sfw = ShapeFileWriter.CreateWriter(rootDir, shapeFileName, shapeType, fields);

            foreach (var p in points)
            {
                String[]      fieldData = new string[] { " " };
                List <PointF> vertices  = new List <PointF>();
                GeoPoint      point     = p;
                if (addDev)
                {
                    point = transform.Transform(point);
                }
                float lng = (float)(point.Lng);
                float lat = (float)(point.Lat);
                vertices.Add(new PointF(lng, lat));
                sfw.AddRecord(vertices.ToArray(), vertices.Count, fieldData);
            }
            sfw.Close();
        }
示例#3
0
        private static void setAsShapeFile(Dictionary <long, HashSet <string> > edgeDevicesDict, Graph graph, string fileName, bool addDev = false)
        {
            //写入文件
            String    rootDir       = Path.GetDirectoryName(fileName);
            String    shapeFileName = Path.GetFileNameWithoutExtension(fileName);
            ShapeType shapeType     = ShapeType.PolyLine;
            var       transform     = new Wgs2MgsTransform();
            int       threshold     = 1;

            DbfFieldDesc[] fields = new DbfFieldDesc[]
            {
                new DbfFieldDesc {
                    FieldName = "ID", FieldType = DbfFieldType.Character, FieldLength = 14, RecordOffset = 0
                },
                //new DbfFieldDesc { FieldName = "Name", FieldType = DbfFieldType.Character, FieldLength = 18, RecordOffset = 14 },
            };
            ShapeFileWriter sfw = ShapeFileWriter.CreateWriter(rootDir, shapeFileName, shapeType, fields);

            foreach (var p in edgeDevicesDict)
            //foreach (Edge e in Edges.Values)
            {
                if (edgeDevicesDict.Count < threshold)
                {
                    continue;
                }
                Edge   e  = graph.Edges[p.Key];
                String id = e.ID.ToString();
                if (e.ID % 2 == 0)
                {
                    continue;
                }
                String[]      fieldData = new string[] { "" };
                List <PointF> vertices  = new List <PointF>();
                for (int i = 0; i < e.Geo.Points.Count; i++)
                {
                    GeoPoint point = e.Geo.Points[i];
                    if (addDev)
                    {
                        point = transform.Transform(point);
                    }
                    float lng = (float)(point.Lng);
                    float lat = (float)(point.Lat);
                    vertices.Add(new PointF(lng, lat));
                }
                sfw.AddRecord(vertices.ToArray(), vertices.Count, fieldData);
            }
            sfw.Close();
        }
示例#4
0
        public static void GenerateParkingRegionShapeFromFile(string fileName, bool addDev = false)
        {
            string txtFileName = Path.Combine(Constants.DATA_DIR, "beijingTrjPart", "stat",
                                              "parkingRegion.txt");
            //string fileName = Path.Combine(Constants.DATA_DIR, "beijingTrjPart", "shp", "parkingRegion.shp");
            String rootDir       = Path.GetDirectoryName(fileName);
            String shapeFileName = Path.GetFileNameWithoutExtension(fileName);
            var    transform     = new Wgs2MgsTransform();

            // Read txt
            string[] lines = File.ReadAllLines(txtFileName);

            ShapeType shapeType = ShapeType.PolyLine;

            DbfFieldDesc[] shpFields = new DbfFieldDesc[]
            {
                new DbfFieldDesc {
                    FieldName = "ID", FieldType = DbfFieldType.Character, FieldLength = 14, RecordOffset = 0
                },
                //new DbfFieldDesc { FieldName = "Name", FieldType = DbfFieldType.Character, FieldLength = 18, RecordOffset = 14 },
            };
            ShapeFileWriter sfw = ShapeFileWriter.CreateWriter(rootDir, shapeFileName, shapeType, shpFields);

            foreach (var line in lines)
            {
                var fields = line.Split(new char[] { ',' });
                if (fields.Length % 2 != 0)
                {
                    continue;
                }
                String[]      fieldData = new string[] { " " };
                List <PointF> vertices  = new List <PointF>();
                for (int i = 0; i < fields.Length; i += 2)
                {
                    float    lat   = float.Parse(fields[i]);
                    float    lng   = float.Parse(fields[i + 1]);
                    GeoPoint point = new GeoPoint(lat, lng);
                    if (addDev)
                    {
                        point = transform.Transform(point);
                    }
                    vertices.Add(new PointF((float)point.Lng, (float)point.Lat));
                }
                sfw.AddRecord(vertices.ToArray(), vertices.Count, fieldData);
            }
            sfw.Close();
        }
示例#5
0
        private void miOpenTrj_Click(object sender, EventArgs e)
        {
            //OpenFileDialog f = new OpenFileDialog();
            OpenFileDialog f = new OpenFileDialog();

            //f.InitialDirectory = Directory.GetCurrentDirectory();
            f.FileName = shpFileName;
            f.Filter   = "Trajectory Files (*.trj;*.txt)|*.trj;*.txt|All Files (*.*)|*.*";
            if (f.ShowDialog() == DialogResult.OK)
            {
                // outputFileDir = f.SelectedPath + "\\";
                //MessageBox.Show(f.SelectedPath);
                //Trajectory trj = new Trajectory(f.FileName, 1, graph);
                Trajectory trj       = new Trajectory(f.FileName, 1);
                var        transform = new Wgs2MgsTransform();
                drawTrj(trj);
                trj = transform.Transform(trj);
                drawTrj(trj);
                MM mm = new MM(graph);
                //var newTrj = mm.match(trj);
                trj = mm.match(trj);
                drawPath(trj.Path.Edges);
            }
        }