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); }
public static string GetFormattedWorldCoordinate(this GisEditorWpfMap map, ScreenPointF screenPoint, MouseCoordinateType mouseCoordinateType) { PointShape lonlat = map.ToWorldCoordinate(screenPoint.X, screenPoint.Y); double xInCurrentProjection = lonlat.X; double yInCurrentProjection = lonlat.Y; string projectionFullName = "Unknown"; if (map.DisplayProjectionParameters != null) { string projectionShortName = map.DisplayProjectionParameters.Split(' ')[0].Replace("+proj=", string.Empty); projectionFullName = projectionAbbreviations[projectionShortName]; } GeographyUnit mapUnit = GisEditorWpfMap.GetGeographyUnit(map.DisplayProjectionParameters); if (projectionFullName == "Unknown" && mapUnit == GeographyUnit.Unknown) { return(String.Format("X:{0}, Y:{1}", lonlat.X.ToString("N4", CultureInfo.InvariantCulture), lonlat.Y.ToString("N4", CultureInfo.InvariantCulture))); } else { if (mapUnit != GeographyUnit.DecimalDegree) { try { Proj4Projection proj = new Proj4Projection(); proj.InternalProjectionParametersString = map.DisplayProjectionParameters; proj.ExternalProjectionParametersString = Proj4Projection.GetDecimalDegreesParametersString(); proj.Open(); lonlat = proj.ConvertToExternalProjection(lonlat) as PointShape; proj.Close(); } catch { lonlat = new PointShape(); } } return(GetMouseCoordinates(lonlat.X, lonlat.Y, mouseCoordinateType, map.DisplayProjectionParameters, xInCurrentProjection, yInCurrentProjection)); } }
public static ContentPresenter GetMapBasicInformation(this GisEditorWpfMap map) { string projectionFullName = "Unknown"; GeographyUnit mapUnit = GeographyUnit.Unknown; if (map.DisplayProjectionParameters != null) { string projectionShortName = map.DisplayProjectionParameters.Split(' ')[0].Replace("+proj=", string.Empty); projectionFullName = projectionAbbreviations[projectionShortName]; mapUnit = GisEditorWpfMap.GetGeographyUnit(map.DisplayProjectionParameters); } double scaleValue = map.CurrentScale; int zoomLevel = map.GetSnappedZoomLevelIndex(scaleValue) + 1; bool isPreciseZoomLevel = map.ZoomLevelSet.GetZoomLevels()[zoomLevel - 1] is PreciseZoomLevel; TextBlock projectionTextBlock = new TextBlock(); projectionTextBlock.SetResourceReference(TextBlock.TextProperty, "MapExtensionProjectionText"); TextBlock projectionValueTextBlock = new TextBlock(); projectionValueTextBlock.Text = string.Format(" {0} | ", projectionFullName); TextBlock mapUnitTextBlock = new TextBlock(); mapUnitTextBlock.SetResourceReference(TextBlock.TextProperty, "MapExtensionMapUnitText"); TextBlock mapUnitValueTextBlock = new TextBlock(); mapUnitValueTextBlock.Text = string.Format(" {0} | ", mapUnit); TextBlock zoomLevelTextBlock = new TextBlock(); zoomLevelTextBlock.SetResourceReference(TextBlock.TextProperty, "MapExtensionZoomLevelText"); TextBlock zoomLevelValueTextBlock = new TextBlock(); if (isPreciseZoomLevel) { zoomLevelValueTextBlock.Text = string.Format(" Temporary Zoom Level | "); } else { zoomLevelValueTextBlock.Text = string.Format(" {0:D2} | ", zoomLevel); } TextBlock scaleTextBlock = new TextBlock(); scaleTextBlock.SetResourceReference(TextBlock.TextProperty, "MapExtensionScaleText"); TextBlock scaleValueTextBlock = new TextBlock(); scaleValueTextBlock.Text = string.Format(" 1:{0:N0}", scaleValue); StackPanel mapInformationStackPanel = new StackPanel(); mapInformationStackPanel.Orientation = Orientation.Horizontal; mapInformationStackPanel.Children.Add(projectionTextBlock); mapInformationStackPanel.Children.Add(projectionValueTextBlock); mapInformationStackPanel.Children.Add(mapUnitTextBlock); mapInformationStackPanel.Children.Add(mapUnitValueTextBlock); mapInformationStackPanel.Children.Add(zoomLevelTextBlock); mapInformationStackPanel.Children.Add(zoomLevelValueTextBlock); mapInformationStackPanel.Children.Add(scaleTextBlock); mapInformationStackPanel.Children.Add(scaleValueTextBlock); ContentPresenter contentPresenter = new ContentPresenter(); contentPresenter.Content = mapInformationStackPanel; return(contentPresenter); }