protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry) { var bottomRight = new Point(); IList <Tuple <string, string, long> > tripleTuplePoints = new List <Tuple <string, string, long> >(); var hasSelection = await QueuedTask.Run(() => { // geometry is a point var clickedPnt = geometry as MapPoint; if (clickedPnt == null) { return(false); } // pixel tolerance var tolerance = 3; //Get the client point edges var topLeft = new Point(clickedPnt.X - tolerance, clickedPnt.Y + tolerance); bottomRight = new Point(clickedPnt.X + tolerance, clickedPnt.Y - tolerance); //convert the client points to Map points var mapTopLeft = MapView.Active.ClientToMap(topLeft); var mapBottomRight = MapView.Active.ClientToMap(bottomRight); //create a geometry using these points Geometry envelopeGeometry = EnvelopeBuilder.CreateEnvelope(mapTopLeft, mapBottomRight); if (envelopeGeometry == null) { return(false); } //Get the features that intersect the sketch geometry. var result = ActiveMapView.GetFeatures(geometry); ProWindowConfig objCfg = new ProWindowConfig(); objCfg = IdentityConfigWindow.promdl; //string[] feat_lyrnames = { }; var feat_lyrnames = new List <string>() { }; //string[] mosic_lyrnames = { }; var mosic_lyrnames = new List <string>() { }; string filtername = "LiquidsHCAFilter"; string strOSPointlayername = "NHD_Intersections"; //Assign defaul layernames if the object is empty if (objCfg is null) { feat_lyrnames = new List <string> { "HydrographicTransportPaths", "WaterbodySpreadPolygons" }; mosic_lyrnames = new List <string> { "MultiDimRasterMosaic" }; } //Assign layer names from the config object else { //Check the values are null or not if (!string.IsNullOrEmpty(objCfg.OSPointName)) { strOSPointlayername = objCfg.OSPointName; } if (!string.IsNullOrEmpty(objCfg.LSName)) { mosic_lyrnames.Add(objCfg.LSName); } if (!string.IsNullOrEmpty(objCfg.NHDIntName)) { feat_lyrnames.Add(objCfg.NHDIntName); } if (!string.IsNullOrEmpty(objCfg.HTPathName)) { feat_lyrnames.Add(objCfg.HTPathName); } if (!string.IsNullOrEmpty(objCfg.HTSpreadName)) { feat_lyrnames.Add(objCfg.HTSpreadName); } } var ospointlyr = ActiveMapView.Map.FindLayers(strOSPointlayername).First() as FeatureLayer; foreach (var kvp in result) { var bfl = kvp.Key; // only look at points if (kvp.Key.ShapeType != esriGeometryType.esriGeometryPoint) { continue; } var layerName = bfl.Name; var oidName = bfl.GetTable().GetDefinition().GetObjectIDField(); foreach (var oid in kvp.Value) { //Select a single state polygon FeatureLayer fl1 = ActiveMapView.Map.FindLayers(strOSPointlayername).First() as FeatureLayer; QueryFilter queryFilter = new QueryFilter(); string whereClause = String.Format("{0} = {1}", oidName, oid); queryFilter.WhereClause = whereClause; //Use a cursor to get to a feature's geometry using (ArcGIS.Core.Data.RowCursor rowCursor = fl1.Search(queryFilter)) { //Grab the first record (and hopefully only record) while (rowCursor.MoveNext()) { //Grab the features geometry Feature feature = rowCursor.Current as Feature; //Geometry geo = feature.GetShape(); string pintid_field = "POINT_ID"; var pointidval = feature[pintid_field]; foreach (string lyrname in feat_lyrnames) { FeatureLayer fl = ActiveMapView.Map.FindLayers(lyrname).First() as FeatureLayer; var lyrfilter = new CIMDefinitionFilter(); lyrfilter.Name = filtername; lyrfilter.DefinitionExpression = String.Format("{0} = '{1}'", pintid_field, pointidval); fl.SetDefinitionFilter(lyrfilter); } foreach (string lyrname in mosic_lyrnames) { MosaicLayer fl = ActiveMapView.Map.FindLayers(lyrname).First() as MosaicLayer; //RasterLayer rl = ActiveMapView.Map.FindLayers(lyrname).First() as RasterLayer; //rl.SetDefinition(); var lyrfilter = new CIMDefinitionFilter(); lyrfilter.Name = filtername; lyrfilter.DefinitionExpression = String.Format("Name LIKE '{0}%'", pointidval); fl.SetDefinitionFilter(lyrfilter); } ActiveMapView.RedrawAsync(true); } } } } return(true); }); return(true); }
public static void BuildDictionariesAsync(Dictionary <int, List <string> > arcNodeListDictionary, Dictionary <string, List <int> > nodeArcListDictionary) { QueuedTask.Run(() => { try { // Used to free up process memory. Without this the trace tool will 'hang up' after going between trace up and trace down. nodeArcListDictionary.Clear(); arcNodeListDictionary.Clear(); // Global vairables var map = MapView.Active.Map; var arcLayer = map.FindLayers("Sewer Lines").FirstOrDefault() as FeatureLayer; var nodeLayer = map.FindLayers("Manholes").FirstOrDefault() as FeatureLayer; var arcTableDef = arcLayer.GetTable().GetDefinition(); //table definition of featurelayer var nodeTableDef = nodeLayer.GetTable().GetDefinition(); //table definition of featurelayer // BUILD ARC AND NODE DICTIONARIES // arc ObjectID-- > { UPS_MH, DWN_MH} Only 2 VALUES for each KEY // node MH Number -- >{ Arc OBjectID, Arc OBjectID, ...} Can have 1 or more VALUES for each KEY // Get the indices for the fields int objIDIdx = arcTableDef.FindField("ObjectID"); int nodeUpIdx = arcTableDef.FindField("UPS_MH"); int nodeDwnIdx = arcTableDef.FindField("DWN_MH"); using (ArcGIS.Core.Data.RowCursor rowCursor = arcLayer.Search()) { while (rowCursor.MoveNext()) { using (Row row = rowCursor.Current) { //List<string> unitIDValueList = new List<string>(); //List<int> objIDValueList = new List<int>(); var objIDVal = row.GetOriginalValue(objIDIdx); var nodeUpVal = row.GetOriginalValue(nodeUpIdx); var nodeDownVal = row.GetOriginalValue(nodeDwnIdx); // Populate arcNodeListDictionary keys and values if (arcNodeListDictionary.ContainsKey((int)objIDVal)) { //Do nothing } else { arcNodeListDictionary.Add((int)objIDVal, new List <string>()); arcNodeListDictionary[(int)objIDVal].Add((string)nodeUpVal); arcNodeListDictionary[(int)objIDVal].Add((string)nodeDownVal); } // Check of the nodeArcListDictionary contains nodeUpVal as KEY- Add nodeUpVal if FALSE if (nodeArcListDictionary.ContainsKey((string)nodeUpVal)) { nodeArcListDictionary[(string)nodeUpVal].Add((int)objIDVal); } else { nodeArcListDictionary.Add((string)nodeUpVal, new List <int>()); nodeArcListDictionary[(string)nodeUpVal].Add((int)objIDVal); } // Check of the nodeArcListDictionary contains nodeDownVal as KEY- Add nodeDownVal if FALSE if (nodeArcListDictionary.ContainsKey((string)nodeDownVal)) { //Do nothing nodeArcListDictionary[(string)nodeDownVal].Add((int)objIDVal); } else { nodeArcListDictionary.Add((string)nodeDownVal, new List <int>()); nodeArcListDictionary[(string)nodeDownVal].Add((int)objIDVal); } } } } } catch (Exception ex) { LogError(ex.Message, ex.StackTrace); string caption = "BuildDictionariesAsync failed!"; string message = "Background process failed. Trace tools will NOT work. \n\nSave and restart ArcGIS Pro and try process again.\n" + "If problem persist, contact your GIS Admin."; //Using the ArcGIS Pro SDK MessageBox class MessageBox.Show(message, caption); } }); }