Exemple #1
0
        void DATAshow(DataGridView DATA_shpLine, shpfile shp) //在数据窗口显示数据
        {
            DATA_shpLine.Rows.Clear();                        //清空窗口
            int row_number = 0;

            DATA_shpLine.Rows.Add();
            DATA_shpLine.Rows[row_number].Cells[0].Value   = "线段总数:";
            DATA_shpLine.Rows[row_number].Cells[1].Value   = shp.line.Count;
            DATA_shpLine.Rows[row_number].Cells[2].Value   = "图层类型:";
            DATA_shpLine.Rows[row_number++].Cells[3].Value = "线";
            for (int i = 0; i < shp.line.Count; i++)
            {
                DATA_shpLine.Rows.Add();
                DATA_shpLine.Rows[row_number].Cells[0].Value   = "线段序号:";
                DATA_shpLine.Rows[row_number].Cells[1].Value   = shp.line[i].recordNumber;
                DATA_shpLine.Rows[row_number].Cells[2].Value   = "折线段数:";
                DATA_shpLine.Rows[row_number++].Cells[3].Value = shp.line[i].numpoints - 1;
                for (int j = shp.line[i].parts[0]; j < shp.line[i].numpoints - 1; j++)
                {
                    DATA_shpLine.Rows.Add();
                    DATA_shpLine.Rows[row_number].Cells[0].Value = shp.line[i]
                                                                   .ponits[j].X.ToString("0.0000");
                    DATA_shpLine.Rows[row_number].Cells[1].Value = shp.line[i]
                                                                   .ponits[j].Y.ToString("0.0000");
                    DATA_shpLine.Rows[row_number].Cells[2].Value = shp.line[i]
                                                                   .ponits[j + 1].X.ToString("0.0000");
                    DATA_shpLine.Rows[row_number++].Cells[3].Value = shp.line[i]
                                                                     .ponits[j + 1].Y.ToString("0.0000");
                }
            }
        }
        public List <List <double> > improve_Hausdorff(shpfile shp1, shpfile shp2)          //基于改进的Hausdorff_SMHD距离
        {
            List <List <double> > im_Hausdorff_D = new List <List <double> >();

            for (int i = 0; i < shp1.line.Count; i++)
            {
                List <double> Haus_D = new List <double>();
                for (int j = 0; j < shp2.line.Count; j++)
                {
                    Haus_D.Add(im_H_Line_D(shp1.line[i], shp2.line[j]));
                }
                im_Hausdorff_D.Add(Haus_D);
            }
            return(im_Hausdorff_D);
        }
        public List <List <double> > aver_Feachet(shpfile shp1, shpfile shp2)//求出两个.shp文件的各个线实体的平均Frechet距离
        {
            List <List <double> > Feachet_D = new List <List <double> >();

            for (int i = 0; i < shp1.line.Count; i++)
            {
                List <double> fc_d = new List <double>();
                for (int j = 0; j < shp2.line.Count; j++)
                {
                    fc_d.Add(aver_Feachet_line(shp1.line[i], shp2.line[j]));
                }
                Feachet_D.Add(fc_d);
            }
            return(Feachet_D);
        }
        public List <List <double> > Hausdorff(shpfile shp1, shpfile shp2)            //求出两个.shp文件的各个线实体的hausdroof距离
        {
            List <List <double> > hausfroff_D = new List <List <double> >();

            for (int i = 0; i < shp1.line.Count; i++)
            {
                List <double> Haus_D = new List <double>();
                for (int j = 0; j < shp2.line.Count; j++)
                {
                    Haus_D.Add(Math.Max(H_line_D(shp1.line[i], shp2.line[j]), H_line_D(shp2.line[j], shp1.line[i])));
                }
                hausfroff_D.Add(Haus_D);
            }
            return(hausfroff_D);
        }
