Exemplo n.º 1
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (layer == null)
            {
                return;
            }
            GISVertex v = view.ToMapVertex(e.Location);

            Console.WriteLine("mapvertex @" + v.x.ToString() + "|" + v.y.ToString()); //此处鼠标点到地图点的转换???
            //创建点选粗选矩形
            GISSelect s = new GISSelect();
            GISExtent MinSelectExtent = s.BuildExtent(v, view);
            Point     bottomleft      = view.ToScreenPoint(MinSelectExtent.bottomleft);
            Point     upleft          = view.ToScreenPoint(new GISVertex(MinSelectExtent.bottomleft.x, MinSelectExtent.upright.y));
            Point     upright         = view.ToScreenPoint(MinSelectExtent.upright);
            Point     bottomright     = view.ToScreenPoint(new GISVertex(MinSelectExtent.upright.x, MinSelectExtent.bottomleft.y));

            Point[]  points   = new Point[] { bottomleft, upleft, upright, bottomright };
            Graphics graphics = this.CreateGraphics();

            graphics.DrawPolygon(new Pen(GISConst.PolygonBoundaryColor, GISConst.PolygonBoundaryWidth), points);

            SelectResult sr = layer.Select(v, view);

            if (sr == SelectResult.OK)
            {
                UpdateMap();
                //toolStripStatusLabel1.Text = layer.Selection.Count.ToString();
                toolStripStatusLabel2.Text = "click @" + v.x.ToString() + "|" + v.y.ToString();
                UpdateAttributeWindow();
                //statusStrip1.Text = layer.Selection.Count.ToString();
            }
        }
Exemplo n.º 2
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            GISVertex mouselocation = view.ToMapVertex(new Point(e.X, e.Y));

            double mindistance = Double.MaxValue;
            int    id          = -1;

            for (int i = 0; i < features.Count; i++)
            {
                double onedistance = features[i].getSpatial().getCentroid().Distance(mouselocation);
                if (onedistance < mindistance)
                {
                    id          = i;
                    mindistance = onedistance;
                }
            }

            if (id == -1)
            {
                MessageBox.Show("points is an empty set!");
                return;
            }
            int screendistance = view.ToScreenPoint(new GISVertex(mindistance, 0)).X -
                                 view.ToScreenPoint(new GISVertex(0, 0)).X;

            if (screendistance > 5)
            {
                MessageBox.Show("please click one point closely!");
                return;
            }

            MessageBox.Show("attribute is " + features[id].getAttributeValue(0));
        }
Exemplo n.º 3
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {//点击空间对象显示属性信息
            //根据鼠标的点击创建节点信息
            if (features.Count == 0)
            {
                return;
            }
            GISVertex mouselocation = view.ToMapVertex(e.Location);
            double    mindistance   = Double.MaxValue;
            int       id            = -1;

            //通过遍历找出features数组中元素的中心点与点击位置最近的点
            for (int i = 0; i < features.Count; i++)
            {
                double onedistance = features[i].spatialpart.centroid.Distance(mouselocation);
                if (onedistance < mindistance)
                {
                    mindistance = onedistance;
                    id          = i;
                }
            }
            //判断是否存在空间对象
            if (id == -1)
            {
                MessageBox.Show("没有任何空间对象!!");
                return;//结束了
            }

            Point nearestpoint = view.ToScreenPoint(features[id].spatialpart.centroid);

            if (ScreenDistance(e.Location, nearestpoint) < 5)
            {
                MessageBox.Show(features[id].getAttribute(0).ToString());
            }
        }
