示例#1
0
        private double im_H_Line_D(shpline line1, shpline line2)           //计算两条线实体之间改进的hausdorff距离
        {
            double        h_Line_D   = 0;
            PointD        p          = new PointD();
            List <double> line1_D    = im_H_line_length(line1);
            List <double> line2_D    = im_H_line_length(line2);
            List <double> Line_mid_D = new List <double>();                   //中点到另一条线实体的各线段的的距离

            if (line1_D.Last() <= line2_D.Last())
            {
                p = line_midpoint(line1, line1_D);
                for (int i = 0; i < line2.numpoints - 1; i++)
                {
                    Line_mid_D.Add(perpendicular_length(p, line2.ponits[i], line2.ponits[i + 1]));
                }
                h_Line_D = Line_mid_D.Min();
            }
            else
            {
                p = line_midpoint(line2, line2_D);
                for (int i = 0; i < line1.numpoints - 1; i++)
                {
                    Line_mid_D.Add(perpendicular_length(p, line1.ponits[i], line1.ponits[i + 1]));
                }
                h_Line_D = Line_mid_D.Min();
            }
            return(h_Line_D);
        }
示例#2
0
 private double P_P_D(shpline line1, shpline line2, double[,] p_p_fc_D, int i, int j)       //利用递归求frechet距离
 {
     if (p_p_fc_D[i, j] > -1)
     {
         return(p_p_fc_D[i, j]);
     }
     else if (i == 0 && j == 0)
     {
         p_p_fc_D[i, j] = D(line1.ponits[i], line2.ponits[j]);
     }
     else if (i > 0 && j == 0)
     {
         p_p_fc_D[i, j] = Math.Max(P_P_D(line1, line2, p_p_fc_D, i - 1, j),
                                   D(line1.ponits[i], line2.ponits[0]));
     }
     else if (i == 0 && j > 0)
     {
         p_p_fc_D[i, j] = Math.Max(P_P_D(line1, line2, p_p_fc_D, i, j - 1),
                                   D(line1.ponits[0], line2.ponits[j]));
     }
     else if (i > 0 && j > 0)
     {
         p_p_fc_D[i, j] = Math.Max(Math.Min(Math.Min(P_P_D(line1, line2, p_p_fc_D, i - 1, j), P_P_D(line1, line2, p_p_fc_D, i - 1, j - 1))
                                            , P_P_D(line1, line2, p_p_fc_D, i, j - 1)
                                            ), D(line1.ponits[i], line2.ponits[j]));
     }
     else
     {
         p_p_fc_D[i, j] = -1;
     }
     return(p_p_fc_D[i, j]);
 }
示例#3
0
 private double aver_P_P_D(shpline line1, shpline line2, double[,,] p_p_fc_D, int i, int j)       //利用递归求frechet距离
 {
     if (p_p_fc_D[i, j, 0] > -1)
     {
         return(p_p_fc_D[i, j, 0]);
     }
     else if (i == 0 && j == 0)
     {
         p_p_fc_D[i, j, 0] = p_p_fc_D[i, j, 1];
     }
     else if (i > 0 && j == 0)
     {
         p_p_fc_D[i, j, 0] = Math.Max(aver_P_P_D(line1, line2, p_p_fc_D, i - 1, j),
                                      p_p_fc_D[i, 0, 1]);
     }
     else if (i == 0 && j > 0)
     {
         p_p_fc_D[i, j, 0] = Math.Max(aver_P_P_D(line1, line2, p_p_fc_D, i, j - 1),
                                      p_p_fc_D[0, j, 1]);
     }
     else if (i > 0 && j > 0)
     {
         p_p_fc_D[i, j, 0] = Math.Max(Math.Min(Math.Min(aver_P_P_D(line1, line2, p_p_fc_D, i - 1, j), aver_P_P_D(line1, line2, p_p_fc_D, i - 1, j - 1))
                                               , aver_P_P_D(line1, line2, p_p_fc_D, i, j - 1)
                                               ), p_p_fc_D[i, j, 1]);
     }
     else
     {
         p_p_fc_D[i, j, 0] = -1;
     }
     return(p_p_fc_D[i, j, 0]);
 }