Exemple #5
0
        private void open_shpfile_Click(object sender, EventArgs e) //    打开shpfile文件
        {
            if (readnum == 0)                                       //全部初始化
            {
                shp1          = new shpfile();
                shp2          = new shpfile();
                dis_result[0] = null;
                dis_result    = new discriminant_result[5];
                all_rangeX.Clear();
                all_rangeY.Clear();
                checkedListBox1.SetItemChecked(0, true);
                checkedListBox1.SetItemChecked(1, true);
                pictureBox1.BackgroundImage = new Bitmap(835, 470);
                REPORT_show.Text            = "";
            }
            ;
            try
            {
                OpenFileDialog opf = new OpenFileDialog();
                opf.InitialDirectory = Path;

                opf.Title = "请选择导入shp文件";

                opf.Filter = "(*.shp)|*.shp";
                status_text("玩命加载中   请稍等……", Color.Black);
                if (opf.ShowDialog() == DialogResult.OK)
                {
                    string shppath = opf.FileName;
                    if (readnum == 0)
                    {
                        readshp(shppath, shp1);
                        DATAshow(DATA_shpLine1, shp1);                     //显示读取的数据
                        DATA_shpLine2.Rows.Clear();
                        status_text("成功读取第一个shpfile文件", Color.Black);
                        readnum = 1;
                    }
                    else
                    {
                        readshp(shppath, shp2);
                        DATAshow(DATA_shpLine2, shp2);                          //显示读取的数据
                        status_text("成功读取第二个shpfile文件", Color.Black);
                        readnum = 0;
                    }
                    DATA_show.BringToFront();
                }
            }
            catch { MessageBox.Show("程序错误"); }
        }
Exemple #6
0
        void readshp(string shppath, shpfile shp)          //读取shpfile文件
        {
            BinaryReader br = new BinaryReader(new FileStream(shppath, FileMode.Open,
                                                              FileAccess.Read)); //建立读取文件的二进制文件流

            br.ReadBytes(24);                                                    //读取头文件信息
            shp.filelength = shp.bigtolitter(br.ReadInt32());                    //读取文件长度及进行转换
            br.ReadInt32();
            shp.shapeType = br.ReadInt32();                                      //读取图层的集合类型
            all_rangeX.Add(br.ReadDouble());                                     //读取该图层的坐标范围
            all_rangeY.Add(br.ReadDouble());
            all_rangeX.Add(br.ReadDouble());
            all_rangeY.Add(br.ReadDouble());
            br.ReadBytes(32);             //读取头文件信息结束

            //读取线实体信息

            while (br.PeekChar() != -1)
            {
                shpline shpl = new shpline();
                shpl.recordNumber  = shp.bigtolitter(br.ReadInt32());       //该线实体序号
                shpl.contentlength = shp.bigtolitter(br.ReadInt32());       //该线实体信息长度
                br.ReadUInt32();
                shpl.Box[0]    = br.ReadDouble();                           //该线实体的范围(X,Y,最大最小)
                shpl.Box[1]    = br.ReadDouble();
                shpl.Box[2]    = br.ReadDouble();
                shpl.Box[3]    = br.ReadDouble();
                shpl.numparts  = br.ReadInt32();                             //线段的起点在总的点数组中的位置
                shpl.numpoints = br.ReadInt32();                             //该线实体的点的个数
                shpl.parts     = new int[shpl.numparts];
                shpl.ponits    = new PointD[shpl.numpoints];
                for (int i = 0; i < shpl.numparts; i++)
                {
                    shpl.parts[i] = br.ReadInt32();
                }

                for (int i = 0; i < shpl.numpoints; i++)                    //读取点信息
                {
                    shpl.ponits[i].name = (shp.line.Count + 1).ToString() + "-" + (i + 1);
                    shpl.ponits[i].X    = br.ReadDouble();
                    shpl.ponits[i].Y    = br.ReadDouble();
                }
                shp.line.Add(shpl);
            }
        }
