public IGeometry GetSelectionBuffer() { IGeometry selectionBuffer = null; if (_appState.Action == Action.FindAllWithin && !String.IsNullOrEmpty(_appState.Proximity)) { Configuration config = AppContext.GetConfiguration(); Configuration.ProximityRow proximity = config.Proximity.FindByProximityID(_appState.Proximity); if (proximity.Distance > 0) { DataTable table = GetFeatures(FeatureType.Selection); if (table != null && table.Rows.Count > 0) { IGeometry selectionShape = MergeShapes(table); selectionBuffer = selectionShape.Buffer(proximity.Distance); } } } return(selectionBuffer); }
public bool SelectTargets() { if (String.IsNullOrEmpty(_appState.TargetLayer) || String.IsNullOrEmpty(_appState.SelectionLayer)) { return(false); } _appState.TargetIds.Clear(); if (_appState.SelectionIds.Count == 0) { return(false); } Configuration config = AppContext.GetConfiguration(); Configuration.LayerRow targetLayerRow = config.Layer.FindByLayerID(_appState.TargetLayer); CommonDataFrame dataFrame = AppContext.GetDataFrame(_appState.MapTab); CommonLayer targetLayer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, targetLayerRow.LayerName, true) == 0); CommonField keyField = targetLayer.FindField(targetLayerRow.KeyField); DataTable targetTable = null; string filter = ""; string sort = ""; bool truncated = false; IGeometry selectionShape; switch (_appState.Action) { case Action.FindAllWithin: Configuration.ProximityRow proximity = config.Proximity.FindByProximityID(_appState.Proximity); targetTable = GetFeatures(FeatureType.Selection); if (targetTable.Rows.Count > 0) { selectionShape = MergeShapes(targetTable); if (proximity.Distance > 0) { selectionShape = selectionShape.Buffer(proximity.Distance); } targetTable = targetLayer.GetFeatureTable(String.Format("{0},{1}", targetLayer.GeometryField.Name, keyField.Name), selectionShape); } break; case Action.FindNearest1: case Action.FindNearest2: case Action.FindNearest3: case Action.FindNearest4: case Action.FindNearest5: Envelope extent = config.Application.FindByApplicationID(_appState.Application).GetFullExtentEnvelope(); double minDist = targetLayerRow.IsMinNearestDistanceNull() ? 100 : targetLayerRow.MinNearestDistance; double maxDist = targetLayerRow.IsMaxNearestDistanceNull() ? Math.Max(extent.Width, extent.Height) : targetLayerRow.MaxNearestDistance; int count = Convert.ToInt32(Enum.GetName(typeof(Action), _appState.Action).Substring(11)); targetTable = GetFeatures(FeatureType.Selection); if (targetTable.Rows.Count > 0) { selectionShape = MergeShapes(targetTable); double distance = minDist; do { targetTable = targetLayer.GetFeatureTable(String.Format("{0},{1}", targetLayer.GeometryField.Name, keyField.Name), selectionShape.Buffer(distance)); distance *= 1.414213562; }while ((targetTable == null || targetTable.Rows.Count < count) && distance < maxDist); if (targetTable != null) { targetTable.Columns.Add("Distance", typeof(double)); targetTable.Columns.Add("Index", typeof(int)); filter = "Index <= " + count.ToString(); sort = "Index"; DataColumn targetShapeColumn = targetTable.Columns.Cast <DataColumn>().First(c => c.DataType.IsSubclassOf(typeof(Geometry))); int targetDistanceColumn = targetTable.Columns.IndexOf("Distance"); DataTable selectionTable = GetFeatures(FeatureType.Selection); DataColumn selectionShapeColumn = selectionTable.Columns.Cast <DataColumn>().First(c => c.DataType.IsSubclassOf(typeof(Geometry))); foreach (DataRow selectionRow in selectionTable.Rows) { selectionShape = (Geometry)selectionRow[selectionShapeColumn]; foreach (DataRow targetRow in targetTable.Rows) { double d = selectionShape.Distance((Geometry)targetRow[targetShapeColumn]); if (targetRow.IsNull(targetDistanceColumn)) { targetRow[targetDistanceColumn] = d; } else { targetRow[targetDistanceColumn] = Math.Min((double)targetRow[targetDistanceColumn], d); } } } DataRow[] targetRows = targetTable.Select("", "Distance"); for (int i = 0; i < targetRows.Length; ++i) { targetRows[i]["Index"] = i + 1; } } } break; } if (targetTable != null) { int maxTargets = targetLayerRow.IsMaxNumberSelectedNull() ? Int32.MaxValue : targetLayerRow.MaxNumberSelected; int c = targetTable.Columns.IndexOf(keyField.Name); foreach (DataRow row in targetTable.Select(filter, sort)) { if (!row.IsNull(c)) { if (_appState.TargetIds.Count == maxTargets) { truncated = true; break; } _appState.TargetIds.Add(row[c].ToString()); } } } return(truncated); }