Example #1
0
        private Feature FindFeatureByPoint(double x, double y)
        {
            Feature result = null;

            IEnumerable <FeatureLayer> allFeatureLayers = null;
            string currentProj4 = String.Empty;

            if (ParentMap != null)
            {
                allFeatureLayers = ParentMap.GetFeatureLayers(true).Reverse();
                currentProj4     = ParentMap.DisplayProjectionParameters;
            }
            else
            {
                allFeatureLayers = new Collection <FeatureLayer>();
            }

            GeographyUnit currentUnit = GeographyUnit.DecimalDegree;

            if (!string.IsNullOrEmpty(currentProj4))
            {
                currentUnit = GisEditorWpfMap.GetGeographyUnit(currentProj4);
            }

            foreach (var featureLayer in allFeatureLayers)
            {
                Collection <Feature> featuresInDistance = null;
                featureLayer.SafeProcess(() =>
                {
                    featuresInDistance = AscendingSearch(x, y, currentUnit, featureLayer, 1, 20);
                });
                //featureLayer.Open();
                //var featuresInDistance = AscendingSearch(x, y, currentUnit, featureLayer, 1, 20);
                //featureLayer.Close();

                if (featuresInDistance != null && featuresInDistance.Count > 0)
                {
                    if (featuresInDistance.Count > 1)
                    {
                        result = featuresInDistance[0];
                        for (int i = 0; i < featuresInDistance.Count - 1; i++)
                        {
                            result = result.GetIntersection(featuresInDistance[i + 1]);
                        }
                    }
                    else
                    {
                        result = featuresInDistance[0];
                    }
                    result.Tag = Convert.ToBase64String(result.GetWellKnownBinary());
                    break;
                }
            }

            return(result);
        }