Exemple #7
0
        public void save_dxf(string path, List <double> rangeX, List <double> rangeY, shpfile shp1, shpfile shp2)// 保存.dxf文件
        {
            double smX = (rangeX.Max() - rangeX.Min());
            double smY = (rangeY.Max() - rangeY.Min());
            double scaling_magnification = Math.Max(smX, smY) / 100;


            StreamWriter sw = new StreamWriter(path);  //(同步读写)

            writeline(sw, "0", "SECTION");             //开始建立图层
            writeline(sw, "2", "TABLES");
            writeline(sw, "0", "TABLE");
            writeline(sw, "2", "LAYER");
            layer(sw, "shp1", 70);
            layer(sw, "shp2", 10);
            layer(sw, "shp1_name", 50);
            layer(sw, "shp2_name", 110);
            writeline(sw, "0", "ENDTAB");
            writeline(sw, "0", "ENDSEC");            //结束建立图层
            writeline(sw, "0", "SECTION");           //开始画图
            writeline(sw, "2", "ENTITIES");
            //画出图层1
            for (int i = 0; i < shp1.line.Count; i++)
            {
                for (int j = 0; j < shp1.line[i].numpoints - 1; j++)
                {
                    line(sw, (float)shp1.line[i].ponits[j].X, (float)shp1.line[i].ponits[j].Y,
                         (float)shp1.line[i].ponits[j + 1].X, (float)shp1.line[i].ponits[j + 1].Y, "shp1");
                    text(sw, (float)((shp1.line[i].ponits[j].X + shp1.line[i].ponits[j + 1].X) / 2.0) + float.Parse((0.3).ToString()),
                         (float)((shp1.line[i].ponits[j].Y + shp1.line[i].ponits[j + 1].Y) / 2.0), "shp1",
                         shp1.line [i].ponits[j].name, float.Parse(scaling_magnification.ToString()));
                }
                // text(sw, (float)shp1.line[i].ponits[shp1.line[i].numpoints - 1].X + float.Parse((0.3).ToString()), (float)shp1.line[i].ponits[shp1.line[i].numpoints - 1].Y, "shp1",
                //  shp1.line[i].ponits[shp1.line[i].numpoints - 1].name, float.Parse((5).ToString()));
            }
            //画出图层2
            for (int i = 0; i < shp2.line.Count; i++)
            {
                for (int j = 0; j < shp2.line[i].numpoints - 1; j++)
                {
                    line(sw, (float)shp2.line[i].ponits[j].X, (float)shp2.line[i].ponits[j].Y,
                         (float)shp2.line[i].ponits[j + 1].X, (float)shp2.line[i].ponits[j + 1].Y, "shp2");
                    text(sw, (float)((shp2.line[i].ponits[j].X + shp2.line[i].ponits[j + 1].X) / 2.0) + float.Parse((0.3).ToString()),
                         (float)((shp2.line[i].ponits[j].Y + shp2.line[i].ponits[j + 1].Y) / 2.0), "shp2",
                         shp2.line[i].ponits[j].name, float.Parse(scaling_magnification.ToString()));
                }
                //   text(sw, (float)shp2.line[i].ponits[shp2.line[i].numpoints - 1].X + float.Parse((0.3).ToString()), (float)shp2.line[i].ponits[shp2.line[i].numpoints - 1].Y, "shp2",
                //     shp2.line[i].ponits[shp2.line[i].numpoints - 1].name, float.Parse((5).ToString()));
            }

            writeline(sw, "0", "ENDSEC");
            writeline(sw, "0", "EOF");
            sw.Close();
        }
