Exemple #1
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {//点击空间对象显示属性信息
            //根据鼠标的点击创建节点信息
            GISVertex onevertex   = new GISVertex((double)e.X, (double)e.Y);
            double    mindistance = Double.MaxValue;
            int       findid      = -1;

            //通过循环计算找出features数组中元素的中心点与点击位置最近的点
            for (int i = 0; i < features.Count; i++)
            {
                double distance = features[i].spatialpart.centroid.Distance(onevertex);
                if (distance < mindistance)
                {
                    mindistance = distance;
                    findid      = i;
                }
            }
            if (mindistance > 5 || findid == -1)
            {
                MessageBox.Show("没有点实体或鼠标点击位置不准确!");
            }
            else
            {
                MessageBox.Show(features[findid].getAttribute(0).ToString());
            }
        }
Exemple #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            double    x         = Convert.ToDouble(textBox1.Text);
            double    y         = Convert.ToDouble(textBox2.Text);
            GISVertex onevertex = new GISVertex(x, y);

            polyvertexes.Add(onevertex);
            GISPolygon onepoly = new GISPolygon(polyvertexes);


            //获取属性信息
            //string attribute = textBox3.Text;
            //GISAttribute oneattribute = new GISAttribute();
            //oneattribute.AddValue(attribute);

            //新建一个GISFeature 并添加到features数组中
            GISFeature onefeature = new GISFeature(onepoly, null);

            features.Add(onefeature);

            //画出这个GISFeature
            Graphics graphics = this.CreateGraphics();

            onefeature.draw(graphics, false, 0);
            //参数分别是画笔 是否绘制属性 属性列表values的索引
        }
 public double Distance(GISVertex anothervertex)
 {
     return(centroid.Distance(anothervertex));
 }
        //public GISVertex Location; **previous code
        //public string Attribute;

        public GISPoint(GISVertex onevertex)
        {
            centroid = onevertex;
            extent   = new GISExtent(onevertex, onevertex);
        }
 public double Distance(GISVertex anothervertex)
 {
     return(Math.Sqrt((x - anothervertex.x) * (x - anothervertex.x)
                      - (y - anothervertex.y) * (y - anothervertex.y)));
 }
 public GISVertex upright; //外接矩形的左下和右上角的节点
 public GISExtent(GISVertex _bottomleft, GISVertex _upright)
 {
     bottomleft = _bottomleft;
     upright    = _upright;
 }
 public void draw(Graphics graphics, GISVertex location, int index)
 {
     graphics.DrawString(values[index].ToString(), new Font("宋体", 20),
                         new SolidBrush(Color.Green), new PointF((int)(location.x), (int)(location.y)));
 }