示例#4
0
        private PointD line_midpoint(shpline line, List <double> line_D)         //求线实体的中点
        {
            PointD p     = new PointD();
            double D_mid = line_D.Last() / 2.0;

            for (int i = 0; i < line_D.Count - 1; i++)
            {
                if (D_mid == line_D[i])
                {
                    p = line.ponits[i];
                    return(p);
                }
                else if (D_mid == line_D[i + 1])
                {
                    p = line.ponits[i + 1];
                    return(p);
                }
                else if (D_mid > line_D[i] && D_mid < line_D[i + 1])
                {
                    p = mid_piont(line.ponits[i], line.ponits[i + 1], D_mid - line_D[i], line_D[i + 1] - line_D[i]);
                    return(p);
                }
            }
            return(p);
        }
示例#5
0
        private List <double> im_H_line_length(shpline line)                   //计算一条线实体的长度
        {
            List <double> length_D = new List <double> ();

            length_D.Add(0.0);
            for (int i = 0; i < line.numpoints - 1; i++)
            {
                length_D.Add(D(line.ponits[0], line.ponits[1]) + length_D.Last());
            }
            return(length_D);
        }
示例#6
0
        private double Feachet_line(shpline line1, shpline line2)//线line1到line2的frechet距离
        {
            double line1_line2_D;

            double[,] p_p_fc_D = new double[line1.numpoints, line2.numpoints];
            for (int i = 0; i < line1.numpoints; i++)
            {
                for (int j = 0; j < line2.numpoints; j++)
                {
                    p_p_fc_D[i, j] = -1.0;
                }
            }
            line1_line2_D = P_P_D(line1, line2, p_p_fc_D, line1.numpoints - 1, line2.numpoints - 1);
            return(line1_line2_D);
        }
示例#7
0
        private double H_line_D(shpline line1, shpline line2)          //线line1到line2的hausdorff距离
        {
            double shp1_linei_D_max = 0;

            for (int ii = 0; ii < line1.numpoints; ii++)
            {
                double pi_min = D(line1.ponits[ii], line2.ponits[0]);
                for (int jj = 0; jj < line2.numpoints; jj++)
                {
                    double d = D(line1.ponits[ii], line2.ponits[jj]);
                    pi_min = pi_min > d ? d : pi_min;
                }
                shp1_linei_D_max = shp1_linei_D_max < pi_min ? pi_min : shp1_linei_D_max;
            }
            return(shp1_linei_D_max);
        }
示例#8
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);
            }
        }
示例#9
0
        private double aver_Feachet_line(shpline line1, shpline line2)        //线line1到line2的平均frechet距离
        {
            double[,,] aver_p_p_fc_D = new double[line1.numpoints, line2.numpoints, 2];
            for (int i = 0; i < line1.numpoints; i++)
            {
                for (int j = 0; j < line2.numpoints; j++)
                {
                    aver_p_p_fc_D[i, j, 0] = -1.0;
                    aver_p_p_fc_D[i, j, 1] = D(line1.ponits[i], line2.ponits[j]);
                }
            }
            aver_P_P_D(line1, line2, aver_p_p_fc_D, line1.numpoints - 1, line2.numpoints - 1);
            List <point_int> p_int = new List <point_int>();

            min_path(aver_p_p_fc_D, line1.numpoints - 1, line2.numpoints - 1, p_int);
            double sum = 0.0;

            for (int i = 0; i < p_int.Count(); i++)
            {
                sum = sum + aver_p_p_fc_D[p_int[i].x, p_int[i].y, 1];
            }
            return(sum / p_int.Count());
        }