Exemplo n.º 1
0
        private void FormXGIS_MouseClick(object sender, MouseEventArgs e)
        {
            if (layer.FeatureCount() == 0)
            {
                return;
            }
            XVertex onevertex   = view.ToMapVertex(e.Location);
            double  mindistance = Double.MaxValue;
            int     findid      = -1;
            int     index       = 0;

            foreach (XFeature feature in layer.Features)
            {
                double distance = feature.Distance(onevertex);
                if (distance < mindistance)
                {
                    mindistance = distance;
                    findid      = index;
                }
                index++;
            }
            int ScreenDistance = view.ToScreenDistance(mindistance);

            if (ScreenDistance < 5)
            {
                MessageBox.Show("找到的Feature的序号是" + findid);
            }
        }
Exemplo n.º 2
0
        internal void SelectByClick(Point location, XView view)
        {
            XVertex v = view.ToMapVertex(location);

            foreach (XFeature feature in Features)
            {
                feature.Selected = false;
            }
            if (ShapeType == SHAPETYPE.point)
            {
                Double distance = Double.MaxValue;
                int    id       = -1;
                for (int i = 0; i < Features.Count; i++)
                {
                    XPointSpatial point = (XPointSpatial)(Features[i].Spatial);
                    double        dist  = point.Distance(v);
                    if (dist < distance)
                    {
                        distance = dist;
                        id       = i;
                    }
                }
                double scd = view.ToScreenDistance(v, Features[id].Spatial.Centroid);//转为屏幕距离
                if (scd <= 5)
                {
                    Features[id].Selected = true;
                }
                else
                {
                    Console.WriteLine("屏幕距离为" + scd + ",选择无效!!");
                }
            }
            else if (ShapeType == SHAPETYPE.line)
            {
                Double distance = Double.MaxValue;
                int    id       = -1;
                for (int i = 0; i < Features.Count; i++)
                {
                    XLineSpatial line = (XLineSpatial)(Features[i].Spatial);
                    double       dist = line.Distance(v);
                    if (dist < distance)
                    {
                        distance = dist;
                        id       = i;
                    }
                }
                double scd = view.ToScreenDistance(distance);//转为屏幕距离
                if (scd <= 5)
                {
                    Features[id].Selected = true;
                }
                else
                {
                    Console.WriteLine("屏幕距离为" + scd + ",选择无效!!");
                }
            }
            else if (ShapeType == SHAPETYPE.polygon)
            {
                for (int i = 0; i < Features.Count; i++)
                {
                    XPolygonSpatial polygon = (XPolygonSpatial)(Features[i].Spatial);
                    if (polygon.Incude(v))
                    {
                        Features[i].Selected = true;
                    }
                }
            }
        }