Exemplo n.º 4
0
        public void delaunay()
        {
            GISVertex v;

            updateview();
            pt.Clear();
            dlay.Clear();
            for (i = 0; i < document.layers.Count; i++)
            {
                if (document.layers[i].ShapeType == SHAPETYPE.POINT)
                {
                    for (j = 0; j < document.layers[i].Features.Count; j++)
                    {
                        v = new GISVertex(view.ToScreenPoint(document.layers[i].Features[j].spatialpart.centroid).X, view.ToScreenPoint(document.layers[i].Features[j].spatialpart.centroid).Y);
                        pt.Add(new PointF(Convert.ToSingle(v.x), Convert.ToSingle(v.y)));
                    }
                    ptA[0].X = this.Width / 2;
                    ptA[0].Y = -Convert.ToSingle(ptA[0].X / Math.Sqrt(3) * 2);
                    ptA[1].X = -ptA[0].X;
                    ptA[1].Y = this.Height;
                    ptA[2].X = this.Width + ptA[0].X;
                    ptA[2].Y = this.Height - 10;
                    dlay.Add(new Delaunay3(ptA[0], ptA[1], ptA[2]));
                    for (q = 0; q < pt.Count; q++)
                    {
                        de = null;
                        for (j = 0; j < dlay.Count; j++)
                        {
                            if (dlay[j].contain(pt[q]))
                            {
                                de = dlay[j];
                                break;
                            }
                        }
                        if (de != null)
                        {
                            dlay.Remove(de);
                            dlay.Add(new Delaunay3(de.pt[0], de.pt[1], pt[q]));
                            dlay.Add(new Delaunay3(de.pt[0], de.pt[2], pt[q]));
                            dlay.Add(new Delaunay3(de.pt[2], de.pt[1], pt[q]));
                        }
                        n1 = false;
                        while (n1 == false)
                        {
                            n1 = true;
                            for (m = 0; m < dlay.Count - 1; m++)
                            {
                                for (n = m + 1; n < dlay.Count; n++)
                                {
                                    if (dlay[m].Ifggb(dlay[n]) && LOP(dlay[m], dlay[n]) == false)
                                    {
                                        de1  = dlay[m];
                                        de2  = dlay[n];
                                        n1   = false;
                                        ggb1 = de1.Findggb(de2);
                                        for (k = 0; k < 3; k++)
                                        {
                                            if (de1.pt[k] != ggb1.StartNode && de1.pt[k] != ggb1.EndNode)
                                            {
                                                p1 = de1.pt[k];
                                            }
                                            if (de2.pt[k] != ggb1.StartNode && de2.pt[k] != ggb1.EndNode)
                                            {
                                                p2 = de2.pt[k];
                                            }
                                        }//交换对角线
                                        dlay.Add(new Delaunay3(ggb1.StartNode, p1, p2));
                                        dlay.Add(new Delaunay3(ggb1.EndNode, p1, p2));
                                        dlay.Remove(de1);
                                        dlay.Remove(de2);
                                    }
                                    if (n1 == false)
                                    {
                                        break;
                                    }
                                }
                                if (n1 == false)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    break;
                }
            }
        }
Exemplo n.º 5
0
        public void delaunay()
        {
            GISVertex v;

            updateview();
            pt.Clear();
            dlay.Clear();
            for (i = 0; i < document.layers.Count; i++)
            {
                if (document.layers[i].ShapeType == SHAPETYPE.POINT)
                {
                    for (j = 0; j < document.layers[i].Features.Count; j++)
                    {
                        v = new GISVertex(view.ToScreenPoint(document.layers[i].Features[j].spatialpart.centroid).X, view.ToScreenPoint(document.layers[i].Features[j].spatialpart.centroid).Y);
                        pt.Add(new PointF(Convert.ToSingle(v.x), Convert.ToSingle(v.y)));
                    }
                    //ptA[0].X = pictureBox1.Width / 2;
                    //ptA[0].Y = -Convert.ToSingle(ptA[0].X / Math.Sqrt(3) * 2);
                    //ptA[1].X = -ptA[0].X;
                    //ptA[1].Y = pictureBox1.Height;
                    //ptA[2].X = pictureBox1.Width + ptA[0].X;
                    //ptA[2].Y = pictureBox1.Height - 5;
                    float xmax, xmin, ymax, ymin, dx, dy, ddx, ddy;
                    xmin = xmax = pt[0].X;
                    ymin = ymax = pt[0].Y;
                    for (j = 1; j < pt.Count; j++)
                    {
                        if (xmin > pt[j].X)
                        {
                            xmin = pt[j].X;
                        }
                        if (xmax < pt[j].X)
                        {
                            xmax = pt[j].X;
                        }
                        if (ymin > pt[j].Y)
                        {
                            ymin = pt[j].Y;
                        }
                        if (ymax < pt[j].Y)
                        {
                            ymax = pt[j].Y;
                        }
                    }
                    dx       = xmax - xmin;
                    dy       = ymax - ymin;
                    ddx      = dx / 100;
                    ddy      = dy / 100;
                    xmin    -= ddx;
                    xmax    += ddx;
                    dx      += 2 * ddx;
                    ymin    -= ddy;
                    ymax    += ddy;
                    dy      += 2 * ddy;
                    ptA[0].X = xmin - dy * Convert.ToSingle(Math.Sqrt(3) / 3);
                    ptA[0].Y = ymin;
                    ptA[1].X = xmax + dy * Convert.ToSingle(Math.Sqrt(3) / 3);
                    ptA[1].Y = ymin;
                    ptA[2].X = (xmin + xmax) / 2;
                    ptA[2].Y = xmax + dy * Convert.ToSingle(Math.Sqrt(3) / 2);
                    dlay.Add(new Delaunay3(ptA[0], ptA[1], ptA[2]));
                    for (q = 0; q < pt.Count; q++)
                    {
                        de = null;
                        for (j = 0; j < dlay.Count; j++)
                        {
                            if (dlay[j].contain(pt[q]))
                            {
                                de = dlay[j];
                                break;
                            }
                        }
                        if (de != null)
                        {
                            dlay.Remove(de);
                            dlay.Add(new Delaunay3(de.pt[0], de.pt[1], pt[q]));
                            dlay.Add(new Delaunay3(de.pt[0], de.pt[2], pt[q]));
                            dlay.Add(new Delaunay3(de.pt[2], de.pt[1], pt[q]));
                        }
                        n1 = false;
                        while (n1 == false)
                        {
                            n1 = true;
                            for (m = 0; m < dlay.Count - 1; m++)
                            {
                                for (n = m + 1; n < dlay.Count; n++)
                                {
                                    if (dlay[m].Ifggb(dlay[n]) && LOP(dlay[m], dlay[n]) == false)
                                    {
                                        de1  = dlay[m];
                                        de2  = dlay[n];
                                        n1   = false;
                                        ggb1 = de1.Findggb(de2);
                                        for (k = 0; k < 3; k++)
                                        {
                                            if (de1.pt[k] != ggb1.StartNode && de1.pt[k] != ggb1.EndNode)
                                            {
                                                p1 = de1.pt[k];
                                            }
                                            if (de2.pt[k] != ggb1.StartNode && de2.pt[k] != ggb1.EndNode)
                                            {
                                                p2 = de2.pt[k];
                                            }
                                        }//交换对角线
                                        dlay.Add(new Delaunay3(ggb1.StartNode, p1, p2));
                                        dlay.Add(new Delaunay3(ggb1.EndNode, p1, p2));
                                        dlay.Remove(de1);
                                        dlay.Remove(de2);
                                    }
                                    if (n1 == false)
                                    {
                                        break;
                                    }
                                }
                                if (n1 == false)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                if (document.layers[i].ShapeType == SHAPETYPE.POINT)
                {
                    break;
                }
            }
        }