Exemple #8
0
        public Bitmap get_picture(List <double> rangeX, List <double> rangeY, shpfile shp1, shpfile shp2)                //在画布上画出图形,并得到画布
        {
            Bitmap   bmap = new Bitmap(835, 470);
            Graphics gph  = Graphics.FromImage(bmap);

            gph.Clear(Color.White);                                 //清空背景
            Brush bru = new SolidBrush(Color.Blue);

            double smX = (rangeX.Max() - rangeX.Min()) / 800.0;
            double smY = (rangeY.Max() - rangeY.Min()) / 450;
            double scaling_magnification = Math.Max(smX, smY);                                   //统一X,Y轴的缩放比例
            PointF base_shp_p            = new PointF((float)rangeX.Min(), (float)rangeY.Min()); //两个图层的基点(x最小和y最小)
            PointF base_p = new PointF(15, 7);

            if (scaling_magnification == smX)
            {
                base_p.Y = (float)(base_p.Y - (450 - (rangeY.Max() - rangeY.Min()) / scaling_magnification) / 2.0);
            }
            else
            {
                base_p.X = (float)(base_p.X + (800 - (rangeX.Max() - rangeX.Min()) / scaling_magnification) / 2.0);
            }
            Pen pen = new Pen(Color.Blue, (float)0.001);

            for (int i = 0; i < shp1.line.Count(); i++)                                            //画图层1
            {
                for (int j = 0; j < shp1.line[i].numpoints - 1; j++)
                {
                    gph.DrawLine(pen, fun1(base_p, shp1.line[i].ponits[j], base_shp_p, scaling_magnification),
                                 fun1(base_p, shp1.line[i].ponits[j + 1], base_shp_p, scaling_magnification));                 //画折线
                    gph.FillEllipse(new SolidBrush(Color.Blue),
                                    fun1(base_p, shp1.line[i].ponits[j], base_shp_p, scaling_magnification).X - (float)1 * (float)scaling_magnification / 2,
                                    fun1(base_p, shp1.line[i].ponits[j], base_shp_p, scaling_magnification).Y - (float)1 * (float)scaling_magnification / 2,
                                    (float)1 * (float)scaling_magnification, (float)1 * (float)scaling_magnification);
                    //    gph.DrawString(shp1.line[i].ponits[j].name, new Font("宋体", 8f), bru,                                     //画点名(如果线段很多,它的点名重复,图像会变得非常模糊)
                    //     fun1(base_p, shp1.line[i].ponits[j], base_shp_p, scaling_magnification));
                }
                gph.FillEllipse(new SolidBrush(Color.Blue),
                                fun1(base_p, shp1.line[i].ponits[shp1.line[i].numpoints - 1], base_shp_p, scaling_magnification).X - (float)1 * (float)scaling_magnification / 2,
                                fun1(base_p, shp1.line[i].ponits[shp1.line[i].numpoints - 1], base_shp_p, scaling_magnification).Y - (float)1 * (float)scaling_magnification / 2,
                                (float)1 * (float)scaling_magnification, (float)1 * (float)scaling_magnification);
                //  gph.DrawString(shp1.line[i].ponits[shp1.line[i].numpoints - 1].name, new Font("宋体", 8f), bru,
                //      fun1(base_p, shp1.line[i].ponits[shp1.line[i].numpoints - 1], base_shp_p, scaling_magnification));
            }
            pen = new Pen(Color.Red, (float)0.001);
            for (int i = 0; i < shp2.line.Count(); i++)                                            //画图层2
            {
                for (int j = 0; j < shp2.line[i].numpoints - 1; j++)
                {
                    gph.DrawLine(pen, fun1(base_p, shp2.line[i].ponits[j], base_shp_p, scaling_magnification),
                                 fun1(base_p, shp2.line[i].ponits[j + 1], base_shp_p, scaling_magnification));                   //画折线
                    gph.FillEllipse(new SolidBrush(Color.Red),                                                                   //画线实体的转折点
                                    fun1(base_p, shp2.line[i].ponits[j], base_shp_p, scaling_magnification).X - (float)1 * (float)scaling_magnification / 2,
                                    fun1(base_p, shp2.line[i].ponits[j], base_shp_p, scaling_magnification).Y - (float)1 * (float)scaling_magnification / 2
                                    , (float)1 * (float)scaling_magnification, (float)1 * (float)scaling_magnification);
                    //        gph.DrawString(shp2.line[i].ponits[j].name, new Font("宋体", 8f), bru,                                     //画点名(如果线段很多,它的点名重复,图像会变得非常模糊)
                    //    fun1(base_p, shp2.line[i].ponits[j], base_shp_p, scaling_magnification));
                }
                gph.FillEllipse(new SolidBrush(Color.Red), fun1(base_p,
                                                                shp2.line[i].ponits[shp2.line[i].numpoints - 1], base_shp_p, scaling_magnification).X - (float)1 * (float)scaling_magnification / 2,
                                fun1(base_p, shp2.line[i].ponits[shp2.line[i].numpoints - 1], base_shp_p, scaling_magnification).Y - (float)1 * (float)scaling_magnification / 2,
                                (float)1 * (float)scaling_magnification, (float)1 * (float)scaling_magnification);
                //  gph.DrawString(shp2.line[i].ponits[shp2.line[i].numpoints - 1].name, new Font("宋体", 8f), new SolidBrush(Color.Red),
                //      fun1(base_p, shp2.line[i].ponits[shp2.line[i].numpoints - 1], base_shp_p, scaling_magnification));
            }
            return(bmap);
        }