Exemple #1
0
        private void SelectInformation(PointShape worldPoint)
        {
            try
            {
                Collection <Feature> selectedFeatures = new Collection <Feature>();

                foreach (Layer layer in ((LayerOverlay)winformsMap1.Overlays[0]).Layers)
                {
                    FeatureLayer featureLayer = layer as FeatureLayer;
                    if (featureLayer != null)
                    {
                        featureLayer.Open();
                        Collection <Feature> nearestFeatures = featureLayer.QueryTools.GetFeaturesNearestTo(worldPoint, winformsMap1.MapUnit, 1, ReturningColumnsType.AllColumns);
                        double       radius           = 10.0 / winformsMap1.Width * winformsMap1.CurrentExtent.Width;
                        EllipseShape searchingEllipse = new EllipseShape(worldPoint, radius, radius);

                        foreach (Feature feature in nearestFeatures)
                        {
                            Feature selectedFeature = feature;
                            selectedFeature.Tag = featureLayer.Name;

                            BaseShape currentShape = feature.GetShape();

                            if (currentShape is AreaBaseShape)
                            {
                                if (currentShape.Contains(worldPoint))
                                {
                                    selectedFeatures.Add(selectedFeature);
                                }
                            }
                            else if (currentShape is LineBaseShape)
                            {
                                if (currentShape.Intersects(searchingEllipse))
                                {
                                    selectedFeatures.Add(selectedFeature);
                                }
                            }
                            else if (currentShape is PointBaseShape)
                            {
                                if (searchingEllipse.Contains(currentShape))
                                {
                                    selectedFeatures.Add(selectedFeature);
                                }
                            }
                        }
                        featureLayer.Close();
                    }
                }

                if (selectedFeatures.Count > 0)
                {
                    FormInformation frmInformation = new FormInformation(selectedFeatures);
                    frmInformation.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
            }
        }